简体   繁体   English

解析 - 重新发送电子邮件验证

[英]Parse - Resend Email Verification

So I want to be able to resend an email verification, based on the users inputted email address in a UITextField and build whether the email address has already been verified or not. 因此,我希望能够根据用户在UITextField中输入的电子邮件地址重新发送电子邮件验证,并构建电子邮件地址是否已经过验证。 Now I know I need to "resave" the email address for parse to send the email. 现在我知道我需要“重新保存”电子邮件地址以便解析发送电子邮件。 However when I'm looking up in the database the email address it keeps saying it cannot find it and the email address is definitely there and not verified. 然而,当我在数据库中查找电子邮件地址时,它一直说它找不到它,电子邮件地址肯定存在且未经验证。

-(IBAction)emailVerification:(id)sender{
PFQuery *query = [PFQuery queryWithClassName:@"User"];
[query whereKey:@"email" equalTo:self.email.text];
[query whereKey:@"emailVerified" equalTo:false];
[query getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
    if (!object) {
        NSLog(@"The getFirstObject request failed.");
        //Failed, incorrect email address
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Error" message:@"Check your internet connection and/or the email address"delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil,nil];
        [alert show];
    }
    else {
        //found email address check verified
        NSLog(@"Successfully retrieved the object.");
        [query whereKey:@"emailVerified" equalTo:false];
        [query getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
            if (!object) {
                // The find succeeded.
                object[@"email"]=self.email.text;
                [object saveInBackground];

            }
            else {
                UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Error" message:@"Already Verified!"delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil,nil];
                [alert show];
            }
        }];
    }


   }];
}

[SOLVED] If you just set again the user's email with the same email, Parse won't trigger the process which re-send the verification mail. [求助]如果您只是使用相同的电子邮件再次设置用户的电子邮件,Parse将不会触发重新发送验证邮件的过程。 You must first set a fake email --> save --> set the correct email --> save. 您必须先设置假电子邮件 - >保存 - >设置正确的电子邮件 - >保存。 Now Parse notices a actual change and do triggers the verification email process. 现在Parse注意到实际的更改,并触发验证电子邮件过程。

Change the capitalization of the email. 更改电子邮件的大小写。

BOOL upperCase = [[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:[currentUser.email characterAtIndex:0]];

if (upperCase) {
   [currentUser setEmail:[currentUser.email lowercaseString]];
}else {
   [currentUser setEmail:[currentUser.email capitalizedString]];
}
[currentUser saveEventually];

To access user information, you need to use the PFUser object defined in Parse . 要访问用户信息,您需要使用Parse定义的PFUser对象。

PFUser *user = [PFUser user];

PFUser has functions for getting the email address and for checking if the email has been verified. PFUser具有获取电子邮件地址和检查电子邮件是否已经过验证的功能。

What I want to know is how to resend the email verification? 我想知道的是如何重新发送电子邮件验证? This is not a procedure defined in the PFUser object. 这不是PFUser对象中定义的过程。

Purely as a test: to have Parse.com send a new verificiation email to a user: 纯粹作为测试:让Parse.com向用户发送新的验证电子邮件:

let email = PFUser.currentUser()?.email
PFUser.currentUser()?.email = "temp@temp.com"
PFUser.currentUser()?.saveInBackground()
PFUser.currentUser()?.email = email
PFUser.currentUser()?.saveInBackground()

This solution is brittle. 这种解决方案很脆弱。 In many ways. 很多方面。

  1. If Parse.com fails after setting the temporarory email address but before resetting it to the correct email address then the account will be lost to the user when they next try to login. 如果Parse.com在设置临时电子邮件地址后但在将其重置为正确的电子邮件地址之前失败,那么当用户下次尝试登录时,该帐户将丢失给用户。

  2. If #1 happens, then you (and your Customer Service) won't know what the correct email address either. 如果#1发生,那么您(以及您的客户服务)也不会知道正确的电子邮件地址。

  3. If #1 happens, what happens to other users using this function? 如果#1发生,使用此功能的其他用户会发生什么? Can their account email field be temporarily set to "temp@temp.com"? 他们的帐户电子邮件字段可以暂时设置为“temp@temp.com”吗? Answer: no it can't. 答:不,不能。 The saveInBackground() will fail and so no email change will happen and so no verification email will be sent. saveInBackground()将失败,因此不会发生电子邮件更改,因此不会发送任何验证电子邮件。

  4. If multiple users try to get a new verification email in the same time frame, what happens when a second account tries sets the email address field to "temp@temp.com" ? 如果多个用户尝试在同一时间段内收到新的验证电子邮件,那么当第二个帐户尝试将电子邮件地址字段设置为“temp@temp.com”时会发生什么? Based on #3 I would say #fail. 根据#3,我会说#fail。

  5. If Parse.com changes the implementation could the code generate two verification emails? 如果Parse.com更改了实现,代码可以生成两个验证电子邮件吗? One for each .saveInBackground(). 每个.saveInBackground()一个。 Actually, Parse does send out an email for each saveInBackground. 实际上,Parse会为每个saveInBackground发送一封电子邮件。

I can't code for all these points but here's some ideas: 我不能为所有这些点编码,但这里有一些想法:

  1. When saving "temp@temp.com" one could also save the user's entered email address in another field to be used by a recovery function. 保存“temp@temp.com”时,还可以将用户输入的电子邮件地址保存在另一个字段中以供恢复功能使用。 The recovery function could be manually started or run periodically to clean up after any "fails". 恢复功能可以手动启动或定期运行,以便在任何“失败”后进行清理。

  2. Rather than "temp@temp.com" use a randomly generated email address to mitigate clashers between users. 而不是“temp@temp.com”使用随机生成的电子邮件地址来减轻用户之间的冲突。

Notes 笔记

  1. Sending a new verification email voids the earlier email (ie the 'verify' hyperlink in the earlier email, when clicked, will tell the user that verification has failed). 发送新的验证电子邮件会使早期的电子邮件无效(即早期电子邮件中的“验证”超链接,点击后会告诉用户验证失败)。

  2. If you skip the two lines that set and save the user's email to a temporary value then no verification email is sent by Parse.com. 如果您跳过设置并将用户电子邮件保存为临时值的两行,则Parse.com不会发送任何验证电子邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM