-
-
Save tristar500/4394565 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
|-------------------------------------------------------------------------- | |
| Register | |
|-------------------------------------------------------------------------- | |
*/ | |
Route::get('register', function() | |
{ | |
return View::make('register'); | |
}); | |
Route::post('register', function() | |
{ | |
$input = Input::get(); //receive input | |
try | |
{ | |
//create some validation rules | |
$rules = array( | |
'email' => 'required|email|unique:users', | |
'password' => 'same:confirm' | |
); | |
//validate the inputs | |
$validation = Validator::make($input, $rules); | |
if($validation->fails()) | |
{ | |
return Redirect::to('register')->with_errors($validation); | |
} | |
else | |
{ | |
unset($input['confirm']); | |
$user = Sentry::user()->create($input); | |
if($user) | |
{ | |
Return Redirect::to('login'); | |
} | |
} | |
} | |
catch (Sentry\SentryException $e) | |
{ | |
//create a real Laravel\Messages object from a sentry error. | |
$errors = new Laravel\Messages(); | |
$errors->add('sentry', $e->getMessage()); | |
Return Redirect::to('register')->with_errors($errors); | |
} | |
}); | |
/* | |
|-------------------------------------------------------------------------- | |
| Login | |
|-------------------------------------------------------------------------- | |
*/ | |
Route::get('login', function() | |
{ | |
return View::make('login'); | |
}); | |
Route::post('login', function() | |
{ | |
try | |
{ | |
$valid_login = Sentry::login(Input::get('email'), Input::get('password'), true); | |
if ($valid_login) | |
{ | |
Return Redirect::to('test'); | |
} | |
} | |
catch (Sentry\SentryException $e) | |
{ | |
$errors = new Laravel\Messages(); | |
$errors->add('sentry', $e->getMessage()); | |
Return Redirect::to('login')->with_errors($errors); | |
} | |
}); | |
/* | |
|-------------------------------------------------------------------------- | |
| Logout | |
|-------------------------------------------------------------------------- | |
*/ | |
Route::get('logout', function() | |
{ | |
Sentry::logout(); | |
return Redirect::to('home'); | |
}); | |
/* | |
|-------------------------------------------------------------------------- | |
| Test | |
|-------------------------------------------------------------------------- | |
*/ | |
Route::get('test', array('before' => 'sentry', 'do' => function() | |
{ | |
Return View::make('test'); | |
})); | |
/* | |
|-------------------------------------------------------------------------- | |
| Filter | |
|-------------------------------------------------------------------------- | |
*/ | |
Route::filter('sentry', function() | |
{ | |
if (!Sentry::check()) return Redirect::to('login'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment