FMPUser

Description

The FMPUser class is used to describe a user.

class FMPUser

Properties

Property Description

login

User login.
var login: String { get }

password

User password.
var password: String { get }

isAuthenticated

User authentication on server. If the value is true, the user is authenticated on server. If the value is false, the user it not authenticated on server.
var isAuthenticated: Bool { get }

Methods

Method Description
auth(completion:) User authentication. After executing the method a user token is obtained. The token is used in each request to server.
func auth(completion: @escaping FMPRequestResponseHandler)

Parameters:

  • completion. Closing expression containing method execution result.

auth(withNewPassword:completion:) User authentication with password change. A new user token is obtained after executing the method. The token is used in each request to server.
func auth(withNewPassword newPassword: String, completion: @escaping FMPRequestResponseHandler)

Parameters:

  • newPassword. New user password

  • completion. Closing expression containing method execution result.

revoke() Cancel user authentication.
func revoke()
copy() Get instance of builder class for copying FMPUser. It returns the instance of the FMPUser.Builder builder class.
func copy() -> FMPUser.Builder

Examples

User authentication:

// Build an instance of the FMPUser class. For details see examples for FMPUser.Builder.
let user: FMPUser = fmp.user.build()
  
// Authenticate user on server
user.auth { (response) in
    if response.success {
        // Display server response
        print(response.result)
    } else {
        // Display error code and description
        print(response.error?.code, response.error?.description)
    }
}

Change user password:

// Build an instance of the FMPUser class. For details see examples for FMPUser.Builder.
let user: FMPUser = fmp.user.build()
  
// Change user password and authenticate user on server with new password
user.auth(withNewPassword: "newPassword") { (response) in
    if response.success {
        // Display server response
        print(response.result)
    } else {
        // Display error code and description
        print(response.error?.code, response.error?.description)
    }
}

Cancel user authentication:

// Build an instance of the FMPUser class. For details see examples for FMPUser.Builder.
let user: FMPUser = fmp.user.build()
  
// Cancel user authentication on server
user.revoke()

Copy FMPUser:

// Build an instance of the FMPUser class. For details see examples for FMPUser.Builder.
let user: FMPUser = fmp.user.build()
  
// Copy instance of the FMPUser class.
let userCopy: FMPUser = user.copy().build()

See also:

FMPWrapper Framework | Classes