laravel记住登录、设置时间
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记住登录、设置时间的更多相关文章
- Web---Cookie技术(显示用户上次登录的时间、显示用户最近浏览的若干个图片(按比例缩放))
本章博客讲解: 1.Cookie基本用法演示 2.演示Cookie的访问权限 3.演示Cookie的删除 4.利用Cookie显示用户上次登录的时间 5.利用Cookie技术显示用户最近浏览的若干个图 ...
- WPF仿网易云音乐系列(二、歌单创建窗口+登录设置模块)
老衲牺牲午休时间写博客,都快把自己感动了,-_-!! 之前上一篇随笔,我看了下评论,有部分人说WPF已经凉凉了,这个我觉得,这只是一个达到自己目的的工具而已,只要自己能用这个工具,得心应手的做出自己想 ...
- net mvc中实现记录用户登录信息(记住登录效果)
现记录用户登录信息(记住登录效果) 本文讲述了使用cookies实现网站记住登录效果,效果如下: 主要实现方法,当用户选择记住登录时建立cookies保存用户名和用户密码,当用户登录不选择记住登录时, ...
- laravel 用户名登录
laravel 用户名登录 默认登录设置为用户登录 laravel 5.3+ 修改文件(app\Http\Controllers\Auth\LoginController.php)增加 public ...
- mac laravel 环境变量设置bash_profile
mac laravel 环境变量设置bash_profile >>>vim ~/.bash_profile '''text export PATH=$PATH:~/.composer ...
- 设置时间&时区
设置时间之前要先了解一件事,时间分为系统时间与硬件时间 如果硬件时间与系统时间不相同的话,经常会发现自己写的程序时间可能对不上 首先修改硬件时间 1)修改时区 输入命令: tzselect 按照指示选 ...
- jQuery实例-记住登录信息
本文介绍下jquery 记住登录信息的方法,引入jquery.cookie.js文件,实现记住登录信息,有需要的朋友参考下. 首先,导入jquery.cookie.js $(function(){ / ...
- centos修改时区,设置时间
在我们使用CentOS系统的时候,也许时区经常会出现问题,有时候改完之后还是会出错,下面我们就来学习一种方法来改变这个状况.如果没有安装,而你使用的是 CentOS系统 那使用命令 yum insta ...
- Java json设置时间格式,Jackson设置时间格式,json设置单引号
Java json设置时间格式,Jackson设置时间格式,json设置单引号 >>>>>>>>>>>>>>> ...
随机推荐
- 3.2 x86体系结构
计算机组成 3 指令系统体系结构 3.2 x86体系结构 X86是商业上最为成功,影响力最大的一种体系结构.但从技术的角度看,它又存在着很多的问题,那我们就来一起分析X86这种体系结构的特点. 要探讨 ...
- mysql数据库切分
一.数据的垂直切分概念:数据的垂直切分,也可以称之为纵向切分.将不同的表分散到不同的数据库主机中.一个应用系统,总体功能肯定是由很多个功能模块所组成的,而每一个功能模块所需要的数据对应到数据库中就是一 ...
- LeetCode--226--翻转二叉树
问题描述: 翻转一棵二叉树. 示例: 输入: 4 / \ 2 7 / \ / \ 1 3 6 9 输出: 4 / \ 7 2 / \ / \ 9 6 3 1 备注: 这个问题是受到 Max Howel ...
- C++中的赋值运算符重载函数(operator=)
MyStr& operator =(const MyStr& str)//赋值运算符 { cout << "operator =" << e ...
- python运维之使用python进行批量管理主机
1. python运维之paramiko 2. FABRIC 一个与多台服务器远程交互的PYTHON库和工具 3. SSH连接与自动化部署工具paramiko与Fabric 4. Python批量管理 ...
- 算法笔记——C/C++语言基础篇(已完结)
开始系统学习算法,希望自己能够坚持下去,期间会把常用到的算法写进此博客,便于以后复习,同时希望能够给初学者提供一定的帮助,手敲难免存在错误,欢迎评论指正,共同学习.博客也可能会引用别人写的代码,如有引 ...
- js中JSON.stringify用于自定义的类
参考:http://stackoverflow.com/questions/7356694/how-to-json-stringify-a-user-defined-class-in-javascri ...
- spring cloud学习(七)Spring Cloud Config(续)
Spring Cloud Config(续) 个人参考项目 个人博客 : https://zggdczfr.cn/ 个人参考项目 : (整合到上一个案例中)https://github.com/Fun ...
- UVALIve 5987 素数
题目链接:Distinct Primes 如果一个数.至少有三个因子是素数..那么这个数就是prime num.30和42是前两个prime num.问你第n个这种数是谁.(1<=n<=1 ...
- [转]利用docker进行java开发小demo
http://www.codeceo.com/article/docker-java-development.html