eliu2016 / Swap

Repository for iOS Application - Swap
2 stars 1 forks source link

Add Forgot Password #64

Closed MichealSBingham closed 7 years ago

MichealSBingham commented 7 years ago
  /// Sends a verification code in order to reset the password of the user to 'destination' in completion block (String). The booleans test shows if it succeeded in sending a verificaiton, if it's false, the user could not be found. The SwapUser object should contain the username, email address, or phone number as the 'username' attribute.
func forgotPassword(completion: @escaping (_ didSendCode: Bool, _ destination: String?) -> Void)  {

    pool.getUser(self.username).forgotPassword().continue({ (task)  in

        if let response = task.result?.codeDeliveryDetails{

            let destination = response.destination!

            completion(true, destination)

        } else{

            // User Not Found
            completion(false, nil)
        }

        return nil
    })
}
MichealSBingham commented 7 years ago
   /// Sends a verification code in order to reset the password of the user to 'destination' in completion block (String). The booleans test shows if it succeeded in sending a verificaiton, if it's false, the user could not be found. The SwapUser object should contain the username, email address, or phone number as the 'username' attribute.
func forgotPassword(completion: @escaping (_ didSendCode: Bool, _ destination: String?) -> Void)  {

    pool.getUser(self.username).forgotPassword().continue({ (task)  in

        DispatchQueue.main.async {

            if let response = task.result?.codeDeliveryDetails{

                let destination = response.destination!

                completion(true, destination)

            } else{

                // User Not Found
                completion(false, nil)
            }

        }

        })

}
MichealSBingham commented 7 years ago
      /// Sends a verification code in order to reset the password of the user to 'destination' in completion block (String). The booleans test shows if it succeeded in sending a verificaiton, if it's false, the user could not be found. The SwapUser object should contain the username, email address, or phone number as the 'username' attribute.
func forgotPassword(completion: @escaping (_ didSendCode: Bool, _ destination: String?) -> Void)  {

    pool.getUser(self.username).forgotPassword().continue({ (task)  in

        DispatchQueue.main.async {

            if let response = task.result?.codeDeliveryDetails{

                let destination = response.destination!

                completion(true, destination)

            } else{

                // User Not Found
                completion(false, nil)
            }

        }

        })

}

func confirmForgotPassword(confirmation code: String, new password: String, completion: @escaping (_: Bool) -> Void)  {

    pool.getUser(self.username).confirmForgotPassword(code, password: password).continue({ (task) in

        DispatchQueue.main.async {

            guard task.error == nil  else {

                completion(false)

                return 
            }

            completion(true)
        }

    })
}

/// Change password of a signed in user
func change(oldPassword old: String, newPassword new: String, completion: @escaping (_ success: Bool) -> Void)  {

    pool.getUser(self.username).changePassword(old, proposedPassword: new).continue({ (task) in

        DispatchQueue.main.async {

            guard task.error == nil  else {

                completion(false)

                return
            }

            completion(true)
        }

    })

}