laravel 5 用户管理
来源:互联网 发布:如何上淘宝网买东西 编辑:程序博客网 时间:2024/06/05 06:59
路由配置
在路由中添加如下定义 查看是否存在 默认是已添加的
Route::get("auth/login",'Auth\AuthController@getLogin');Route::post("auth/login",'Auth\AuthController@postLogin');Route::get("auth/register",'Auth\AuthController@getRegister');Route::post("auth/register",'Auth\AuthController@postRegister');Route::get("auth/logout",'Auth\AuthController@getLogout');Route::get("user",'UserController@index'); //测试页面用于登录成功 注册成功后的跳转
模板
在resouces/views/下添加
auth/login.blade.php auth/register.blade.php
为何如此可跟踪
AuthController
AuthenticatesAndRegistersUsers
AuthenticatesUsers
login.blade.php中添加类似表单
{!! Form::open(["url"=>"auth/login"]) !!}<input type="text" name="email"><br><input type="text" name="password"><input type="submit">{!! Form::close() !!}@if($errors->any()) @foreach($errors->all() as $err) {!! $err !!} @endforeach@endif
注:提交地址
email password即可
默认是使用email做用户名验证的
$errors 是错误的提示
register.blade.php
<input type="text" name="name"><br><input type="text" name="email"><br><input type="text" name="password"><br><input type="text" name="password_confirmation"><input type="submit">{!! Form::close() !!}@if($errors->any()) @foreach($errors->all() as $err) {!! $err !!} @endforeach@endif
password_confirmation两次密码验证
测试
正常 访问 http://localhost:8000/auth/register应该没问题了,
注册成功后url会找不到http://localhost:8000/home
因默认成功后返回到/home,项目中没有,
更改默认提交后地址
<?phpnamespace Illuminate\Foundation\Auth;trait RedirectsUsers{ /** * Get the post register / login redirect path. * * @return string */ public function redirectPath() { if (property_exists($this, 'redirectPath')) { return $this->redirectPath; } return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home'; }}
从代码中可以看到如果定义了redirectPath属性则会就使用redirectPath的值了。
在authController.php下添加 redirectPath
class AuthController extends Controller{ /* |-------------------------------------------------------------------------- | Registration & Login Controller |-------------------------------------------------------------------------- | | This controller handles the registration of new users, as well as the | authentication of existing users. By default, this controller uses | a simple trait to add these behaviors. Why don't you explore it? | */ use AuthenticatesAndRegistersUsers, ThrottlesLogins; protected $redirectPath="/user"; //注册后的页面 protected $redirectAfterLogout="/user"; //注销后的页 getLogout
查看当前用户的登录信息
// dd(Auth::user()); //当前登录的用户信息 dd(User::all());
Auth::user()->name 即取出当前的用户名
使用用户名登录验证
从AuthenticatesUsers的以下方法中可看出
public function loginUsername() { return property_exists($this, 'username') ? $this->username : 'email'; }
如果有username属性就使用username作为登录名否则使用email
protected $username="name"; //使用用户登录 从AuthenticatesUsers中的loginUsername找到的
用户信息添加其它信息
数据库添加字段,添加migrate命令重新生成表
模型中添加
控制器中添加
0 0
- laravel 5 用户管理
- Laravel大型项目系列教程(二)之用户管理
- Laravel-使用中间件做用户认证和权限管理
- Laravel 用户认证
- Laravel 重写用户登录
- laravel 用户身份验证
- Laravel 用户之间关注
- LARAVEL 用户登录实例
- Laravel的路由管理
- laravel 权限管理
- laravel entrust 权限管理
- Laravel-日志管理
- laravel 5.5 创建用户对象
- Laravel的用户认证模块
- Laravel 用户认证体系详解
- CentOS6.5的用户管理
- linux-5 用户的管理
- Laravel 5
- swing之进度监视
- ubuntu中安装和卸载apache2
- soj 1679 Gangsters(dp)
- Apache 调试日志
- Cocos2D旋转炮塔到指定角度(一)
- laravel 5 用户管理
- 编程设计-如何写可维护的程序. 通往架构思维之路
- android 在kernel中获取启动kernel命令行的参数
- Drools入门系列(五)——KIE概论
- armeabi、mips、x86、armeabi-v7a、armeabiarmeabi-v7a等的初步理解
- QT 编程 learn
- Swift Literal Convertibles
- 静态map成员的一种替代方法
- grunt使用的一些感悟