Exemplo n.º 1
0
 protected bool ValidateModel(ChangePwdModel model)
 {
     if(!string.IsNullOrEmpty(model.NewPassword))
     {
         bool containDigit = false;
         bool containLetter = false;
         string password = model.NewPassword;
         foreach (char c in password)
         {
             if (Char.IsDigit(c))
                 containDigit = true;
             else if (Char.IsLetter(c))
                 containLetter = true;
         }
         if(!containDigit || !containLetter)
             ModelState.AddModelError("NewPassword", "Поле 'Новый пароль' должен содержать буквы и цифры");
     }
     return ModelState.IsValid;
 }
Exemplo n.º 2
0
 public ActionResult ChangePwd()
 {
     ChangePwdModel model = new ChangePwdModel();
     return View(model);
 }
Exemplo n.º 3
0
 public ActionResult ChangePwd(ChangePwdModel model)
 {
     if (!ValidateModel(model))
         return View(model);
     LoginBl.OnChangePwd(model);
     if (!string.IsNullOrEmpty(model.Error))
         ModelState.AddModelError("", model.Error);
     else
         model.Success = "Пароль успешно изменен.";
     return View(model);
 }
Exemplo n.º 4
0
 public void OnChangePwd(ChangePwdModel model)
 {
     try
     {
         User user = UserDao.Load(CurrentUser.Id);
         user.Password = model.NewPassword;
         UserDao.MergeAndFlush(user);
     }
     catch (Exception ex)
     {
         Log.Error("Exception:", ex);
         model.Error = "Исключение:" + ex.GetBaseException().Message;
     }
 }