예제 #1
0
        /// <summary>
        /// Change password
        /// </summary>
        /// <param name="request">Request</param>
        /// <returns>Result</returns>
        public virtual DataResult ChangePassword(ChangePasswordRequest request)
        {
            Guard.IsNotNull(request, "Request");

            var result = new DataResult();
            if (String.IsNullOrWhiteSpace(request.UserName))
            {
                result.AddError(this.localizationService.GetResource("Security.Login.UserDoesNotExists"));
                return result;
            }
            if (String.IsNullOrWhiteSpace(request.NewPassword))
            {
                result.AddError("Password is not entered");
                return result;
            }

            var User = this.userService.GetByUsername(request.UserName);
            if (User == null)
            {
                result.AddError(this.localizationService.GetResource("Security.Login.UserDoesNotExists"));
                return result;
            }

            var requestIsValid = false;
            if (request.ValidateRequest)
            {
                //password
                string oldPwd = request.OldPassword;

                bool oldPasswordIsValid = encryptionService.GetSHAHash(oldPwd,true).IsCaseInsensitiveEqual(User.Password);

                if (!oldPasswordIsValid)
                    result.AddError("Old password doesn't match");

                if (oldPasswordIsValid)
                    requestIsValid = true;
            }
            else
                requestIsValid = true;

            //at this point request is valid
            if (requestIsValid)
            {
                User.Password = encryptionService.GetSHAHash(request.NewPassword, true);
                User.LastPasswordChangeDate = DateTime.UtcNow; // set the date time when the password has been changed.

                this.userService.Update(User);
            }

            return result;
        }
예제 #2
0
        public ActionResult AccountActivation(AccountActivationModel model)
        {
            if (ModelState.IsValid)
            {
                var user = ValidateUserActivation(model.UserId, model.Token, SystemUserAttributeNames.AccountActivationToken);

                // set the question and answers and the security verification image for this user in the database
                if (user != null)
                {
                    // set this user unique password
                    ChangePasswordRequest changeRequest = new ChangePasswordRequest(user.Username,
                        false, model.Password);
                    var changeResult = userRegistrationService.ChangePassword(changeRequest);

                    if (changeResult.Success)
                    {
                        // activate this user account now
                        user.CurrentPublishingStatus = PublishingStatus.Active;
                        user.LastActivityDate = DateTime.UtcNow;
                        userService.Update(user);

                        // need to delete the activation token
                        attributeService.SaveAttribute(user, SystemUserAttributeNames.AccountActivationToken, string.Empty);

                        SuccessNotification("Your account has been activated");
                        return RedirectToRoute(SystemRouteNames.Login);
                    }

                    ErrorNotification(changeResult.ErrorMessages);
                }
            }

            // reached here, means error, show the form again
            PrepareAccountActivationModel(model);
            return View(model);
        }
예제 #3
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {
                var changePasswordRequest = new ChangePasswordRequest(workContext.CurrentUser.Username,
                    true, model.NewPassword, model.OldPassword);
                var changePasswordResult = userRegistrationService.ChangePassword(changePasswordRequest);
                if (changePasswordResult.Success)
                {
                    SuccessNotification("Your password has been successfully changed");
                    return RedirectToRoute(SystemRouteNames.HomePage);
                }
                else
                {
                    ErrorNotification(changePasswordResult.ErrorMessages);
                }
            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }