Skip to content

Dynamic Authentication

FUIDynamicAuthenticationScreen

open class FUIDynamicAuthenticationScreen: FUIWelcomeController, FUIBlurNavigationBarViewController

The FUIDynamicAuthenticationScreen is an UIViewController to display the screen to prompt user to enter information needed for authentication.

It has a message label and a number of the input fields for user to enter information needed. The input fields are configured using the informationFields property.

There is a 'Cancel' button on the navigation bar for user to cancel the authentication process. There is also a 'Done' button on the navigation bar for user to submit the information. The Done button is disabled until all the input fields are not empty.

Developer should implement FUIDynamicAuthenticationDelegate and set it to the delegate property to handle user responses.

var dynamicAuthenticationScreen: FUIDynamicAuthenticationScreen?
var completionBlock: ((_ errorMessage: String?) -> Void)?

func presentDynamicAuthenticationScreen() {
    let controllers = FUIDynamicAuthenticationScreen.createInstanceFromStoryboard()
    let dynamicAuthController = controllers.dynamicAuthenticationScreen

    dynamicAuthController.informationFields = [
        FUIAuthenticationInformationField(placeholder: "username", isSecureText: false, informationString: "Admin"),
        FUIAuthenticationInformationField(placeholder: "password", isSecureText: true, informationString: nil),
        FUIAuthenticationInformationField(placeholder: "url", isSecureText: false, informationString: nil),
        FUIAuthenticationInformationField(placeholder: "test field", isSecureText: false, informationString: nil)
    ]
    dynamicAuthController.delegate = self

    self.navigationController?.present(controllers.navigationController, animated: true, completion: nil)
}

func verify(_ controller: FUIDynamicAuthenticationScreen, informationStrings: [String], completion: @escaping ((_ errorMessage: String?) -> Void)) {
    dynamicAuthenticationScreen = controller
    completionBlock = completion

    // Send information to server for verification here

    // Simulate callback from verification process
    DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
        self.verificationDone()
    }
}

func verificationDone() {
    completionBlock?(verificationErrorMessage)
    if verificationErrorMessage == nil {
        dynamicAuthenticationScreen?.dismiss(animated: true, completion: nil)
    }
}

func didCancel(_ controller: FUIBasicAuthenticationScreen) {
   print("User Cancelled Basic Authentication")
   controller.dismiss(animated: true, completion: nil)
}

Theming

fdlFUIDynamicAuthenticationScreen_detailLabel {
   font-color: @primary1;
}

fdlFUIDynamicAuthenticationScreen_cancelButton {
   background-tint-color: @tintColorDark;
}

fdlFUIDynamicAuthenticationScreen_doneButton {
   background-tint-color: @tintColorDark;
}

fdlFUIDynamicAuthenticationScreen_messageBannerTitleLabel {
   font-color: @primary7;
}

fdlFUIDynamicAuthenticationScreen_messageBannerDividerTop {
   background-color: @line;
}

fdlFUIDynamicAuthenticationScreen_errorMessageBannerTitleLabel {
   font-color: @negative;
}

fdlFUIDynamicAuthenticationScreen_errorMessageBannerDividerTop {
   background-color: @negative;
}

fdlFUIDynamicAuthenticationScreen_navigationBar {
   background-color: clear;
   background-tint-color: @tintColor;
   bar-style: default;
}

Attention

The delegate object with type FUIDynamicAuthenticationDelegate is declared as a weak reference. On deallocation it will be automatically set to nil. To keep it alive as expected, developer should retain the delegate object during its whole execution scope.


Last update: December 8, 2020