예제 #1
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
                    var aclUser    = AclUserContext.GetDetail(dataContext, User.Identity.Name);
                    if (aclUser == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }

                    if (ModelState.IsValid)
                    {
                        var isSuccess = AclUserContext.ChangePassword(dataContext, aclUser, model, false);
                        if (isSuccess)
                        {
                            FormsAuthentication.SetAuthCookie(aclUser.Email, false);
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, AccountRes.SUCCESS_PASSWORD_CHANGED);
                            return(RedirectToAction("Manage", "Account"));
                        }
                    }
                    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"));
            }
        }
예제 #2
0
        public ActionResult ForgottenPasswordConfirm(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 (aclUser.AccountTypeEx == AccountTypeEnum.Admin)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, AccountRes.ERROR_FORGOTTEN_PASSWORD_ADMIN);
                        return(RedirectToAction("Index", "Home"));
                    }
                    if (ModelState.IsValid)
                    {
                        var isSuccess = AclUserContext.ChangePassword(dataContext, aclUser, model, false);
                        if (isSuccess)
                        {
                            FormsAuthentication.SetAuthCookie(aclUser.Email, false);
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, AccountRes.SUCCESS_PASSWORD_CHANGED);
                            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"));
            }
        }