Laravel5.1 框架登录和注册实现方法详解
Laravel  /  管理员 发布于 9年前   206
本文实例讲述了Laravel5.1 框架登录和注册实现方法。分享给大家供大家参考,具体如下: 关于登录和注册 Laravel自带了一套组件实现了这一功能,我们只需要实现简单的视图即可。 AuthController是专门管理用户注册和登录的。 PassWordController是重置密码用的,今天暂不做记录。 我们可以在 config/auth.php 文件中进行用户认证的配置: 这是默认的配置,注释写的很清楚了 如果有特别需要可以做更改,一般情况中我们使用默认的就OK。 注册视图的路径必须放在 views/auth/ 目录中 并命名为 register.blade.php。1 配置
'eloquent', /* |-------------------------------------------------------------------------- | Authentication Model |-------------------------------------------------------------------------- | | When using the "Eloquent" authentication driver, we need to know which | Eloquent model should be used to retrieve your users. Of course, it | is often just the "User" model but you may use whatever you like. | */ 'model' => App\User::class, /* |-------------------------------------------------------------------------- | Authentication Table |-------------------------------------------------------------------------- | | When using the "Database" authentication driver, we need to know which | table should be used to retrieve your users. We have chosen a basic | default value but you may easily change it to any table you like. | */ 'table' => 'users', /* |-------------------------------------------------------------------------- | Password Reset Settings |-------------------------------------------------------------------------- | | Here you may set the options for resetting passwords including the view | that is your password reset e-mail. You can also set the name of the | table that maintains all of the reset tokens for your application. | | The expire time is the number of minutes that the reset token should be | considered valid. This security feature keeps tokens short-lived so | they have less time to be guessed. You may change this as needed. | */ 'password' => [ 'email' => 'emails.password', 'table' => 'password_resets', 'expire' => 60, ],];
2 创建路由
/** * 用户认证 */// getLogin 用于展示登录表单。Route::get('/auth/login', 'Auth\AuthController@getLogin');// postLogin 用于提交用户登录数据。Route::post('/auth/login', 'Auth\AuthController@postLogin');// getLogout 用于退出登录。Route::get('/auth/logout', 'Auth\AuthController@getLogout');/** * 用户注册 */// getRegister 用于展示注册表单。Route::get('/auth/register', 'Auth\AuthController@getRegister');// postRegister 用于提交用户注册数据。Route::post('/auth/register', 'Auth\AuthController@postRegister');3 注册实现
3.1 编写视图