<?php
class SessionController extends \BaseController
{
public function showLogin()
{
if(Auth::check())
{
return Redirect::route('user');
}
return View::make('login');
}
public function doLogin()
{
$rules = array(
'email' => 'required|email',
'password' => 'required|alphaNum|min:3'
);
$validator = Validator::make(Input::all(), $rules);
$remember = \Input::get('remember');
if ($validator->fails()) {
return Redirect::to('login')
->withErrors($validator)
->withInput(Input::except('password'));
} else {
$userdata = array(
'email' => Input::get('email'),
'password' => Input::get('password')
);
if($remember == 'yes')
{
if (Auth::attempt($userdata, true))
{
return \Redirect::intended('/');
} else {
return \Redirect::to('login');
}
}else
{
if (Auth::attempt($userdata))
{
return \Redirect::intended('/');
} else {
return \Redirect::to('login');
}
}
}
}
public function doLogout()
{
Auth::logout();
return Redirect::to('login');
Session::forget('user');
}
}