Exemplo n.º 1
0
 public ActionResult ForgottenPasswordConfirm(string code)
 {
     try
     {
         using (var dataContext = new HuntingEntities())
         {
             int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
             if (string.IsNullOrWhiteSpace(User.Identity.Name) == false)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                 return(RedirectToAction("Index", "Home"));
             }
             var aclUser = AclUserContext.GetDetailByEmailCode(dataContext, code);
             if (aclUser == null)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, AccountRes.ERROR_CODE_INVALID);
                 return(RedirectToAction("Index", "Home"));
             }
             if (aclUser.AccountTypeEx == AccountTypeEnum.Admin)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, AccountRes.ERROR_FORGOTTEN_PASSWORD_ADMIN);
                 return(RedirectToAction("Index", "Home"));
             }
             var model = new ChangePasswordModel(aclUser);
             return(View(model));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "AccountController");
         ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
         return(RedirectToAction("Index", "Home"));
     }
 }
Exemplo n.º 2
0
        public ActionResult Confirm(ChangePasswordModel model)
        {
            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
                    if (string.IsNullOrWhiteSpace(User.Identity.Name) == false)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }

                    var aclUser = AclUserContext.GetDetailByEmailCode(dataContext, model.Code);
                    if (aclUser == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, AccountRes.ERROR_CODE_INVALID);
                        return(RedirectToAction("Index", "Home"));
                    }
                    if (ModelState.IsValid)
                    {
                        var isSuccess = AclUserContext.ChangePassword(dataContext, aclUser, model, true);
                        if (isSuccess)
                        {
                            FormsAuthentication.SetAuthCookie(aclUser.Email, false);
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, AccountRes.SUCCESS_CONFIRM);
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    model = new ChangePasswordModel(aclUser);
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "AccountController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }