laravel记住登录、设置时间
来源:互联网 发布:淘宝客帐号怎么注册 编辑:程序博客网 时间:2024/05/22 13:02
laravel 自动登陆的时间改如何实现?
控制器
public function login()
{
$email =Input::get('email');
$password = Input::get('password');
$remember = Input::get('remember');
// lets validate the users input
$validator = Validator::make(
array(
'email' =>$email,
'password' =>$password
),
array(
'email' => 'required|email',
'password' => 'required'
)
);
if ($validator->fails()){
return Redirect::back()->withErrors($validator)->withInput();
}else{
if( Auth::attempt(array('email' => $email, 'password' => $password),$remember) ){
return Redirect::to('hud');
}else{
$validator->getMessageBag()->add('input', 'Incorrect email or password');
return Redirect::back()->withErrors($validator)->withInput();;
}
}
}
view层
@extends('templates.outs.auth')
@section('content')
<div class="special-form">
<a href="{{ route('home') }}"><img src="{{ \App\Helpers\Helpers::logoUrl() }}" alt=""></a>
<h3 class="text-center">LOGIN</h3>
@if ($errors->first())
<span class="status-msg error-msg">{{ $errors->first() }}</span>
@endif
<hr>
{!! Form::open(array('action' => 'UsersController@login')) !!}
<div class="form-group">
<label for="email" class="color-primary">Email:</label>
{!! Form::text( 'email', null, array('class' => 'form-control', "placeholder" => "Email","autofocus" => "true" )) !!}
</div>
<div class="form-group">
<label for="password" class="color-primary">Password:</label>
{!! Form::password( 'password', array('class' => 'form-control', "placeholder" => "Password" )) !!}
</div>
<div class="form-group">
<label for="remember" class="color-primary">Remember:</label>
<input type="checkbox" name="remember" value="remember me">
</div>
<div class="form-group">
{!! Form::submit( 'Login', array('class' => 'btn btn-primary btn-wide')) !!}
</div>
{!! Form::close() !!}
<p>Don't have an account? <a href="{{ route('register') }}">register</a></p>
</div>
@stop
路由
Route::get('login', function(){ return View::make('login')->with('pTitle', "Login"); })->name('login');
底层实现
public function login(UserContract $user, $remember = false)
{
$this->updateSession($user->getAuthIdentifier());
// If the user should be permanently "remembered" by the application we will
// queue a permanent cookie that contains the encrypted copy of the user
// identifier. We will then decrypt this later to retrieve the users.
if ($remember) {
$this->createRememberTokenIfDoesntExist($user);
$this->queueRecallerCookie($user);
}
// If we have an event dispatcher instance set we will fire an event so that
// any listeners will hook into the authentication events and run actions
// based on the login and logout events fired from the guard instances.
$this->fireLoginEvent($user, $remember);
$this->setUser($user);
}
比如我现在要设置30天都是可以自动登陆的,
前端设置一个name="remember"的checkbox
然后后台在attempt添加一个$remember对象、你只需接收checkbox的值是否为true就行了,因为默认$remember=false
'lifetime' => 43200,'expire_on_close' => false,
- laravel记住登录、设置时间
- laravel 修改记住我功能的cookie保存时间
- ssh 登录时间设置
- Laravel timestamps 设置为unix时间戳
- laravel 登录
- 系统登录后设置Cookie记住登陆信息
- 设置登录时间session属性
- iOS解决Cookie登录问题(记住第三方的cookie,下次登录记住cookie并设置cookie)
- 记住登录状态
- 登录实现记住密码
- 登录时记住密码
- android登录记住密码
- 记住密码登录
- 记住登录状态
- 登录时 记住我
- jquery记住登录密码
- 登录-记住用户名
- Cookie登录记住用户名
- java中类加载的全过程及内存图分析
- 天气不错很晴朗
- Android Launcher加载流程源码分析
- ld: library not found for -lAFNetworking clang: error: linker command failed with exit code 1 (use
- android studio 一直在提示 fail to open zip file,而且刚一clean就终止报错了
- laravel记住登录、设置时间
- 微信网页开发--仿美团、饿了么红包分享
- Hdu 3065 病毒侵袭持续中(AC自动机)
- 学习基于Koa2、Mongodb、jade的博客开发
- ButterKnife及插件使用教程
- DOM4j解析xml文件
- 数据结构
- Class PLBuildVersion is implemented in both frameworks(stackoverflow的 快照)
- AdminEAP框架数据列表render的五种方式