コード例 #1
0
        public ActionResult RecoverPasswordFinish(RecoverPasswordFinishModel model)
        {
            if (ModelState.IsValid)
            {
                var response = this.VerifyRecaptcha();
                if (!response)
                {
                    return(View(model));
                }

                var accountService = IoCConfig.Service <IAccountService>();
                var acc            = accountService.GetAccountByIdentity(model.Username);

                if (!CheckAccount(acc))
                {
                    return(View(model));
                }

                //Chưa tồn tại key hoặc key hết hiệu lực
                if (!acc.Account_RecoverPasswordExpired.HasValue ||
                    acc.Account_RecoverPasswordExpired.Value < DateTime.Now)
                {
                    //reset recover password key
                    acc.Account_RecoverPasswordKey     = null;
                    acc.Account_RecoverPasswordExpired = null;
                    accountService.Update(acc);

                    SetCustomError("Mã khôi phục đã hết hiệu lực. Vui lòng thực hiện lại việc khôi phục mật khẩu ở form đăng nhập.");
                }
                else if (acc.Account_RecoverPasswordKey != model.RecoverKey)
                {
                    SetCustomError("Mã khôi phục không đúng. Vui lòng liên hệ lại với ban quản trị.");
                }
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                acc.Account_Password = PasswordEncryptManager.EncryptPassword(model.NewPassword);
                //reset recover password key
                acc.Account_RecoverPasswordKey     = null;
                acc.Account_RecoverPasswordExpired = null;
                acc = accountService.Update(acc);

                if (acc != null)
                {
                    ViewBag.CurrentStep = 2;
                    SetSuccess("Khôi phục mật khẩu thành công. Hãy click vào Đăng nhập để bắt đầu sử dụng :)");
                }
                else
                {
                    SetCustomError("Có lỗi xảy ra. Vui lòng thực hiện lại");
                }
            }

            return(View(model));
        }
コード例 #2
0
        public ActionResult RecoverPasswordFinish(string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                SetCustomError("Vui lòng nhập mã khôi phục đã được gửi đến email của bạn");
                return(View());
            }
            var model = new RecoverPasswordFinishModel();

            model.RecoverKey = key;
            return(View(model));
        }