diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/user.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/user.resource.js index 5c7b379704..2134efc594 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/user.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/user.resource.js @@ -68,6 +68,36 @@ function userResource($q, $http, umbRequestHelper) { "userApiBaseUrl", "GetAll")), 'Failed to retreive all users'); + }, + + /** + * @ngdoc method + * @name umbraco.resources.userResource#changePassword + * @methodOf umbraco.resources.userResource + * + * @description + * Changes the current users password + * + * ##usage + *
+         * contentResource.getAll()
+         *    .then(function(userArray) {
+         *        var myUsers = userArray; 
+         *        alert('they are here!');
+         *    });
+         * 
+ * + * @returns {Promise} resourcePromise object containing the user array. + * + */ + changePassword: function (oldPassword, newPassword) { + return umbRequestHelper.resourcePromise( + $http.post( + umbRequestHelper.getApiUrl( + "userApiBaseUrl", + "PostChangePassword"), + { oldPassword: oldPassword, newPassword: newPassword }), + 'Failed to change password'); } }; } diff --git a/src/Umbraco.Web.UI.Client/src/common/services/user.service.js b/src/Umbraco.Web.UI.Client/src/common/services/user.service.js index 6b5a4cd7b5..54a5ae1999 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/user.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/user.service.js @@ -72,7 +72,6 @@ angular.module('umbraco.services') }, logout: function () { - return authResource.performLogout() .then(function (data) { currentUser = null; diff --git a/src/Umbraco.Web.UI.Client/src/views/dashboard/ChangePassword.html b/src/Umbraco.Web.UI.Client/src/views/dashboard/ChangePassword.html index 1baa74b493..db41e8666a 100644 --- a/src/Umbraco.Web.UI.Client/src/views/dashboard/ChangePassword.html +++ b/src/Umbraco.Web.UI.Client/src/views/dashboard/ChangePassword.html @@ -1,28 +1,49 @@
+

Change password

+

Enter your current password, then repeat your new password to change it

+ - + + + + Required + + + + Old password was not correct + - + + + Required - + + + Required + + + + You must re-enter the new password + + - - {{profile | json}} --- - {{passwordForm.$error | json}} - - {{passwordForm | json}}
\ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/views/dashboard/dashboard.tabs.controller.js b/src/Umbraco.Web.UI.Client/src/views/dashboard/dashboard.tabs.controller.js index 5e5a03caa3..bf5e20a152 100644 --- a/src/Umbraco.Web.UI.Client/src/views/dashboard/dashboard.tabs.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/dashboard/dashboard.tabs.controller.js @@ -1,6 +1,4 @@ function startUpVideosDashboardController($scope, xmlhelper, $log, $http) { - - //xmlHelper.parseFeed("http://umbraco.org/feeds/videos/getting-started").then(function(feed){ //}); @@ -18,17 +16,19 @@ function startUpVideosDashboardController($scope, xmlhelper, $log, $http) { } angular.module("umbraco").controller("Umbraco.Dashboard.StartupVideosController", startUpVideosDashboardController); -function ChangePasswordDashboardController($scope, xmlhelper, $log, userService) { +function ChangePasswordDashboardController($scope, xmlhelper, $log, userResource) { //this is the model we will pass to the service $scope.profile = {}; - $scope.changePassword = function (p) { - userService.changePassword(p.oldPassword, p.newPassword).then(function () { - //changed - }, function () { - //this only happens if there is a wrong oldPassword sent along - $scope.passwordForm.oldPass.$setValidity("oldPassword", false); - }); + $scope.changePassword = function (p) { + userResource.changePassword(p.oldPassword, p.newPassword).then(function () { + alert("changed"); + $scope.passwordForm.$setValidity(true); + }, function () { + alert("not changed"); + //this only happens if there is a wrong oldPassword sent along + $scope.passwordForm.oldpass.$setValidity("oldPassword", false); + }); } } diff --git a/src/Umbraco.Web/Editors/UserController.cs b/src/Umbraco.Web/Editors/UserController.cs index 6508d44205..6863b8fd93 100644 --- a/src/Umbraco.Web/Editors/UserController.cs +++ b/src/Umbraco.Web/Editors/UserController.cs @@ -12,6 +12,7 @@ using Umbraco.Web.Mvc; using legacyUser = umbraco.BusinessLogic.User; using System.Net.Http; +using System.Collections.Specialized; namespace Umbraco.Web.Editors @@ -43,16 +44,16 @@ namespace Umbraco.Web.Editors /// /// /// - public HttpResponseMessage PostChangePassword(string oldPassword, string newPassword) - { + public HttpResponseMessage PostChangePassword(UserPasswordChange data) + { + var u = UmbracoContext.Security.CurrentUser; - if(!System.Web.Security.Membership.ValidateUser(u.Username, oldPassword)) - return new HttpResponseMessage(HttpStatusCode.Unauthorized); - - u.Password = newPassword; - Services.UserService.SaveUser(u); - + if (!UmbracoContext.Security.ValidateBackOfficeCredentials(u.Username, data.OldPassword)) + return new HttpResponseMessage(HttpStatusCode.Forbidden); + if(!UmbracoContext.Security.ChangePassword(data.OldPassword, data.NewPassword)) + return new HttpResponseMessage(HttpStatusCode.InternalServerError); + return new HttpResponseMessage(HttpStatusCode.OK); } diff --git a/src/Umbraco.Web/Models/ContentEditing/UserPasswordChange.cs b/src/Umbraco.Web/Models/ContentEditing/UserPasswordChange.cs new file mode 100644 index 0000000000..f9c384dd5b --- /dev/null +++ b/src/Umbraco.Web/Models/ContentEditing/UserPasswordChange.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Umbraco.Web.Models.ContentEditing +{ + public class UserPasswordChange + { + public string OldPassword { get; set; } + public string NewPassword { get; set; } + } +} diff --git a/src/Umbraco.Web/Security/WebSecurity.cs b/src/Umbraco.Web/Security/WebSecurity.cs index 2f52d9a721..a9f9461e9e 100644 --- a/src/Umbraco.Web/Security/WebSecurity.cs +++ b/src/Umbraco.Web/Security/WebSecurity.cs @@ -181,6 +181,18 @@ namespace Umbraco.Web.Security return membershipProvider != null && membershipProvider.ValidateUser(username, password); } + /// + /// Changes password for a back office user + /// + /// + /// + /// + internal bool ChangePassword(string oldpassword, string newpassword) + { + var membershipProvider = Membership.Providers[LegacyUmbracoSettings.DefaultBackofficeProvider]; + return membershipProvider.GetUser(CurrentUser.Username, true).ChangePassword(oldpassword, newpassword); + } + /// /// Validates the user node tree permissions. /// diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 3338fd23b5..26a7f7aed1 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -317,6 +317,7 @@ + @@ -329,6 +330,7 @@ +