Skip to content

Instantly share code, notes, and snippets.

@spacious
Created October 11, 2013 21:22
Show Gist options
  • Save spacious/6942233 to your computer and use it in GitHub Desktop.
Save spacious/6942233 to your computer and use it in GitHub Desktop.
Example of a login with Sparse
// 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