/// <summary>
        /// Checks confirm token is not expired and identifies a user who can be confirmed.
        /// </summary>
        /// <param name="model">Contains confirmation token details.</param>
        /// <param name="keyPrefix">Validation key prefix.</param>
        public void ValidateConfirmUserStatus(ConfirmUserStatusModel model, string keyPrefix = null)
        {
            Token token = ValidateConfirmUserToken(model.ConfirmKey, keyPrefix);

            ValidateConfirmUserTokenExpiry(token, keyPrefix);
            ValidateConfirmUserUser(model.TenantId, token, model.SetPassword, keyPrefix);
        }
        /// <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);
        }
示例#3
0
 public void CheckConfirmUserStatus(ConfirmUserStatusModel model)
 {
     _authenticationValidator.ValidateConfirmUserStatus(model);
 }