public IHttpActionResult UpdatePassword(UpdatePass pass)
        {
            string str = "Password modification failed";

            if (!string.IsNullOrEmpty(pass.username) && !string.IsNullOrEmpty(pass.newPassword) && !string.IsNullOrEmpty(pass.oldP))
            {
                var MembershipService = new AccountMembershipService();
                try
                {
                    Membership.ApplicationName = "MES";
                    if (MembershipService.ChangePassword(pass.username, pass.oldP, pass.newPassword))
                    {
                        str = "Password reset complete";
                    }
                    else
                    {
                        return(BadRequest("Password modification failed"));
                    }
                }
                catch (Exception eJob)
                {
                    var error = string.Format("Job错误,执行aspnet_Membership_SetPassword出错,错误信息{0}", eJob.Message);
                    var resp  = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                    {
                        ReasonPhrase = error,
                        Content      = new StringContent(error)
                    };

                    Loger.Error(eJob);
                    throw new HttpResponseException(resp);
                }
            }

            return(Ok(str));
        }
        public ActionResult UpdateDeveloperPassSubmit(UpdatePass pass)
        {
            if (Session["CurrentUser"] == null)
                return RedirectToAction("RedirectByUser");
            User CurrentUser = (User)Session["CurrentUser"];
            TryValidateModel(pass);
            if (ModelState.IsValid && pass.OldPassword==CurrentUser.Password)
            {

                UserDal usrDal = new UserDal();
                User updateUser = usrDal.Users.FirstOrDefault(x => x.UserName == CurrentUser.UserName);
                updateUser.Password = pass.NewPassword;
                usrDal.SaveChanges();
                TempData["Update"] = "הסיסמה שונתה בהצלחה";
                return RedirectToAction("ShowDeveloperProfile");
            }
            TempData["notUpdate"] = "לא בוצע שינוי!";
            return RedirectToAction("ShowDeveloperProfile");

        }
Exemplo n.º 3
0
        public IActionResult UpdatePass([FromBody] UpdatePass model)
        {
            var userID = _userService.GetContextUserId(HttpContext.User);
            var user   = _userService.Get(userID);

            if (!_userService.UpdatePassword(user.Email, model.Pass))
            {
                return(NotFound());
            }

            var userDto = new UserDto()
            {
                Id     = user.Id,
                Name   = user.UserName + "**",
                Email  = user.Email,
                Active = user.Active
            };

            return(Ok(userDto));
        }
Exemplo n.º 4
0
        // GET api/updatepwd/5
        public string Get(string userName, string oldPwd, string newPwd)
        {
            UpdatePass updatepass = new UpdatePass();

            return(updatepass.UpdatePassword(userName, oldPwd, newPwd));;
        }