public JsonResult UpdateProfile(ProfileModel model) { try { Assert.ArgumentNotNull(model, "UpdateProfileInputModel"); ProfileBaseJsonResult result = new ProfileBaseJsonResult(); this.ValidateModel(result); if (result.HasErrors) { return Json(result, JsonRequestBehavior.AllowGet); } if (!Context.User.IsAuthenticated || Context.User.Profile.IsAdministrator) { return Json(result); } var response = this.AccountManager.UpdateUser(this.CurrentStorefront, this.CurrentVisitorContext, model); result.SetErrors(response.ServiceProviderResult); if (response.ServiceProviderResult.Success && !string.IsNullOrWhiteSpace(model.Password) && !string.IsNullOrWhiteSpace(model.PasswordRepeat)) { var changePasswordModel = new ChangePasswordInputModel { NewPassword = model.Password, ConfirmPassword = model.PasswordRepeat }; var passwordChangeResponse = this.AccountManager.UpdateUserPassword(this.CurrentStorefront, this.CurrentVisitorContext, changePasswordModel); result.SetErrors(passwordChangeResponse.ServiceProviderResult); if (passwordChangeResponse.ServiceProviderResult.Success) { result.Initialize(response.ServiceProviderResult); } } return Json(result); } catch (Exception e) { CommerceLog.Current.Error("UpdateProfile", this, e); return Json(new BaseJsonResult("UpdateProfile", e), JsonRequestBehavior.AllowGet); } }
/// <summary> /// Updates the user password. /// </summary> /// <param name="storefront">The storefront.</param> /// <param name="visitorContext">The visitor context.</param> /// <param name="inputModel">The input model.</param> /// <returns>The manager response.</returns> public virtual ManagerResponse<UpdatePasswordResult, bool> UpdateUserPassword([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext, ChangePasswordInputModel inputModel) { Assert.ArgumentNotNull(storefront, "storefront"); Assert.ArgumentNotNull(visitorContext, "visitorContext"); Assert.ArgumentNotNull(inputModel, "inputModel"); Assert.ArgumentNotNullOrEmpty(inputModel.OldPassword, "inputModel.OldPassword"); Assert.ArgumentNotNullOrEmpty(inputModel.NewPassword, "inputModel.NewPassword"); var userName = visitorContext.UserName; var request = new UpdatePasswordRequest(userName, inputModel.OldPassword, inputModel.NewPassword); var result = this.CustomerServiceProvider.UpdatePassword(request); if (!result.Success && !result.SystemMessages.Any()) { var message = StorefrontManager.GetSystemMessage("PasswordCouldNotBeReset"); result.SystemMessages.Add(new SystemMessage { Message = message }); } if (!result.Success) { Helpers.LogSystemMessages(result.SystemMessages, result); } return new ManagerResponse<UpdatePasswordResult, bool>(result, result.Success); }
public JsonResult ChangePassword(ChangePasswordInputModel inputModel) { try { Assert.ArgumentNotNull(inputModel, "ChangePasswordInputModel"); ChangePasswordBaseJsonResult result = new ChangePasswordBaseJsonResult(); this.ValidateModel(result); if (result.HasErrors) { return Json(result, JsonRequestBehavior.AllowGet); } var response = this.AccountManager.UpdateUserPassword(this.CurrentStorefront, this.CurrentVisitorContext, inputModel); result = new ChangePasswordBaseJsonResult(response.ServiceProviderResult); if (response.ServiceProviderResult.Success) { result.Initialize(this.CurrentVisitorContext.UserName); } return Json(result); } catch (Exception e) { CommerceLog.Current.Error("ChangePassword", this, e); return Json(new BaseJsonResult("ChangePassword", e), JsonRequestBehavior.AllowGet); } }