コード例 #1
0
        public ActionResult ForgottenPassword(ForgotPasswordModel 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"));
                    }

                    if (ModelState.IsValid)
                    {
                        var aclUser = AclUserContext.GetDetail(dataContext, model.Email);
                        if (aclUser != null)
                        {
                            if (aclUser.AccountTypeEx == AccountTypeEnum.Admin)
                            {
                                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, AccountRes.ERROR_FORGOTTEN_PASSWORD_ADMIN);
                                return(RedirectToAction("Index", "Home"));
                            }
                            var isSuccess = AclUserContext.ForgotPassword(dataContext, aclUser);
                            if (isSuccess)
                            {
                                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, AccountRes.SUCCESS_FORGOTTEN_PASSWORD);
                                return(RedirectToAction("Index", "Home"));
                            }
                        }
                        else
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, AccountRes.SUCCESS_FORGOTTEN_PASSWORD);
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "AccountController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }