Login and Register Functional
研究了一晚上,总算初步搞懂 laravel 自带的 user 模块。
注册 Routes:
1 2 3 4 5 6 |
// Authentication routes... Route::post('auth/login', 'Auth\AuthController@postLogin'); Route::get('auth/logout', 'Auth\AuthController@getLogout'); // Registration routes... Route::post('auth/register', 'Auth\AuthController@postRegister'); |
blade 中判断是否已经登录:
1 2 3 4 5 |
@if (Auth::guest()) @else @endif |
blade 中抛出 Error 信息:
1 2 3 4 5 6 7 8 9 |
@if (count($errors) > 0) <div> <ul> @foreach ($errors->all() as $error) <li><i class="fa fa-warning"></i>{{ $error }}</li> @endforeach </ul> </div> @endif |
AuthController 中设定登录和注册后的返回页面:
1 2 |
protected $loginPath="/"; protected $redirectTo="/"; |
vendor 中有两个 class 分别控制登录和注册:
1 2 3 4 5 6 |
trait AuthenticatesAndRegistersUsers { use AuthenticatesUsers, RegistersUsers { AuthenticatesUsers::redirectPath insteadof RegistersUsers; } } |
修改 postLogin,增加邮箱后缀,完成登录验证后再去掉:
1 2 3 4 5 6 7 |
if (!$request['email']==null){ $request['email']=$request['email']."@morningstar.com"; } ... $request['email']=str_replace('@morningstar.com','',$request['email']); |
修改 postRegister,增加邮箱后缀,用户名直接跟邮箱同名:
1 2 |
$request['name']=$request['email']; $request['email']=$request['email']."@morningstar.com"; |
架空了 getLogin 和 getRegister,因为没必要分别做一个登录和注册的页面。
最后学习了怎样根据浏览器分辨率调整 div 的宽度,IE8 必然是不支持的,不过 I don’t care 哈哈。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
@media screen and (min-width: 1601px) { .sidebar { width: 16.7%; } .mainframe { width: 83.3%; } } @media screen and (max-width: 1600px) { .sidebar { width: 25%; } .mainframe { width: 75%; } } @media screen and (max-width: 800px) { .sidebar { width: 100%; } .mainframe { width: 100%; } } |
最后,去掉了隐藏左侧栏的动画,反正也不怎么好看。