Skip to content

Instantly share code, notes, and snippets.

@JosephLenton
Created June 7, 2012 20:12
Show Gist options
  • Save JosephLenton/2891281 to your computer and use it in GitHub Desktop.
Save JosephLenton/2891281 to your computer and use it in GitHub Desktop.
login code for 5.4 framework
<?
get( 'login' );
post()->login = function() {
// is already logged in
post()->
verify( function() {
return $this->obj->session->isLoggedIn();
})->
redirect( '/' );
// login attempt
post()->
verify( function($username, $password, $location, $user, $error) {
$username->trim()->exists()->len( 1, 15 )->regex( Home::USERNAME_REGEX )
and
$password->trim()->exists()->minLen( Users::PASSWORD_MIN_LEN )
and
$location->trim()
and
list( $user, $error ) = $this->model->users->userLogin( $username, $password );
} )->
action(
// success \o/
function($username, $password, $remember_me, $user) {
$this->session->loginUser( $user, $remember_me );
$this->redirect( '/' );
},
// fail : (
function($error) {
$this->view( 'login/index', $error );
}
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment