2016-07-07 18:03:32 +02:00
|
|
|
/*
|
|
|
|
Copyright (c) 2016 VMware, Inc. All Rights Reserved.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
2016-05-10 12:43:52 +02:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('harbor.layout.reset.password')
|
|
|
|
.controller('ResetPasswordController', ResetPasswordController);
|
|
|
|
|
2016-07-01 12:37:17 +02:00
|
|
|
ResetPasswordController.$inject = ['$scope', '$location', 'ResetPasswordService', '$window', 'getParameterByName', '$filter', 'trFilter'];
|
2016-05-10 12:43:52 +02:00
|
|
|
|
2016-07-01 12:37:17 +02:00
|
|
|
function ResetPasswordController($scope, $location, ResetPasswordService, $window, getParameterByName, $filter, trFilter) {
|
2016-05-10 12:43:52 +02:00
|
|
|
var vm = this;
|
|
|
|
vm.resetUuid = getParameterByName('reset_uuid', $location.absUrl());
|
2016-05-14 07:34:54 +02:00
|
|
|
|
|
|
|
vm.reset = reset;
|
2016-05-10 12:43:52 +02:00
|
|
|
vm.resetPassword = resetPassword;
|
2016-07-01 12:37:17 +02:00
|
|
|
vm.confirm = confirm;
|
2016-05-14 07:34:54 +02:00
|
|
|
vm.cancel = cancel;
|
|
|
|
|
|
|
|
vm.hasError = false;
|
|
|
|
vm.errorMessage = '';
|
|
|
|
|
2016-07-01 12:37:17 +02:00
|
|
|
//Error message dialog handler for resetting password.
|
|
|
|
$scope.$on('modalTitle', function(e, val) {
|
|
|
|
vm.modalTitle = val;
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.$on('modalMessage', function(e, val) {
|
|
|
|
vm.modalMessage = val;
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.$on('raiseError', function(e, val) {
|
|
|
|
if(val) {
|
|
|
|
vm.action = function() {
|
|
|
|
$scope.$broadcast('showDialog', false);
|
|
|
|
};
|
|
|
|
vm.contentType = 'text/plain';
|
|
|
|
vm.confirmOnly = true;
|
|
|
|
$scope.$broadcast('showDialog', true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-05-14 07:34:54 +02:00
|
|
|
function reset() {
|
|
|
|
vm.hasError = false;
|
|
|
|
vm.errorMessage = '';
|
|
|
|
}
|
|
|
|
|
2016-05-10 12:43:52 +02:00
|
|
|
function resetPassword(user) {
|
2016-05-16 05:41:54 +02:00
|
|
|
if(user && angular.isDefined(user.password)) {
|
2016-07-01 12:37:17 +02:00
|
|
|
|
|
|
|
vm.action = vm.confirm;
|
|
|
|
|
2016-05-14 07:34:54 +02:00
|
|
|
console.log('rececived password:' + user.password + ', reset_uuid:' + vm.resetUuid);
|
|
|
|
ResetPasswordService(vm.resetUuid, user.password)
|
|
|
|
.success(resetPasswordSuccess)
|
|
|
|
.error(resetPasswordFailed);
|
|
|
|
}
|
2016-05-10 12:43:52 +02:00
|
|
|
}
|
|
|
|
|
2016-07-01 12:37:17 +02:00
|
|
|
function confirm() {
|
|
|
|
$window.location.href = '/';
|
|
|
|
}
|
|
|
|
|
2016-05-10 12:43:52 +02:00
|
|
|
function resetPasswordSuccess(data, status) {
|
2016-07-01 12:37:17 +02:00
|
|
|
vm.modalTitle = $filter('tr')('reset_password');
|
|
|
|
vm.modalMessage = $filter('tr')('successful_reset_password');
|
|
|
|
vm.confirmOnly = true;
|
|
|
|
$scope.$broadcast('showDialog', true);
|
2016-05-10 12:43:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function resetPasswordFailed(data) {
|
2016-05-14 07:34:54 +02:00
|
|
|
vm.hasError = true;
|
2016-07-01 12:37:17 +02:00
|
|
|
|
|
|
|
$scope.$emit('modalTitle', $filter('tr')('error'));
|
2016-07-04 06:34:34 +02:00
|
|
|
$scope.$emit('modalMessage', $filter('tr')('failed_to_reset_pasword') + data);
|
2016-07-01 12:37:17 +02:00
|
|
|
$scope.$emit('raiseError', true);
|
|
|
|
|
2016-07-04 06:34:34 +02:00
|
|
|
console.log('Failed to reset password:' + data);
|
2016-05-10 12:43:52 +02:00
|
|
|
}
|
|
|
|
|
2016-07-01 12:37:17 +02:00
|
|
|
function cancel() {
|
|
|
|
$window.location.href = '/';
|
2016-05-14 07:34:54 +02:00
|
|
|
}
|
2016-05-10 12:43:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
})();
|