Created
July 15, 2013 13:02
-
-
Save frenetic/5999757 to your computer and use it in GitHub Desktop.
Routes + Controller para login básico no Laravel 4.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Routes.php | |
| /* login */ | |
| Route::get('login', 'BaseController@getLogin'); | |
| Route::post('login', ['before' => 'csrf', 'uses' => 'BaseController@postLogin']); | |
| //LoginController.php | |
| class LoginController extends BaseController | |
| { | |
| public function getLogin() | |
| { | |
| return View::make('login'); | |
| } | |
| public function postLogin() | |
| { | |
| $regras = array("email" => "required|email", | |
| "senha" => "required"); | |
| $validacao = Validator::make(Input::all(), $regras); | |
| if ($validacao->fails()) { | |
| return Redirect::to('login')->withErrors($validacao); | |
| } | |
| //tenta logar o usuário | |
| if (Auth::attempt( array('email' => Input::get('email'), 'password' => Input::get('senha') ) ) ) { | |
| return Redirect::to('/'); | |
| } | |
| else { | |
| return Redirect::to('login')->withErrors('Usuário ou Senha Inválido'); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment