public HttpResponseMessage ChangePassword(HttpRequestMessage request, [FromBody] AccountChangePasswordModel passwordModel)
        {
            return(GetHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                var loginName = User.Identity.Name;
                passwordModel.LoginID = loginName;
                ValidateAuthorizedUser(passwordModel.LoginID);
                _SecurityAdapter.Initialize();
                //_SecurityAdapter.LogOut();

                bool success = _SecurityAdapter.ChangePassword(passwordModel.LoginID, passwordModel.OldPassword, passwordModel.NewPassword);
                //bool success = _SecurityAdapter.ChangePassword(loginName, passwordModel.OldPassword, passwordModel.NewPassword);
                if (success)
                {
                    response = request.CreateResponse(HttpStatusCode.OK);
                }
                else
                {
                    response = request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Unable to change password.");
                }
                //_SecurityAdapter.LogOut();
                return response;
            }));
        }
        public HttpResponseMessage ChangePassword(HttpRequestMessage request, [FromBody] AccountChangePasswordModel changePasswordModel)
        {
            return(GetHttpResponse(request, () =>
            {
                var loginID = User.Identity.Name;

                _SecurityAdapter.Initialize();

                var status = _SecurityAdapter.ChangePassword(loginID, changePasswordModel.OldPassword, changePasswordModel.NewPassword);

                return request.CreateResponse <bool>(HttpStatusCode.OK, status);
            }));
        }
        public HttpResponseMessage ChangePassword(HttpRequestMessage request, [FromBody] AccountChangePasswordModel passwordModel)
        {
            return(GetHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                ValidateAuthorizedUser(passwordModel.LoginEmail);

                bool success = _SecurityAdapter.ChangePassword(passwordModel.LoginEmail, passwordModel.OldPassword, passwordModel.NewPassword);
                if (success)
                {
                    response = request.CreateResponse(HttpStatusCode.OK);
                }
                else
                {
                    response = request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Unable to change password.");
                }

                return response;
            }));
        }
示例#4
0
        /// <summary>
        /// Change the member's password.
        /// </summary>
        /// <param name="oldPassword">Old Password</param>
        /// <param name="newPassword">New Password - Rules vary on configuration and provider used.</param>
        /// <returns>Status of request directly from the adapter.</returns>
        /// <exception cref="WtfException">Underlying call to the adapter's ChangePassword(oldPassword, newPassword) has failed with an exception</exception>
        public ChangePasswordStatus ChangePassword(string oldPassword, string newPassword)
        {
            String logMethodName = ".ChangePassword(string oldPassword, string newPassword) - ";

            _log.Debug(logMethodName + "Begin Method");

            ChangePasswordStatus status = ChangePasswordStatus.Error;

            try
            {
                _log.Debug(logMethodName + "Calling ISecurityAdapter.ChangePassword(String oldPassword, String newPassword)");
                status = _adapter.ChangePassword(oldPassword, newPassword);
            }
            catch (Exception ex)
            {
                _log.Error(logMethodName + "Error attempting to change the account password", ex);
                throw new WtfException("Error attempting to change the account password", ex);
            }

            _log.Debug(logMethodName + "End Method");
            return(status);
        }
示例#5
0
        public async Task <ActionResult> ChangePassword(ChangePasswordModel model)
        {
            ActionResult response = null;

            var errors = new List <string>();

            if (!await _securityAdapter.CheckPassword(User.Identity.Name, model.OldPassword))
            {
                errors.Add("Old password is incorrect");
            }

            if (string.IsNullOrWhiteSpace(model.NewPassword))
            {
                errors.Add("New password is invalid");
            }

            if (model.NewPassword != model.ConfirmPassword)
            {
                errors.Add("Passwords do not match");
            }

            bool changePasswordSuccess = false;

            if (!errors.Any())
            {
                changePasswordSuccess = await _securityAdapter.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword);
            }

            if (changePasswordSuccess)
            {
                response = StatusCode((int)HttpStatusCode.OK);
            }
            else
            {
                response = StatusCode((int)HttpStatusCode.BadRequest, errors);
            }

            return(response);
        }