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. 4-6 select_tag和select的区别和理解。javascript_tag

    via: :all是什么意思?主要用于约束http动作. <%= select_tag "set_locale", options_for_select(LANGUAGES, ...

  2. 我的Java学习笔记 -开发环境搭建

    开始学习Java~ 一.Java简介 Java编程语言是一种简单.面向对象.分布式.解释型.健壮安全.与系统无关.可移植.高性能.多线程和动态的语言. Java分为三个体系: JavaSE(J2SE) ...

  3. H.Playing games

    fwt #include<bits/stdc++.h> using namespace std; const int N=1<<19; const int mod=100000 ...

  4. hdu-4678-sg

    Mine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  5. OC MRC之多对象之间管理(代码分析)

    #import <Foundation/Foundation.h> @interface Book : NSObject { int _price; } - (void)setPrice: ...

  6. Intel daal4py demo运行过程

    daal安装(记得先安装anaconda): git clone https://github.com/IntelPython/daal4py.git cd daal4py conda create ...

  7. VAE demo

    先看tflearn 官方的: from __future__ import division, print_function, absolute_import import numpy as np i ...

  8. 使用Windbg解析dump文件

    WinDbg OllyDbg SoftICE (已经停止更新) 虽说WinDbg在无源码调试方面确实比较困难,但在调试内核方面却真的有独到之处. https://www.pediy.com/kssd/ ...

  9. laravel中通过查询构造器,实现数据的curd

    //查询构造器: public function query1(){ //利用查询构造器,插入数据: /*$num=DB::table('student')->insert( ['name'=& ...

  10. python3.6 ubuntu

    apt-get install python3.6-dev 安装 pip install mysqlclient 必备