Created
October 11, 2013 21:22
-
-
Save spacious/6942233 to your computer and use it in GitHub Desktop.
Example of a login with Sparse
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
// This code would be on any PHP page handling the login form | |
// Create a User suitable for logging in | |
$loggingInUser = new \Sparse\User(array('username'=>$_POST['username'],'password'=>$_POST['password'])); | |
// Make actual login API call | |
$loggingInUser->logIn(); | |
// This will be true if it worked | |
if($loggingInUser->authenticated()){ | |
// Do something special | |
}else{ | |
$error = "Could not login. Please try again."; | |
} | |
// After logging in, subsequent page loads can do this... | |
$user = \Sparse\User::current(); | |
if($user->authenticated()){ | |
// Still logged in! | |
}else{ | |
// show login | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment