2017-10-20 195 views
0

我在AWS:如果你創建一個用戶帳戶,離開應用程序,並在回去使用發送代碼到電子郵件以確認一個可怕的問題/ SMS,那麼它會說你輸入的用戶名必須大於1個字符,並且必須遵循某種模式。這是amazon發佈的示例代碼中的一個錯誤。我在這裏發帖,因爲有人的話題沒有文獻,我想我的發佈解決方案,工作,因爲這是一個非常令人沮喪的問題。確認用Amazon Web Services帳戶創建後一個未經證實的用戶(在應用程序)

這裏的錯誤:在「用戶名」

值不能滿足約束:成員的長度必須大於或等於1;在 '用戶名' 值不能滿足約束:成員必須滿足正則表達式模式:[\ p {L} \ p {M} \ p {S} \ p {N} \ p {P}] +「;

回答

0

值在「用戶名」不能滿足約束:成員的長度必須大於或等於1;在「用戶名」值不能滿足約束:成員必須滿足正則表達式模式:[\ p {L} \ p {M} \ p {S} \ p {N} \ p {p}] +「;

當您最初創建一個帳戶,你會被帶到哪裏,你必須輸入用戶名和密碼的確認用戶故事板。但是用戶名已經輸入,因爲您在技術上使用未經確認的帳戶登錄。然而這是唯一一次,您將能夠登錄在未確認的帳戶(除非你發現周圍的一些其他工作)。因此,如果要繼續回到確認用戶控制器,他們不能簡單地輸入用戶名,因爲代碼使用登錄用戶的用戶名,而不是輸入的用戶名。以下是如何解決該問題,以便您可以簡單地輸入用戶名和代碼,然後確認帳戶。

這是我在堆棧的第一篇文章所以這裏是我最好的答案:

的方法

...

override func viewDidLoad() { 

變化......

self.username.text = self.user!.username 

到....

if self.user?.username == "" || self.user == nil { 
    print("user is nil") 
} else { 
    self.username.text = self.user!.username 
} 

....並插入以下內容與您的poolID和@IBAction中的「確認」方法和您自己的SEGUE;插入後,您檢查,看看是否碼值是空的,之前「self.user?.confirmSignUp」的方法...

if self.user?.username == "" || self.user == nil { 
// change the poolid to yours 
    let pool = AWSCognitoIdentityUserPool(fenter code hereorKey: userPoolID) 
// change the "username" title to whatever corresponds to the text field identifier you are using 
    let user = pool.getUser((self.username?.text)!) 

    user.confirmSignUp(self.code.text!, forceAliasCreation: true).continueWith {[weak self] (task: AWSTask) -> AnyObject? in 
    guard let strongSelf = self else { return nil } 
    DispatchQueue.main.async(execute: { 
     if let error = task.error as? NSError { 
      let alertController = UIAlertController(title: error.userInfo["__type"] as? String, message: error.userInfo["message"] as? String, preferredStyle: .alert) 
      let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil) 
      alertController.addAction(okAction) 
      strongSelf.present(alertController, animated: true, completion: nil) 
     } else { 
      // Change the segue identifier to yours 
      strongSelf.performSegue(withIdentifier: "confirmedUserSegue", sender:sender) 
     } 
    }) 
return nil 
} 
} 

希望這有助於!

要解決重新發送代碼,做同樣的事情:

if self.user?.username == "" || self.user == nil { 
      let pool = AWSCognitoIdentityUserPool(forKey: userPoolID) 
      let user = pool.getUser((self.username?.text)!) 

      user.resendConfirmationCode().continueWith {[weak self] (task: AWSTask) -> AnyObject? in 
       guard let _ = self else { return nil } 
       DispatchQueue.main.async(execute: { 
        if let error = task.error as? NSError { 
         let alertController = UIAlertController(title: error.userInfo["__type"] as? String, 
                   message: error.userInfo["message"] as? String, 
                   preferredStyle: .alert) 
         let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil) 
         alertController.addAction(okAction) 

         self?.present(alertController, animated: true, completion: nil) 
        } else if let result = task.result { 
         let alertController = UIAlertController(title: "Code Resent", 
                   message: "Code resent to \(result.codeDeliveryDetails?.destination!)", 
          preferredStyle: .alert) 
         let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil) 
         alertController.addAction(okAction) 
         self?.present(alertController, animated: true, completion: nil) 
        } 
       }) 
       return nil 
      } 

     } else 

...其餘的代碼從亞馬遜例如else語句...

相關問題