Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class IndexController extends BaseController {
- public function showLogin(){
- return View::make('hello');
- }
- public function doLogin(){
- if (Auth::user() != null)
- {
- BaseController::myLogger('user '.Auth::user()->username.' from '.$_SERVER['REMOTE_ADDR'] .' logged out successfully!');
- Auth::logout();
- }
- $rules = array(
- 'username' => 'required|min:2',
- 'password' => 'required|alphaNum'
- );
- $validator = Validator::make(Input::all(), $rules);
- if ($validator->fails()) {
- $messages = $validator->messages();
- BaseController::myLogger('validation fails: '.$messages);
- return Redirect::to('login')
- ->withErrors($validator)->withInput();
- } else {
- $userdata = array(
- 'username' => Input::get('username'),
- 'password' => Input::get('password')
- );
- //authentication
- //if it success it'll log in the user
- if (Auth::attempt($userdata)) {
- BaseController::myLogger('user '.Auth::user()->username.' from '.$_SERVER['REMOTE_ADDR'].' logged in successfully!' );
- return Redirect::to('home');
- } else {
- BaseController::myLogger('username and/or password was incorrect for the given username:'.$userdata['username']);
- return Redirect::to('login')
- ->with('flash_error', 'Your username and/or password was incorrect.')
- ->withInput();
- }
- }
- }
- public function doLogout()
- {
- if (Auth::user() != null)
- {
- BaseController::myLogger('user '.Auth::user()->username.' from '.$_SERVER['REMOTE_ADDR'] .' logged out successfully!');
- Auth::logout();
- }
- return Redirect::to('');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement