PHP Tutorial Laravel 4 Framework (Authentication) - User Account Signin I
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
This tutorial is the continuation from Activating user account II - Update user's status.
Now that the user's account can be activated, we want to process the user's sign-in request. So, we need to provide the sign-in form.
In this section, we'll setup the route for the sign-in page and write get / post methods for the sign-in form.
routes.php file:
<?php Route::get('/', array('as' => 'home', 'uses' => 'HomeController@home' )); /* Unauthenticated group */ Route::group(array('before' => 'guest'), function() { /* CSRF protection */ Route::group(array('before' => 'csrf'), function() { /* Create an account (POST) */ Route::post('/account/create', array('as' => 'account-create-post', 'uses' => 'AccountController@postCreate' )); /* Sign in (POST) */ Route::post('/account/sign-in', array('as' => 'account-sign-in-post', 'uses' => 'AccountController@postSignIn' )); }); /* Sign in (GET) */ Route::get('/account/sign-in', array('as' => 'account-sign-in', 'uses' => 'AccountController@getSignIn' )); /* Create an account (GET) */ Route::get('/account/create', array('as' => 'account-create', 'uses' => 'AccountController@getCreate' )); /* Activate an account */ Route::get('/account/activate/{code}', array('as' => 'account-activate', 'uses' => 'AccountController@getActivate' )); });
AccountController.php file:
<?php class AccountController extends BaseController { public function getSignIn() { } public function postSignIn() { } ...
signin.blade.php template file:
@extends('layout.main') @section('content') Sign in. @stop
With a slightly modified AccountController.php to return the view for signin:
class AccountController extends BaseController { /* Viewing the sign-in form */ public function getSignIn() { return View::make('account.signin'); }
And witt the following navigation:views/layout/navigation.blade.php:
<nav> <ul> <li> <a href="{{ URL::route('home') }}">Home</a></li> @if(Auth::check()) @else <li><a href="{{ URL::route('account-sign-in') }}">Sign in</a></li> <li><a href="{{ URL::route('account-create') }}">Create an account</a></li> @endif </ul> </nav>
Now, we have a sing-in link in our root page:
But the sign-in link does nothing becase we haven't redirected the link to sign-in page. So, if we do it now:
<li><a href="{{ URL::route('account-sign-in') }}">Sign in</a></li>
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