Created
October 2, 2015 17:03
-
-
Save jeffhuangtw/ef31f0b5b35b34ce2173 to your computer and use it in GitHub Desktop.
Resend Parse User Verification Email Cloud Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// resend verify email | |
Parse.Cloud.define("ResendVerifyEmail", function(request, response) { | |
var user = Parse.User.current(); | |
if (!user) { | |
response.error("INVALID_USER"); | |
return; | |
} | |
var email = request.params.email; | |
var query = new Parse.Query(Parse.User); | |
Parse.Cloud.useMasterKey(); | |
query.equalTo('objectId', user.id); | |
query.first().then(function(userObj) { | |
if (userObj != undefined) { | |
console.log("ResendVerifyEmail:" + user.id + " update email from:" + userObj.get("email") + " to:" + email); | |
userObj.unset("email"); // set empty | |
return userObj.save(); | |
} else { | |
return Parse.Promise.error("INVALID_USER"); | |
} | |
}).then(function(updatedObj) { | |
updatedObj.set("email", email); // set email to trigger resend verify Email | |
return updatedObj.save(); | |
}).then(function(obj) { | |
response.success('ok'); | |
}, function(error) { | |
response.error(error); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Parse.Cloud.useMasterKey() deprecated for a long time.
parse-community/parse-server#37
I think it should be as following
Btw, In our current design, I do the follwing things.
If there is user matched, server will trigger an reset email with mailgun/mandril with forgot password email template
generate the encrypted token in the email link
If the token is verified, show the reset password UI