/// <summary>
        /// Retrieves form.
        /// </summary>
        /// <param name="context">Form context.</param>
        /// <returns>View model used to render form.</returns>
        public Form GetForm(string context)
        {
            // Construct form
            Form form = new Form
            {
                Fields = new Dictionary <string, IFormField>(),
                CustomErrorMessages = new List <string>(),
                SubmitLabel         = AuthenticationResource.ConfirmUserSetPasswordButtonLabel,
                Id      = FormId.ToString(),
                Context = context
            };

            try
            {
                // Get website identifier
                long tenantId = _authenticationService.TenantId;

                // Get confirm user details
                ConfirmUserStatusModel model = new ConfirmUserStatusModel
                {
                    ConfirmKey  = context,
                    SetPassword = true,
                    TenantId    = tenantId
                };

                // Validate supplied details
                _authenticationValidator.ValidateConfirmUserStatus(model);

                // Add form fields
                form.Fields.Add("password", new PasswordTextField
                {
                    Name                  = "password",
                    Label                 = AuthenticationResource.ConfirmUserPasswordLabel,
                    Required              = true,
                    RequiredErrorMessage  = AuthenticationResource.ConfirmUserPasswordRequiredMessage,
                    MaxLength             = AuthenticationLengths.PasswordMaxLength,
                    MaxLengthErrorMessage = string.Format(AuthenticationResource.ConfirmUserPasswordLengthMessage, "password", AuthenticationLengths.PasswordMaxLength, AuthenticationLengths.PasswordMinLength),
                    MinLength             = AuthenticationLengths.PasswordMinLength,
                    MinLengthErrorMessage = string.Format(AuthenticationResource.ConfirmUserPasswordLengthMessage, "password", AuthenticationLengths.PasswordMaxLength, AuthenticationLengths.PasswordMinLength)
                });
                form.Fields.Add("confirmPassword", new PasswordTextField
                {
                    Name                 = "confirmPassword",
                    Label                = AuthenticationResource.ConfirmUserConfirmPasswordLabel,
                    Required             = true,
                    RequiredErrorMessage = AuthenticationResource.ConfirmUserConfirmPasswordRequiredMessage
                });
            }
            catch (ValidationErrorException ex)
            {
                foreach (ValidationError error in ex.Errors)
                {
                    form.CustomErrorMessages.Add(error.Message);
                }
            }

            // Return result
            return(form);
        }
Exemplo n.º 2
0
 public void CheckConfirmUserStatus(ConfirmUserStatusModel model)
 {
     _authenticationValidator.ValidateConfirmUserStatus(model);
 }