Reputation: 95
I'm working on some PHP website, and I'm using the Parse.com SDK.
So, the SDK has some built-in "LogIn" function which is working fine, there is just one issue: if the login fails (bad credentials for example) it's throwing an exception, thus stopping the website from running.
Is there a way to not do that? And just show a message like "Bad credentials" or something? (I don't want to alter the default login function, I just want a way - if there is - to not stop the website from running when this exception is thrown)
Before someone asks: YES I've already consulted multiple times the documentation on the SDK. YES I've already asked it to the Parse community on their Google Group (which is inactive it seems). And finally YES I've searched about this on other forums (the whole point of posting it here, is that I didn't found it).
Thank you for helping :-)
Solid
Upvotes: 0
Views: 193
Reputation: 56
You can use this code,
function user_login($username, $password) {
try {
$user = ParseUser::logIn($username, $password);
return $user;
} catch (ParseException $error) {
return FALSE;
}
catch (Exception $e) {
return FALSE;
}
}
$user = user_login($username, $password);
if($user){
// $message = "Logged in";
// code to show message whether user logged in
} else {
// $message = "Bad credentials";
// code to show message "bad credentials"
}
Upvotes: 2