View difference between Paste ID: 4rp00uV1 and pdRRD5hB
SHOW: | | - or go back to the newest paste.
1
// Opção 1... Usar group...
2
Route::group(array('before' => 'auth'), function(){
3
	Route::controller(Controller::detect());
4
});
5
// Fim opção 1
6-
Route::get('login', function(){
6+
7-
	return View::make('dashboard.login');
7+
// Opção 2... Usar Filter para 'auth'
8
Route::filter('pattern: *', 'auth');
9
Route::controller(Controller::detect());
10-
Route::post('login', function(){
10+
// Fim opção 2
11-
	$userinfo = array(
11+
12-
		'username' => Input::get('login'),
12+
// Filter 'auth' com as validações
13-
		'password' => Input::get('senha')
13+
14-
	);
14+
15
	if(Auth::guest() && strpos(Request::route()->uri, 'auth') !== 0){
16-
	if(Auth::attempt($userinfo))
16+
		// NÃO Autenticado && NÃO INICIA com 'auth'
17-
		return Redirect::to('/');
17+
		// Ação: Redireciona para 'auth'
18-
	else
18+
		return Redirect::to('auth');
19-
		return Redirect::to('login')
19+
	}else if(!Auth::guest()){
20-
			->with('login_errors', true);
20+
		// AUTENTICADO
21
		// Ação: Valida caso auth/logout
22
		// O restante deixa passar mesmo!
23-
Route::get('logout', function(){
23+
		if( strpos(Request::route()->uri, 'auth') === 0){
24-
	Auth::logout();
24+
			if( !in_array('logout', Request::route()->parameters) ){
25-
	return Redirect::to('/');
25+
				return Redirect::to('dashboard');
26
			}
27
		}
28
			
29
	}
30-
	if (Auth::guest()) {
30+
31-
		return Redirect::to('login');
31+
	// O restante que chegar aqui é pra deixar passar mesmo, pois o importante já foi validado
32
});