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记住登录、设置时间的更多相关文章

  1. Web---Cookie技术(显示用户上次登录的时间、显示用户最近浏览的若干个图片(按比例缩放))

    本章博客讲解: 1.Cookie基本用法演示 2.演示Cookie的访问权限 3.演示Cookie的删除 4.利用Cookie显示用户上次登录的时间 5.利用Cookie技术显示用户最近浏览的若干个图 ...

  2. WPF仿网易云音乐系列(二、歌单创建窗口+登录设置模块)

    老衲牺牲午休时间写博客,都快把自己感动了,-_-!! 之前上一篇随笔,我看了下评论,有部分人说WPF已经凉凉了,这个我觉得,这只是一个达到自己目的的工具而已,只要自己能用这个工具,得心应手的做出自己想 ...

  3. net mvc中实现记录用户登录信息(记住登录效果)

    现记录用户登录信息(记住登录效果) 本文讲述了使用cookies实现网站记住登录效果,效果如下: 主要实现方法,当用户选择记住登录时建立cookies保存用户名和用户密码,当用户登录不选择记住登录时, ...

  4. laravel 用户名登录

    laravel 用户名登录 默认登录设置为用户登录 laravel 5.3+ 修改文件(app\Http\Controllers\Auth\LoginController.php)增加 public ...

  5. mac laravel 环境变量设置bash_profile

    mac laravel 环境变量设置bash_profile >>>vim ~/.bash_profile '''text export PATH=$PATH:~/.composer ...

  6. 设置时间&时区

    设置时间之前要先了解一件事,时间分为系统时间与硬件时间 如果硬件时间与系统时间不相同的话,经常会发现自己写的程序时间可能对不上 首先修改硬件时间 1)修改时区 输入命令: tzselect 按照指示选 ...

  7. jQuery实例-记住登录信息

    本文介绍下jquery 记住登录信息的方法,引入jquery.cookie.js文件,实现记住登录信息,有需要的朋友参考下. 首先,导入jquery.cookie.js $(function(){ / ...

  8. centos修改时区,设置时间

    在我们使用CentOS系统的时候,也许时区经常会出现问题,有时候改完之后还是会出错,下面我们就来学习一种方法来改变这个状况.如果没有安装,而你使用的是 CentOS系统 那使用命令 yum insta ...

  9. Java json设置时间格式,Jackson设置时间格式,json设置单引号

    Java json设置时间格式,Jackson设置时间格式,json设置单引号 >>>>>>>>>>>>>>> ...

随机推荐

  1. 读CSV转换datatable

    using System.Data; using System.IO;   /// <summary> /// Stream读取.csv文件 /// </summary> // ...

  2. [Java学习] Java异常处理基础

    Java异常是一个描述在代码段中发生的异常(也就是出错)情况的对象.当异常情况发生,一个代表该异常的对象被创建并且在导致该错误的方法中被抛出(throw).该方法可以选择自己处理异常或传递该异常.两种 ...

  3. Illumina Sequence Identifiers 序列标识符 index详解

    大家基本都知道什么是 FASTA 和 FastQ 格式了,但这是不够的. 我们还需要了解世界上最大的测序公司自己定制的 FastQ 格式,因为你可能会经常用到,有时还会亲自去处理它们. 本文主题:Il ...

  4. jquery添加类

    一.addClass() 方法向被选元素添加一个或多个类. 1.对P元素添加一个intro类.<!DOCTYPE html><html><head lang=" ...

  5. POJ-1129 Channel Allocation (DFS)

    Description When a radio station is broadcasting over a very large area, repeaters are used to retra ...

  6. React-Router v4.0 hashRouter使用js跳转

    React-Router v4.0上已经不推荐使用hashRouter,主推browserRouter,但是因为使用browserRouter需要服务端配合可能造成不便,有时还是需要用到hashRou ...

  7. kill word fore out

    1●   fore f ɔ: 预先,前面

  8. C++模板详解——使用篇

    假如我们需要取得两个变量中较大的变量,或许,我们可以通过重载的方式实现,如下. int max(int fir,int sec); float max(float fir,float sec); do ...

  9. 快速切题 sgu123. The sum

    123. The sum time limit per test: 0.25 sec. memory limit per test: 4096 KB The Fibonacci sequence of ...

  10. ZOJ 3161 Damn Couples 动态规划 难度:2

    Damn Couples Time Limit: 1 Second      Memory Limit: 32768 KB As mentioned in the problem "Coup ...