Skip to content

Instantly share code, notes, and snippets.

@JosephLenton
Created June 7, 2012 19:25
Show Gist options
  • Save JosephLenton/2891027 to your computer and use it in GitHub Desktop.
Save JosephLenton/2891027 to your computer and use it in GitHub Desktop.
controller for 5.4
<?
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