Пример #1
0
        public async Task <ActionResult> OnPutPassword([FromBody] PasswordInputModel model)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            if (user != null)
            {
                IdentityResult changePasswordResult;
                if (await _userManager.HasPasswordAsync(user))
                {
                    changePasswordResult = await _userManager.ChangePasswordAsync(user, model.Current, model.Password);
                }
                else
                {
                    changePasswordResult = await _userManager.AddPasswordAsync(user, model.Password);
                }
                if (changePasswordResult.Succeeded)
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest("Password was not set."));
                }
            }
            else
            {
                return(NotFound("User not recognized"));
            }
        }
Пример #2
0
        public LogOnModel()
        {
            Title = "log_on_title";

            EmailInput    = new EmailInputModel("Email", "email", true);
            PasswordInput = new PasswordInputModel("Password", "password", true);
        }
Пример #3
0
 public string ValidatePasswordInputModel(PasswordInputModel passwordModel)
 {
     if (!Regex.IsMatch(passwordModel.Password, passwordPattern))
     {
         return("Password have to be between 8 and 20 characters long and contain lowercase, uppercase and number, possible characters: @#$%^&+=*.-_");
     }
     return("");
 }
Пример #4
0
        public ResetPasswordModel()
        {
            Title = Localizer.Localize("reset_password_title");

            TokenInput           = new HiddenInputModel("Token");
            EmailInput           = new HiddenInputModel("Email");
            PasswordInput        = new PasswordInputModel("Password", "password", true);
            ReEnterPasswordInput = new PasswordInputModel("ReEnterNewPassword", "re_enter_password", true);
        }
Пример #5
0
        public void PasswordInputModel(string name, string labelKey, bool isRequired, string value)
        {
            var model = new PasswordInputModel(name, labelKey, isRequired, value);

            Assert.AreEqual(name, model.Name);
            Assert.AreEqual(labelKey, model.LabelKey);
            Assert.AreEqual(isRequired, model.IsRequired);
            Assert.AreEqual(value, model.Value);
        }
Пример #6
0
        public ChangePasswordModel()
        {
            Title = "user_change_password_title";

            UserUidInput = new HiddenInputModel("UserUid");

            OldPasswordInput        = new PasswordInputModel("OldPassword", "old_password", true);
            NewPasswordInput        = new PasswordInputModel("NewPassword", "password", true);
            ReEnterNewPasswordInput = new PasswordInputModel("ReEnterNewPassword", "re_enter_new_password", true);
        }
Пример #7
0
        public string UpdatePasswordRW(PasswordInputModel passwordModel)
        {
            string validationResult = _validator.ValidatePasswordInputModel(passwordModel);

            if (!string.IsNullOrWhiteSpace(validationResult))
            {
                return(validationResult);
            }
            return("");
        }
Пример #8
0
        public SignUpModel()
        {
            Title = "sign_up_title";

            EmailInput            = new EmailInputModel("Email", "email", true);
            FirstNameInput        = new InputModel("FirstName", "first_name", true);
            LastNameInput         = new InputModel("LastName", "last_name", true);
            OrganizationNameInput = new LongInputModel("OrganizationName", "organization_name", true);
            PasswordInput         = new PasswordInputModel("Password", "password", true);
            IsTermsAcceptedInput  = new CheckboxInputModel("IsTermsAccepted", "accept_terms", true);
        }
Пример #9
0
        public UserSettingsViewModel(User user)
        {
            User = user;

            NewUserInfo        = new UserInfo();
            PasswordInputModel = new PasswordInputModel();

            UserInfoTypes = Enum.GetValues(typeof(UserInfoType))
                            .Cast <UserInfoType>()
                            .ToSelectList(x => x.GetDescription(), x => ((int)x).ToString());
        }
Пример #10
0
        public InviteAcceptModel()
        {
            Title = "accept_invite_title";

            TokenInput = new HiddenInputModel("Token");
            EmailInput = new HiddenInputModel("Email");

            FirstNameInput       = new InputModel("FirstName", "first_name", true);
            LastNameInput        = new InputModel("LastName", "last_name", true);
            PasswordInput        = new PasswordInputModel("Password", "password", true);
            ReEnterPasswordInput = new PasswordInputModel("ReEnterPassword", "re_enter_password", true);
        }
Пример #11
0
        public MvcHtmlString Password <TProperty>(Expression <Func <TModel, TProperty> > expression, string placeholder = null,
                                                  string label = null)
        {
            ModelMetadata      modelMetadata      = ModelMetadata.FromLambdaExpression(expression, Helper.ViewData);
            PasswordInputModel passwordInputModel = new PasswordInputModel(Helper,
                                                                           modelMetadata,
                                                                           ExpressionHelper.GetExpressionText(expression),
                                                                           label,
                                                                           placeholder);

            return(Helper.Partial("EditorTemplates/Forms/Input", passwordInputModel));
        }
Пример #12
0
        public AdminAcceptInviteModel()
        {
            Title = "admin_accept_title";

            OrganizationUidInput = new HiddenInputModel("OrganizationUid");
            TokenInput           = new HiddenInputModel("Token");
            EmailInput           = new HiddenInputModel("Email");

            FirstNameInput       = new InputModel("FirstName", "first_name", true);
            LastNameInput        = new InputModel("LastName", "last_name", true);
            PasswordInput        = new PasswordInputModel("Password", "password", true);
            ReEnterPasswordInput = new PasswordInputModel("ReEnterPassword", "re_enter_password", true);
        }
Пример #13
0
        public ActionResult UpdatePassword(PasswordInputModel passwordModel)
        {
            var message = _wrapper.UpdatePasswordRW(passwordModel);

            if (string.IsNullOrWhiteSpace(message))
            {
                passwordModel.Password = new PasswordEncryptor().EncryptPassword(passwordModel.Password);
                _repo.UpdatePassword(_mapper.Map <PasswordDto>(passwordModel));
                _logger.Info($"Update password for lead with Id: {passwordModel.Id}");
                return(Ok("Successfully updated"));
            }
            else
            {
                return(BadRequest(message));
            }
        }
Пример #14
0
        public ActionResult ChangePassword(int id, PasswordInputModel passwordInputModel)
        {
            if (passwordInputModel.Password != passwordInputModel.PasswordRepeat)
            {
                ModelState.AddModelError("passwordInputModel.PasswordRepeat", "Det repiterade lösenordet skiljer sig!");
            }

            if (!ModelState.IsValid)
            {
                return(Settings(id));
            }

            var user = _userService.Get(id);

            user.Password = Encrypter.Encrypt(passwordInputModel.Password);

            FlashSuccess("Lösenordet har uppdaterats!");
            return(RedirectToAction("Settings", new { id }));
        }
Пример #15
0
        public async Task <IActionResult> ChangePassword([FromBody] PasswordInputModel model, [FromServices] IUserRepository userRepository)
        {
            //データの存在チェック
            var user = await userRepository.GetByIdAsync(CurrentUserInfo.Id);

            if (user == null)
            {
                return(JsonNotFound($"User ID {CurrentUserInfo.Id} is not found."));
            }
            //パスワード変更を許可するのは、ローカルアカウントのユーザのみ
            if (user.ServiceType != AuthServiceType.Local)
            {
                return(JsonBadRequest($"Only local account user can change the password. Your account service type is {user.ServiceType} not Local."));
            }
            string oldHash = Infrastructure.Util.GenerateHash(model.CurrentPassword, user.Name);

            if (oldHash != user.Password)
            {
                return(JsonBadRequest($"Password mismatch. Please input the current correct password."));
            }

            if (string.IsNullOrWhiteSpace(model.NewPassword))
            {
                //新しいパスワードに空文字は許可しない
                return(JsonBadRequest($"New password is NOT allowed to set empty string."));
            }

            //パスワードをハッシュ化
            string hash = Infrastructure.Util.GenerateHash(model.NewPassword, user.Name);

            //もしパスワードが同じであれば、エラーにする
            if (oldHash == hash)
            {
                return(JsonBadRequest($"Current password and new password are same."));
            }

            user.Password = hash;

            unitOfWork.Commit();

            return(JsonNoContent());
        }
Пример #16
0
        public async Task <IActionResult> ChangePassword(PasswordInputModel inputModel)
        {
            if (ModelState.IsValid)
            {
                User user = await _userManager.GetUserAsync(User);

                var changePasswordResult = await _userManager.ChangePasswordAsync(user, inputModel.OldPassword, inputModel.Password);

                if (changePasswordResult.Succeeded)
                {
                    await _signInManager.RefreshSignInAsync(user);

                    ViewData["Message"] = "Успешно сменихте паролата си!";
                }
                else
                {
                    ViewData["ЕrrorMessage"] = "Невалидни данни!";
                }
            }
            return(this.View("ChangePassword"));
        }
Пример #17
0
        public ActionResult ChangePassword(PasswordInputModel passwordInputModel)
        {
            if (passwordInputModel.Password != passwordInputModel.PasswordRepeat)
            {
                ModelState.AddModelError("passwordInputModel.PasswordRepeat", "Det repiterade lösenordet skiljer sig!");
            }

            if (!ModelState.IsValid)
            {
                return(Settings());
            }

            var existingUser = _userService.Get(User.Id);

            existingUser.Password = Encrypter.Encrypt(passwordInputModel.Password);

            _storage.Store(SessionKeys.User, existingUser);

            FlashSuccess("Lösenordet har uppdaterats!");
            return(RedirectToAction("Settings"));
        }
Пример #18
0
        public SettingsViewModel(User user)
        {
            User = user;

            PasswordInputModel = new PasswordInputModel();
        }