0

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

8
  • Can you show your code. Commented Aug 12, 2015 at 9:12
  • @Jangyasatapathy, thanks for your answer. I tried to paste the relevant code here: pastebin.com/4FDmsGyE Commented Aug 12, 2015 at 9:14
  • Great code! I will get back to you soon with answers. Commented Aug 12, 2015 at 9:36
  • Simply do after catch echo '$error->getMessage()' Commented Aug 12, 2015 at 9:40
  • This still gets me this screen: imgur.com/sq6JEgz Commented Aug 12, 2015 at 10:49

1 Answer 1

2

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"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.