Skip to content

Instantly share code, notes, and snippets.

@morteza2128
Last active December 27, 2017 12:02
Show Gist options
  • Save morteza2128/9e3d8eb1b36052ebb1cf443d55c1b347 to your computer and use it in GitHub Desktop.
Save morteza2128/9e3d8eb1b36052ebb1cf443d55c1b347 to your computer and use it in GitHub Desktop.
@IBAction func signupButtonClicked(_ sender: UIButton) {
do {
try decideToSendSignupData()
SVProgressHUD.setDefaultMaskType(.gradient)
SVProgressHUD.show(withStatus: LoadingMessages.simple.localized )
self.serviceCore.sendSignUpRequet(email: self.emailTextField.text!, password: self.passTextField.text!)
}
catch RegisterError.incorrectEmail {
self.showMessageView(message: RegisterError.incorrectEmail.localized, style: .error)
}
catch RegisterError.incorrectPass {
self.showMessageView(message: RegisterError.incorrectPass.localized, style: .error)
}
catch RegisterError.unequalPassword {
self.showMessageView(message: RegisterError.unequalPassword.localized, style: .error)
}
catch{}
}
func decideToSendSignupData() throws {
guard emailTextField.text!.isValidEmail() else {
throw RegisterError.incorrectEmail
}
guard passTextField.text!.isValidPassword() else {
throw RegisterError.incorrectPass
}
guard repeatPassTextField.text?.characters.count == passTextField.text?.characters.count else {
throw RegisterError.unequalPassword
}
}
enum RegisterError : String, Error {
case incorrectEmail = "incorrectEmail"
case incorrectPass = "incorrectPassword"
case incorrectUsernameOrPass = "incorrectUsernameOrPass"
case incompatibilityPasswords = "incompatibilityPasswords"
case exceededLoginRequest = "ExceededLoginRequest"
case inactiveUser = "InactiveUser"
case duplicateEmail = "DuplicateEmail"
case unequalPassword = "UnequalPassword"
var localized: String {
return self.rawValue.localized
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment