SCUser


init()

SCUser initialization

Example

let appUser = SCUser()

.login(email, password, callback)

Method for application user authentication

Parameter Type Properties Description Value example
email String Mandatory User email "user@domain.zone"
password String Mandatory User password "CorrectHorseBatteryStaple"
callback (Bool, SCError?, [String: AnyObject]?) -> Void Callback for the request being executed.

Example

    @IBAction private func loginPressed() {

        guard let email = emailTextField.text where email != "",
            let password = passwordTextField.text where password != "" else {
                let alert = UIAlertController(title: "Вход невозможен", message: "Не указан email или пароль", preferredStyle: .Alert)
                let ok = UIAlertAction(title: "OK", style: .Default) {
                    action in
                    return
                }
                alert.addAction(ok)
                presentViewController(alert, animated: true, completion: nil)
                return
        }

        let user = SCUser()
        user.login(email, password: password) {
            success, error, result in
            if success {
                let alert = UIAlertController(title: "Вход выполнен", message: nil, preferredStyle: .Alert)
                let ok = UIAlertAction(title: "OK", style: .Default) {
                    action in
                    self.performSegueWithIdentifier("ToObjects", sender: nil)
                }
                alert.addAction(ok)
                self.presentViewController(alert, animated: true, completion: nil)
            }
        }

.logout(callback)

Method for application user deauthentication.

Parameter Type Properties Description Value example
callback (Bool, SCError?, [String: AnyObject]?) -> Void Callback for the request being executed.

Example

    @IBAction private func logoutPressed() {
        SCUser.logout() {
            success, error in
            if success {
                self.dismissViewControllerAnimated(true, completion: nil)
            }
        }
    }

.signup(username, email, password, callback)

Method for application user registration.

Parameter Type Properties Description Value example
username String Mandatory Имя пользователя "Jovan"
email String Mandatory Email пользователя "user@domain.zone"
password String Mandatory Пароль пользователя "CorrectHorseBatteryStaple"
callback (Bool, SCError?, [String: AnyObject]?) -> Void Callback for the request being executed.

Example

@IBAction private func signupPressed() {
    guard let email = emailTextField.text where email != "",
        let password = passwordTextField.text where password != "",
    let username = usernameTextField.text where username != "" else {
            let alert = UIAlertController(title: "Регистрация невозможна", message: "Не указан email, пароль или имя пользователя", preferredStyle: .Alert)
            let ok = UIAlertAction(title: "OK", style: .Default) {
                action in
                return
            }
            alert.addAction(ok)
            presentViewController(alert, animated: true, completion: nil)
            return
    }

    let user = SCUser()
    user.signup(username, email: email, password: password) {
        success, error, result in
        if success {
            let alert = UIAlertController(title: "Пользователь зарегистрирован", message: nil, preferredStyle: .Alert)
            let ok = UIAlertAction(title: "OK", style: .Default) {
                action in
                self.dismissViewControllerAnimated(true, completion: nil)
            }
            alert.addAction(ok)
            self.presentViewController(alert, animated: true, completion: nil)
        } else {
            var message = ""
            switch error! {
            case .API(_, let apiMessage):
                message = apiMessage
            default:
                break
            }
            let alert = UIAlertController(title: "Ошибка при регистрации", message: message, preferredStyle: .Alert)
            let ok = UIAlertAction(title: "OK", style: .Default) {
                action in
            }
            alert.addAction(ok)
            self.presentViewController(alert, animated: true, completion: nil)
        }
    }
}

.signup(callback)

Method for application user registration. Fields are defined using the Object parent class methods.

Parameter Type Properties Description Value example
callback (Bool, SCError?, [String: AnyObject]?) -> Void Callback for the request being executed.