コード例 #1
0
        public ActionResult Staff_ChangePassword(ChangPasswordModel model, string returnURL)
        {
            if (ModelState.IsValid)
            {
                string username = model.Username;
                string password = model.Password;
                string confirm  = model.ConfirmPassword;
                if (confirm.Equals(password))
                {
                    AccountDB accountDB = new AccountDB();
                    bool      check     = accountDB.ChangePass(username, password);
                    if (check)
                    {
                        TempData["alertMessage"] = "Success";
                        return(RedirectToAction("Staff_Product", "Staff"));
                    }
                    else
                    {
                        TempData["alertMessage"] = "Fail";
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Password must match Confirm");
                }
            }

            return(View());
        }
コード例 #2
0
 public IHttpActionResult PostChangePassword([FromBody] ChangPasswordModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             this.memberService.ChangePassword(User.Identity.Name, model);
             return(Ok(new { Message = "Password has chaged" }));
         }catch (Exception e)
         {
             ModelState.AddModelError("Exception", e.Message);
         }
     }
     return(BadRequest(ModelState.GetErrorModelState()));
 }
コード例 #3
0
 public void ChangePassword(string email, ChangPasswordModel model)
 {
     try
     {
         var memberItem = this.db.Members.SingleOrDefault(item => item.email.Equals(email));
         if (memberItem == null)
         {
             throw new Exception("Not found member");
         }
         this.db.Members.Attach(memberItem);
         memberItem.password             = PasswordHashModel.Hash(model.new_pass);
         memberItem.updated              = DateTime.Now;
         this.db.Entry(memberItem).State = System.Data.Entity.EntityState.Modified;
         this.db.SaveChanges();
     }catch (Exception e)
     {
         throw e.GetErrorException();
     }
 }