User password change dashboard

This commit is contained in:
perploug
2013-09-16 14:50:56 +02:00
parent b6d00cca63
commit fdfb019ea7
8 changed files with 108 additions and 29 deletions

View File

@@ -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
* <pre>
* contentResource.getAll()
* .then(function(userArray) {
* var myUsers = userArray;
* alert('they are here!');
* });
* </pre>
*
* @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');
}
};
}

View File

@@ -72,7 +72,6 @@ angular.module('umbraco.services')
},
logout: function () {
return authResource.performLogout()
.then(function (data) {
currentUser = null;

View File

@@ -1,28 +1,49 @@
<form name="passwordForm" ng-controller="Umbraco.Dashboard.StartupChangePasswordController">
<h3>Change password</h3>
<p>Enter your current password, then repeat your new password to change it</p>
<umb-pane>
<umb-control-group label="Old password">
<input type="text" name="oldpass" ng-model="profile.oldPassword" required/>
<input type="password" name="oldpass" ng-model="profile.oldPassword" required/>
<small class="help-inline"
ng-show="passwordForm.oldpass.$error.required">
Required
</small>
<small class="help-inline"
ng-show="passwordForm.passcompare.$error.serverside">
Old password was not correct
</small>
</umb-control-group>
<umb-control-group label="New password">
<input type="text" name="pass" ng-model="profile.newPassword" required/>
<input type="password" name="pass" ng-model="profile.newPassword" required/>
<span class="help-inline" val-msg-for="pass" val-toggle-msg="required">Required</span>
</umb-control-group>
<umb-control-group label="Repeat new password">
<input type="text" name="passcompare"
val-custom="{compare: '$value === profile.newPassword'}"
<input type="password" name="passcompare"
val-custom="{compare: '$value === profile.newPassword'}"
val-custom-watch="'profile.newPassword'"
ng-model="profile.repeatNewPassword" required/>
<small class="help-inline"
ng-show="passwordForm.passcompare.$error.required">
Required
</small>
<small class="help-inline"
ng-show="passwordForm.passcompare.$error.compare">
You must re-enter the new password
</small>
</umb-control-group>
<umb-control-group hideLabel="1">
<button class="btn btn-primary"
ng-disabled="!passwordForm.$valid"
ng-click="changePassword(profile)">Change</button>
</umb-control-group>
</umb-pane>
{{profile | json}} ---
{{passwordForm.$error | json}}
{{passwordForm | json}}
</form>

View File

@@ -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);
});
}
}