2017-07-13 32 views
0

我已成功實施Cognito for iOS。我已決定在3個階段來分割認證過程:Cognito用戶確認有未確認的狀態

  • 的註冊
  • 確認與代碼
  • 登入

對於代碼確認我有這一段代碼:

func sendCode() { 
    self.pool = AWSCognitoIdentityUserPool(forKey: AWSCognitoUserPoolsSignInProviderKey) 
    let userForCode = self.pool?.getUser(self.emailTextField.text!) 

    // Bizarre ce test ne passe pas pourtant le client est confirmé dans Cognito... 
    if (userForCode?.confirmedStatus != AWSCognitoIdentityUserStatus.confirmed) { 
     userForCode?.confirmSignUp(confirmCodeTextField.text!, forceAliasCreation: true).continueWith { [weak self] (task) -> Any? in 
      DispatchQueue.main.async { 
       if let error = task.error as? NSError { 
        print("erreurCode : \(error.userInfo["message"])") 
       } else if let result = task.result { 
        print("client créé confirmé") 
       } 
      } 
      return nil 
     } 
    } 
} 

我從userPool得到一個用戶,我想詢問用戶是否是確認代碼,如果他的acco unt尚未確認,因此對userCode.confirmedStatus進行了測試。不幸的是,即使用戶在Cognito AWS控制檯中具有確認狀態,測試也總是如此。

回答

0

我已經做了確認代碼在我的應用程序,我把它用verifyAttribute發送電子郵件給用戶之後所做的:

self.user?.verifyAttribute("email", code: code).continueWith { (task) in 
     DispatchQueue.main.async(execute: { 
      if let error = task.error as NSError? { 
       // handle error (display message perhaps) 
      } else { 
       // the verification code is correct, continue with your application 
      } 
     }) 
     return nil 
    } 

變量code從用戶在其中輸入驗證他的文本框取碼。