Skip to content

Commit

Permalink
fix(Restwrite): Do not send verification email if users is authentica…
Browse files Browse the repository at this point in the history
…ted using some auth provider (#2660) (#3882)
  • Loading branch information
davimacedo authored and flovilmart committed May 30, 2017
1 parent 31744c5 commit 6cc99aa
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
31 changes: 31 additions & 0 deletions spec/ParseUser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3003,4 +3003,35 @@ describe('Parse.User testing', () => {
done();
}, done.fail);
});

it('should not send a verification email if the user signed up using oauth', (done) => {
let emailCalledCount = 0;
const emailAdapter = {
sendVerificationEmail: () => {
emailCalledCount++;
return Promise.resolve();
},
sendPasswordResetEmail: () => Promise.resolve(),
sendMail: () => Promise.resolve()
}
reconfigureServer({
appName: 'unused',
verifyUserEmails: true,
emailAdapter: emailAdapter,
publicServerURL: "http://localhost:8378/1"
});
const user = new Parse.User();
user.set('email', 'email1@host.com');
Parse.FacebookUtils.link(user, {
id: "8675309",
access_token: "jenny",
expiration_date: new Date().toJSON()
}).then((user) => {
user.set('email', 'email2@host.com');
user.save().then(() => {
expect(emailCalledCount).toBe(0);
done();
});
});
});
});
12 changes: 9 additions & 3 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,15 @@ RestWrite.prototype._validateEmail = function() {
if (results.length > 0) {
throw new Parse.Error(Parse.Error.EMAIL_TAKEN, 'Account already exists for this email address.');
}
// We updated the email, send a new validation
this.storage['sendVerificationEmail'] = true;
this.config.userController.setEmailVerifyToken(this.data);
if (
!this.data.authData ||
!Object.keys(this.data.authData).length ||
Object.keys(this.data.authData).length === 1 && Object.keys(this.data.authData)[0] === 'anonymous'
) {
// We updated the email, send a new validation
this.storage['sendVerificationEmail'] = true;
this.config.userController.setEmailVerifyToken(this.data);
}
});
};

Expand Down

0 comments on commit 6cc99aa

Please sign in to comment.