1
我使用Parse-Server和mailgun的cloudcode向註冊或更改其電子郵件的用戶發送電子郵件驗證代碼。如何使用DirtyKeys知道PFUser中的「email」字段是否已被修改?
的BeforeSave方法:
Parse.Cloud.beforeSave(Parse.User, function(request, response) {
var verificationCode = Math.floor(Math.random()*999999);
var text = "Hi ... this is a verification code:" + verificationCode;
var data = {
from: 'WBP Team <[email protected]>',
to: request.object.get("email"),
subject: 'Please verify your e-mail for you Account',
text: text
};
mailgun.messages().send(data, function (error, body) {
if (error) {
response.error("Email not sent..."+error);
}else{
var user = Parse.User.current();
user.set("emailVerificationCode", verificationCode);
user.save();
response.success("Email Sent");
}
console.log(body);
});
});
現在郵件發送每次用戶修改任何申請。但是我想僅在用戶更改電子郵件時使用該方法。
謝謝!我解決了它:) – Kingofmit