demo20230512/Browser_Local/js/Management/ManagementCreateUserController.js
2023-05-12 10:20:28 +08:00

72 lines
3.0 KiB
JavaScript

angular.module('CarbonFootprint')
.config(function ($routeProvider, CONSTANTS) {
$routeProvider.when('/Management/CreateUser', {
templateUrl: CONSTANTS.PB + 'Management-CreateUser',
controller: 'ManagementCreateUserCtrl'
});
})
.controller('ManagementCreateUserCtrl', ['$scope', '$timeout', 'Redirect', 'Survey_Data_Service',
function ($scope, $timeout, Redirect, Survey_Data_Service) {
var redirect = new Redirect();
$scope.correctUserName = false;
$scope.password_match = false;
$scope.needChangePassword = false;
$scope.account_repeat = false;
$scope.isCheckOnce = false;
$scope.user = {};
$scope.createUser = function () {
$scope.isCheckOnce = true;
$scope.user.DefaultPassword = $scope.user.Password;
Save(Survey_Data_Service.API, $scope.user, 'User', 'Save')
.then(function (response) {
console.log('createUser then', response);
if (mergeNumber(response) !== -1) {
redirect.backToManagement();
} else {
$scope.account_repeat = true;
}
}, function (error) {
console.log('createUser error', error);
console.log('error.data', error.data);
console.log('error.data.ExceptionMessage', error.data.ExceptionMessage);
if (typeof (error) !== 'undefined' &&
typeof (error.data) !== 'undefined' &&
typeof (error.data.ExceptionMessage) !== 'undefined')
alert(error.data.ExceptionMessage);
});
};
$scope.checkUserName = function (user_name) {
if (/^\w+$/.test(user_name) && user_name.length >= 5 && user_name.length <= 25) {
$scope.correctUserName = true;
} else {
$scope.correctUserName = false;
}
};
$scope.checkPassword = function () {
var pwd = $scope.user.Password,
re_pwd = $scope.user.PasswordRepeat;
$scope.password_match = pwd === re_pwd ? true : false;
};
$scope.checkChangePassword = function () {
var pwd = $scope.user.ChangePassword.NewPassword,
re_pwd = $scope.user.ChangePassword.PasswordRepeat;
$scope.change_password_match = pwd === re_pwd ? true : false;
};
$scope.changePassword = function () {
$scope.isChangeCheckOnce = true;
};
$scope.backToManagement = function () {
redirect.backToManagement();
};
}]);