|
|
-
-
- function createLdapUser(adminUid, adminPwd, newEntry) {
- if (adminUid === "admin" && adminPwd === "password") {
- return { "failed": false,
- "newPasswd": "NuOvA-PaSsWwOrD" };
- }
- return { "failed": true,
- "reason": "Invalid admin username or password." };
-
- };
-
- var lilikAddUserApp = angular.module('lilikAddUserApp', []);
-
- lilikAddUserApp.filter('excludeKey', function() {
- return function(input, search) {
- if (!input) return input;
- if (!search) return input;
- var excluded_key = ('' + search);
- var result = {};
- angular.forEach(input, function(value, key) {
- var actual_key = ('' + key);
- if (actual_key != excluded_key) {
- result[key] = value;
- }
- });
- return result;
- }
- });
-
- lilikAddUserApp.controller('AddUserController', function AddUserController($scope, $http) {
- // Initialize scope variable
- $scope.showLoginForm = true;
- $scope.showAddForm = false;
- $scope.showConfirmForm = false;
- $scope.startConfirm = false;
- $scope.creationPending = false;
- $scope.newExtraGroups = [];
-
- $scope.typingUser = function () {
- $scope.newUid = $scope.newUid.toLowerCase().replace(' ', '.');
- $scope.newCn = $scope.newUid.replace('.',' ').replace(/(^\w|\s\w)/g, m => m.toUpperCase());
- };
-
- $scope.notPrincipal = function (group) {
- return group.key !== $scope.newGroup;
- }
-
- // Try to login and download groups
- $scope.getGroups = function () {
- $scope.creationPending = true;
- delete $scope.loginError;
- $http.post('../user_backend/groups', { 'username': $scope.adminUid, 'password': $scope.adminPwd })
- .then(function (response) {
- result = response.data;
- if (result.failed === false) {
- $scope.showAddForm = true;
- $scope.showLoginForm = false;
- $scope.groups = result.groups;
- } else {
- $scope.loginError = result.reason;
- }
- });
- $scope.creationPending = false;
- };
-
- // Ask for confirmation of user details
- $scope.createNewUser = function () {
- $scope.startConfirm = true;
- };
-
- // Try to create the user
- $scope.confirmNewUser = function () {
- newEntry = {
- "cn": $scope.newCn,
- "sn": $scope.newSn,
- "memberOf": $scope.newExtraGroups
- };
- $http.post('../user_backend/group/'+$scope.newGroup+'/create/'+$scope.newUid,
- {
- 'username': $scope.adminUid,
- 'password': $scope.adminPwd,
- 'newEntry': newEntry
- })
- .then(function (response) {
- result = response.data;
- if (result.failed === false) {
- $scope.newPasswd = result.newPasswd;
- } else {
- $scope.createError = result.reason;
- }
- });
- };
-
- // Clear old user scope variable and start creating another
- $scope.anotherUser = function () {
- delete $scope.newPasswd;
- delete $scope.newGroup;
- delete $scope.newUid;
- delete $scope.newCn;
- delete $scope.newSn;
- $scope.newExtraGroups = [];
- $scope.startConfirm = false;
- };
-
- $scope.editUser = function () {
- delete $scope.createError;
- $scope.startConfirm = false;
- };
- });
|