示例#1
0
        public async Task UpdatePwdAsync(UpdatePwdViewModel model)
        {
            string userId = User.FindFirst(JwtClaimTypes.Subject)?.Value;

            if (String.IsNullOrWhiteSpace(userId))
            {
                throw new IamException(HttpStatusCode.BadRequest, "用户未登录");
            }

            if (await _userService.IsPwdValidAsync(userId, model.OldPwd))
            {
                await _userService.UpdatePwdAsync(userId, model.NewPwd);

                return;
            }

            throw new IamException(HttpStatusCode.BadRequest, "当前密码不正确,请重新输入!");
        }
示例#2
0
        public async Task <IActionResult> UpdatePwd(UpdatePwdViewModel seller)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string flag = "";
                    HttpContext.Request.Cookies.TryGetValue("CurrentUser", out flag);
                    if (string.IsNullOrEmpty(flag))
                    {
                        return(RedirectToAction(nameof(SellerController.Login), "Seller"));
                    }
                    else
                    {
                        Seller cur = JsonConvert.DeserializeObject <Seller>(flag);
                        Seller ss  = this._context.Sellers.First <Seller>(t => t.Id == cur.Id);
                        ss.Password = seller.Password;
                        var result = await this._context.SaveChangesAsync();

                        cur.Password = seller.Password;
                        string currentUser = JsonConvert.SerializeObject(cur);
                        HttpContext.Response.Cookies.Append("CurrentUser", currentUser);
                        return(RedirectToAction(nameof(SellerController.Profile), "Seller"));
                    }
                }
                catch (Exception ex)
                {
                    HttpContext.Response.Cookies.Append("IsSuccess", "false");
                    HttpContext.Response.Cookies.Append("Messages", ex.Message);
                    HttpContext.Response.Cookies.Append("IsRegister", "false");
                    HttpContext.Response.Cookies.Append("Info", "Woops, Update Password Failed!");
                    return(RedirectToAction(nameof(SellerController.Result), "Seller"));
                }
            }
            return(View());
        }