Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.63 KB | None | 0 0
  1. <?php
  2.  
  3. class IndexController extends BaseController { 
  4.    
  5.     public function showLogin(){
  6.        
  7.         return View::make('hello');
  8.        
  9.     }
  10.    
  11.     public function doLogin(){
  12.         if (Auth::user() != null)
  13.         {
  14.             BaseController::myLogger('user '.Auth::user()->username.' from '.$_SERVER['REMOTE_ADDR'] .' logged out successfully!');
  15.             Auth::logout();
  16.         }
  17.  
  18.         $rules = array(
  19.             'username'    => 'required|min:2',
  20.             'password' => 'required|alphaNum'
  21.             );
  22.  
  23.        
  24.         $validator = Validator::make(Input::all(), $rules);
  25.        
  26.         if ($validator->fails()) {
  27.             $messages = $validator->messages();
  28.             BaseController::myLogger('validation fails: '.$messages);  
  29.             return Redirect::to('login')
  30.             ->withErrors($validator)->withInput();
  31.                    
  32.         } else {           
  33.             $userdata = array(
  34.                 'username'  => Input::get('username'),
  35.                 'password'  => Input::get('password')
  36.                 );
  37.                
  38.             //authentication
  39.             //if it success it'll log in the user
  40.             if (Auth::attempt($userdata)) {
  41.                 BaseController::myLogger('user '.Auth::user()->username.' from '.$_SERVER['REMOTE_ADDR'].' logged in successfully!' );
  42.                 return Redirect::to('home');
  43.                
  44.             } else {
  45.                 BaseController::myLogger('username and/or password was incorrect for the given username:'.$userdata['username']);  
  46.                 return Redirect::to('login')
  47.                 ->with('flash_error', 'Your username and/or password was incorrect.')
  48.                 ->withInput();
  49.  
  50.             }
  51.  
  52.         }
  53.     }
  54.    
  55.     public function doLogout()
  56.     {
  57.         if (Auth::user() != null)
  58.         {
  59.             BaseController::myLogger('user '.Auth::user()->username.' from '.$_SERVER['REMOTE_ADDR'] .' logged out successfully!');
  60.             Auth::logout();
  61.         }
  62.         return Redirect::to('');
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement