In the the app, the user can sign-up via email/password, Facebook or Twitter.
When they create an account via Facebook, the app sets the email field to their Facebook account. This is not true of Twitter because they don't share the email.
An issues arises when a user who signed up with Facebook, later decides to set a password.
The typical password change form consists of a three text fields:
If the user was created via Facebook, the PFUser object doesn't contain a password known to the user. Therefore the current password field cannot be required during the password change.
How can I tell if the user was created via Facebook/Twitter vs email/password since there is no method in Parse to check for an empty password?
Simply checking if they are linked with Facebook or Twitter isn't sufficient since the app also has an option to link and unlink Facebook or Twitter for an authenticated account.
I found a way to solve this that works in my particular case.
When the user signs up with an email/password, I have:
signupViewController.signUpView.emailAsUsername = YES;
Per the documentation, this sets the username and email to the same value on a the newly created PFUser.
However, even with this set, when a Facebook or Twitter is the first login, Parse sets the 'username' field for the user object to a hash.
This means Facebook and Twitter logins have a username that is not a valid email, which means the user has never set a password.
I accomplish this by adding the following method the class PFSubclassing PFUser:
-(BOOL)hasPassword
{
//isValidEmail is from a custom NSString category
if([self.username isValidEmail])
{
//they created their account with a username/password
return YES;
}
else
{
//they created their account with Facebook or Twitter
return NO;
}
}
This solution additional requires changing the username to the email when the password is set. This is required so that during the next password change, the 'old password' will be required.
Not the most elegant solution but works in the current version of the Parse Framework (v1.6.2).