コード例 #1
0
        public ActionResult ResetEmail(string token)
        {
            ResetEmailNewViewModel model = new ResetEmailNewViewModel {
                Token = token
            };

            ViewBag.PageName = AccountResetEmail.PageName;
            return(View(model));
        }
コード例 #2
0
        public async Task <ActionResult> ResetEmail(ResetEmailNewViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var account = await new AccountComponent().GetAccountByIdAsync(AccountInfo.Id);

            if (model.Email.Equals(account.Email, StringComparison.CurrentCultureIgnoreCase))
            {
                ModelState.AddModelError("", AccountResetEmail.EmailSameAsOriginal);
            }
            try
            {
                var token = HttpUtility.UrlDecode(model.Token);
                SecurityVerify.Verify <ResetEmailOldTokenVerification>(account.Email.Replace("@", "_"), null, token, false);
            }
            catch (ApplicationException ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(model));
            }
            catch (Exception)
            {
                ModelState.AddModelError("", GeneralResource.SaveFailed);
                return(View(model));
            }
            try
            {
                SecurityVerify.Verify <ResetEmailNewVerification>(model.Email.Replace("@", "_"), null, model.Code);
            }
            catch (ApplicationException ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(model));
            }
            catch (Exception)
            {
                ModelState.AddModelError("", GeneralResource.SaveFailed);
                return(View(model));
            }

            var emailExist = await new AccountComponent().CheckEmailBind(AccountInfo.Id, model.Email);

            if (emailExist)
            {
                ModelState.AddModelError("", AccountFirstSetting.EmailBindByOtherAccount);
                return(View(model));
            }

            SecurityVerify.DeleteCodeKey <ResetEmailOldTokenVerification>(account.Email.Replace("@", "_"));

            await new AccountComponent().ResetEmailAsync(account.Id, model.Email);

            return(RedirectToAction("Index", "Merchant", new { lang = CurrentLanguage }));
        }