Created
June 7, 2012 19:25
-
-
Save JosephLenton/2891027 to your computer and use it in GitHub Desktop.
controller for 5.4
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
<? | |
ajax()->login = function() { | |
// is already logged in | |
ajax()->verify( function() { | |
return $this->obj->session->isLoggedIn(); | |
}); | |
// login with all details | |
ajax()-> | |
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 ); | |
} )-> | |
action( | |
// success \o/ | |
function($username, $password, $remember_me, $user, $location) { | |
$this->session->loginUser( $user, $remember_me ); | |
$location = strtolower( $location ); | |
if ( preg_match('/^(http(s?):\/\/)?[a-zA-Z.]+\/build\/try_pmc(\/.*)?$/', $location) > 0 ) { | |
return array( 'redirect' => '/build' ); | |
} else { | |
return true; | |
} | |
}, | |
// fail : ( | |
function($error) { | |
return jsError( $error ); | |
} | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment