예제 #1
0
        public IActionResult ResetPwdO(ResetPwdDTO model)
        {
            if (!_loginServices.isInAdminRoles(this.GetRoles()))
            {
                return(RedirectToAction("Login", "Accounts"));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var user = this._context.Users.Where(w => w.ID == model.ID).FirstOrDefault();
                    if (model.oldpassword == model.password)
                    {
                        ModelState.AddModelError("oldpassword", "รหัสผ่านใหม่เหมือนกับรหัสผ่านเดิม");
                        ModelState.AddModelError("password", "รหัสผ่านใหม่เหมือนกับรหัสผ่านเดิม");
                    }
                    if (model.oldpassword != DataEncryptor.Decrypt(user.Password))
                    {
                        ModelState.AddModelError("oldpassword", "รหัสผ่านเดิมไม่ถูกต้อง");
                    }
                    if (ModelState.IsValid)
                    {
                        if (!string.IsNullOrEmpty(model.password))
                        {
                            user.Password  = DataEncryptor.Encrypt(model.password);
                            user.Update_On = DateUtil.Now();
                            user.Update_By = this.HttpContext.User.Identity.Name;
                        }

                        this._context.Users.Attach(user);
                        this._context.Entry(user).Property(u => u.Password).IsModified  = true;
                        this._context.Entry(user).Property(u => u.Update_On).IsModified = true;
                        this._context.Entry(user).Property(u => u.Update_By).IsModified = true;
                        this._context.SaveChanges();

                        return(RedirectToAction("Update", new { ID = model.ID }));
                    }
                }
                catch
                {
                }
            }
            return(View(model));
        }
예제 #2
0
        public IActionResult ResetPwdO()
        {
            if (!_loginServices.isInAdminRoles(this.GetRoles()))
            {
                return(RedirectToAction("Login", "Accounts"));
            }

            string idParam = "";

            if (this.RouteData.Values["id"] != null)
            {
                idParam = this.RouteData.Values["id"].ToString();
            }
            ResetPwdDTO model    = new ResetPwdDTO();
            int         recordId = -1;

            if (!string.IsNullOrEmpty(idParam))
            {
                recordId = Int32.Parse(idParam);
                var user = this._context.Users.Where(c => c.ID == recordId).FirstOrDefault();
                if (user == null)
                {
                    ModelState.AddModelError("Error", "ไม่พบข้อมูลสมาชิก");
                    return(RedirectToAction("Index"));
                }
                else
                {
                    model.ID = user.ID;
                }
            }
            else
            {
                ModelState.AddModelError("Error", "ไม่พบข้อมูลสมาชิก");
                return(RedirectToAction("Index", "Home"));
            }
            return(View("ResetPwdO", model));
        }
예제 #3
0
 public JsonResult ResetPwd([FromBody] ResetPwdDTO model)
 {
     return(Json(new { responseCode = "200", responseDesc = "Reset password successfully." }));
 }