From f33d21b8f61013e7d9fd9d84faa262b8ca8e7244 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 15 Jun 2017 12:45:53 +0200 Subject: [PATCH] Gets all the localization for the invite setup and error checking based on the password provider information --- .../src/common/resources/auth.resource.js | 19 ++++++- .../common/resources/currentuser.resource.js | 20 +------- .../views/common/dialogs/login.controller.js | 49 ++++++++++++++----- .../src/views/common/dialogs/login.html | 10 ++-- .../views/common/dialogs/user.controller.js | 2 +- .../common/overlays/user/user.controller.js | 2 +- .../Editors/AuthenticationController.cs | 11 +++++ .../Editors/BackOfficeController.cs | 2 +- .../Editors/CurrentUserController.cs | 12 +---- .../MembershipProviderExtensions.cs | 3 +- 10 files changed, 80 insertions(+), 50 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/auth.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/auth.resource.js index 5de92527d3..4f95893490 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/auth.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/auth.resource.js @@ -200,7 +200,7 @@ function authResource($q, $http, umbRequestHelper, angularHelper) { if (!newPassword) { return angularHelper.rejectedPromise({ errorMsg: 'newPassword cannot be empty' }); - } + } return umbRequestHelper.resourcePromise( $http.post( @@ -209,6 +209,23 @@ function authResource($q, $http, umbRequestHelper, angularHelper) { "PostSetInvitedUserPassword"), angular.toJson(newPassword)), 'Failed to change password'); + }, + + /** + * @ngdoc method + * @name umbraco.resources.currentUserResource#getMembershipProviderConfig + * @methodOf umbraco.resources.currentUserResource + * + * @description + * Gets the configuration of the user membership provider which is used to configure the change password form + */ + getMembershipProviderConfig: function () { + return umbRequestHelper.resourcePromise( + $http.get( + umbRequestHelper.getApiUrl( + "authenticationApiBaseUrl", + "GetMembershipProviderConfig")), + 'Failed to retrieve membership provider config'); }, /** diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/currentuser.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/currentuser.resource.js index 21f55dd6a1..fee8f34e41 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/currentuser.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/currentuser.resource.js @@ -29,24 +29,8 @@ function currentUserResource($q, $http, umbRequestHelper) { "PostChangePassword"), changePasswordArgs), 'Failed to change password'); - }, - - /** - * @ngdoc method - * @name umbraco.resources.currentUserResource#getMembershipProviderConfig - * @methodOf umbraco.resources.currentUserResource - * - * @description - * Gets the configuration of the user membership provider which is used to configure the change password form - */ - getMembershipProviderConfig: function () { - return umbRequestHelper.resourcePromise( - $http.get( - umbRequestHelper.getApiUrl( - "currentUserApiBaseUrl", - "GetMembershipProviderConfig")), - 'Failed to retrieve membership provider config'); - }, + } + }; } diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/login.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/login.controller.js index 229bc1047a..904ae58289 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/login.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/login.controller.js @@ -1,22 +1,43 @@ angular.module("umbraco").controller("Umbraco.Dialogs.LoginController", - function ($scope, $cookies, $location, currentUserResource, formHelper, localizationService, userService, externalLoginInfo, resetPasswordCodeInfo, $timeout, authResource, dialogService) { + function ($scope, $cookies, $location, currentUserResource, formHelper, localizationService, userService, externalLoginInfo, resetPasswordCodeInfo, $timeout, authResource, dialogService, $q) { $scope.invitedUser = null; $scope.invitedUserPasswordModel = { - password: "", - confirmPassword: "" + password: "", + confirmPassword: "", + buttonState: "", + passwordPolicies: null, + passwordPolicyText: "" } function init() { // Check if it is a new user if ($location.search().invite) { - - authResource.getCurrentInvitedUser().then(function (data) { - $scope.invitedUser = data; + + $q.all([ + //get the current invite user + authResource.getCurrentInvitedUser().then(function (data) { + $scope.invitedUser = data; + }, + function() { + //it failed so we should remove the search + $location.search('invite', null); + }), + //get the membership provider config for password policies + authResource.getMembershipProviderConfig().then(function (data) { + $scope.invitedUserPasswordModel.passwordPolicies = data; + + //localize the text + localizationService.localize("errorHandling_errorInPasswordFormat", + [ + $scope.invitedUserPasswordModel.passwordPolicies.minPasswordLength, + $scope.invitedUserPasswordModel.passwordPolicies.minNonAlphaNumericChars + ]).then(function(data) { + $scope.invitedUserPasswordModel.passwordPolicyText = data; + }); + }) + ]).then(function() { $scope.inviteSetPassword = true; - }, function () { - //it failed so we should remove the search - $location.search('invite', null); }); } } @@ -25,14 +46,14 @@ if (formHelper.submitForm({ scope: $scope, statusMessage: "Saving..." })) { - $scope.inviteChangePasswordButtonState = "busy"; + $scope.invitedUserPasswordModel.buttonState = "busy"; authResource.performSetInvitedUserPassword($scope.invitedUserPasswordModel.password) .then(function (data) { //success formHelper.resetForm({ scope: $scope, notifications: data.notifications }); - $scope.inviteChangePasswordButtonState = "success"; + $scope.invitedUserPasswordModel.buttonState = "success"; $scope.inviteSetPassword = false; $scope.inviteSetAvatar = true; @@ -42,7 +63,7 @@ //error formHelper.handleError(err); - $scope.inviteChangePasswordButtonState = "error"; + $scope.invitedUserPasswordModel.buttonState = "error"; }); } @@ -144,6 +165,8 @@ } $scope.loginSubmit = function (login, password) { + + //TODO: Do validation properly like in the invite password update //if the login and password are not empty we need to automatically // validate them - this is because if there are validation errors on the server @@ -195,6 +218,8 @@ $scope.requestPasswordResetSubmit = function (email) { + //TODO: Do validation properly like in the invite password update + if (email && email.length > 0) { $scope.requestPasswordResetForm.email.$setValidity('auth', true); } diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/login.html b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/login.html index 059366659b..0fb7af2c42 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/login.html +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/login.html @@ -18,10 +18,11 @@
- - Required + + Your new password cannot be blank! + Minimum {{invitedUserPasswordModel.passwordPolicies.minPasswordLength}} characters
@@ -29,12 +30,13 @@ Required + The confirmed password doesn't match the new password!
diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/user.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/user.controller.js index bac8fcded7..cc7f1d158f 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/user.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/user.controller.js @@ -115,7 +115,7 @@ angular.module("umbraco") }; //go get the config for the membership provider and add it to the model - currentUserResource.getMembershipProviderConfig().then(function(data) { + authResource.getMembershipProviderConfig().then(function(data) { $scope.changePasswordModel.config = data; //ensure the hasPassword config option is set to true (the user of course has a password already assigned) //this will ensure the oldPassword is shown so they can change it diff --git a/src/Umbraco.Web.UI.Client/src/views/common/overlays/user/user.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/overlays/user/user.controller.js index 2ba14f13b6..f59292dcc8 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/overlays/user/user.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/overlays/user/user.controller.js @@ -121,7 +121,7 @@ angular.module("umbraco") }; //go get the config for the membership provider and add it to the model - currentUserResource.getMembershipProviderConfig().then(function(data) { + authResource.getMembershipProviderConfig().then(function(data) { $scope.changePasswordModel.config = data; //ensure the hasPassword config option is set to true (the user of course has a password already assigned) //this will ensure the oldPassword is shown so they can change it diff --git a/src/Umbraco.Web/Editors/AuthenticationController.cs b/src/Umbraco.Web/Editors/AuthenticationController.cs index eaa26625cf..45a0325df3 100644 --- a/src/Umbraco.Web/Editors/AuthenticationController.cs +++ b/src/Umbraco.Web/Editors/AuthenticationController.cs @@ -50,6 +50,17 @@ namespace Umbraco.Web.Editors get { return _signInManager ?? (_signInManager = TryGetOwinContext().Result.GetBackOfficeSignInManager()); } } + /// + /// Returns the configuration for the backoffice user membership provider - used to configure the change password dialog + /// + /// + [WebApi.UmbracoAuthorize(requireApproval: false)] + public IDictionary GetMembershipProviderConfig() + { + var provider = Core.Security.MembershipProviderExtensions.GetUsersMembershipProvider(); + return provider.GetConfiguration(Services.UserService); + } + /// /// Checks if a valid token is specified for an invited user and if so logs the user in and returns the user object /// diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index 23cafd7c73..b371142fcc 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -339,7 +339,7 @@ namespace Umbraco.Web.Editors }, { "currentUserApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetMembershipProviderConfig()) + controller => controller.PostChangePassword(null)) }, { "legacyApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( diff --git a/src/Umbraco.Web/Editors/CurrentUserController.cs b/src/Umbraco.Web/Editors/CurrentUserController.cs index aacad99fb7..d7da1cd713 100644 --- a/src/Umbraco.Web/Editors/CurrentUserController.cs +++ b/src/Umbraco.Web/Editors/CurrentUserController.cs @@ -29,17 +29,7 @@ namespace Umbraco.Web.Editors [PluginController("UmbracoApi")] public class CurrentUserController : UmbracoAuthorizedJsonController { - - /// - /// Returns the configuration for the backoffice user membership provider - used to configure the change password dialog - /// - /// - public IDictionary GetMembershipProviderConfig() - { - var provider = Core.Security.MembershipProviderExtensions.GetUsersMembershipProvider(); - return provider.GetConfiguration(Services.UserService); - } - + /// /// Changes the users password /// diff --git a/src/Umbraco.Web/MembershipProviderExtensions.cs b/src/Umbraco.Web/MembershipProviderExtensions.cs index 2a32384732..0aec00eb76 100644 --- a/src/Umbraco.Web/MembershipProviderExtensions.cs +++ b/src/Umbraco.Web/MembershipProviderExtensions.cs @@ -28,7 +28,8 @@ namespace Umbraco.Web {"enableReset", canReset}, {"enablePasswordRetrieval", membershipProvider.EnablePasswordRetrieval}, {"requiresQuestionAnswer", membershipProvider.RequiresQuestionAndAnswer}, - {"allowManuallyChangingPassword", baseProvider != null && baseProvider.AllowManuallyChangingPassword} + {"allowManuallyChangingPassword", baseProvider != null && baseProvider.AllowManuallyChangingPassword}, + {"minNonAlphaNumericChars", membershipProvider.MinRequiredNonAlphanumericCharacters} //TODO: Inject the other parameters in here to change the behavior of this control - based on the membership provider settings. }; }