PHP Tutorial Laravel 4 Framework (Authentication) - Remember Me
bogotobogo.com site search:
Laravel 4
- Installing on Ubuntu - local
- Installing on a Shared host
- Installing on Windows
- Creating users table
- Home page with controller and blade
- Blade Templating
- Database connection and sending emails
- Creating user account I - GET
- Creating user account II - POST
- Creating user account III - Error checking & redirecting input
- Creating user account IV - User::create()
- Activating user account I - Mail::send()
- Activating user account II - Update user's status
- User account sign-in I - Route and link
- User account sign-in II - Validation
- User account sign-in III - Login Authentication
- Singing out
- Remember the user
- Changing Password I
- Changing Password II
- Recovering forgotten password I
- Recovering forgotten password II
- User Profile
- Database Migration using artisan
bogotobogo.com site search:
Note
This tutorial is the continuation from Singing out.
Now that a user can sign in and sign out, we want to have our app remember the user's information if the user wants.
Check box in sign in page
In this section, we'll provide a check box so that a user can have a choice for the remember feature.
views/account/signin.blade.php file:
@extends('layout.main') @section('content') <form action="{{ URL::route('account-sign-in-post') }}" method="post"> <div class="field"> Email: <input type="text" name="email" value="{{ Input::old('email') }}"> @if($errors->has('email')) {{ $errors->first('email')}} @endif </div> <div class="field"> Password: <input type="password" name="password" > @if($errors->has('password')) {{ $errors->first('password')}} @endif </div> <div class="field"> <input type="checkbox" name="remember" id="remember"> <label for="remember"> Remember me </div> <input type="submit" value="Sign in"> {{ Form::token() }} </form> @stop
So, how we can make it work?
Implementing remember
We will work on the postSignIn() function in AccountController.php file:
public function postSignIn() { $validator = Validator::make(Input::all(), array( 'email' => 'required|email', 'password' => 'required' ) ); if($validator->fails()) { // Redirect to the sign in page return Redirect::route('account-sign-in') ->withErrors($validator) ->withInput(); // redirect the input } else { $remember = (Input::has('remember')) ? true : false; $auth = Auth::attempt(array( 'email' => Input::get('email'), 'password' => Input::get('password'), 'active' => 1 ), $remember); }
Sign in without checked
We can see additional cookies for the session compared with the case when signed in without checking the Remember.
Sign in witchecked
Laravel 4
- Installing on Ubuntu - local
- Installing on a Shared host
- Installing on Windows
- Creating users table
- Home page with controller and blade
- Blade Templating
- Database connection and sending emails
- Creating user account I - GET
- Creating user account II - POST
- Creating user account III - Error checking & redirecting input
- Creating user account IV - User::create()
- Activating user account I - Mail::send()
- Activating user account II - Update user's status
- User account sign-in I - Route and link
- User account sign-in II - Validation
- User account sign-in III - Login Authentication
- Singing out
- Remember the user
- Changing Password I
- Changing Password II
- Recovering forgotten password I
- Recovering forgotten password II
- User Profile
- Database Migration using artisan
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization