Browse Source

Add support for multiple users in frontend and backend.

master
Zolfa 4 years ago
parent
commit
4dfa7dc599
Signed by: zolfa GPG Key ID: E1A43B038C4D6616
3 changed files with 31 additions and 5 deletions
  1. +3
    -0
      lilik_users.py
  2. +2
    -2
      static/add.html
  3. +26
    -3
      static/add.js

+ 3
- 0
lilik_users.py View File

@ -136,6 +136,9 @@ def new_user(group_cn, new_uid):
else:
ldapmanager_create_uid(new_uid, group_cn, request.json['newEntry'])
g.add_member(group_cn, new_uid)
if 'memberOf' in request.json['newEntry']:
for extra_group in request.json['newEntry']['memberOf']:
g.add_member(extra_group, new_uid)
new_passwd = g.reset_password(new_uid)
result = { "failed": False,
"newPasswd": new_passwd }


+ 2
- 2
static/add.html View File

@ -36,7 +36,7 @@
<div class="form-group">
<label for="newExtraGroups">Gruppi aggiuntivi</label>
<select multiple class="form-control" id="newExtraGroups" ng-model="newExtraGroups" ng-readonly="startConfirm">
<option ng-repeat="(key,value) in groups | filter notPrincipal" value="{{key}}">{{value}}</option>
<option ng-repeat="(key,value) in groups | excludeKey: newGroup" value="{{key}}">{{value}}</option>
</select>
<div class="form-group">
<label for="newUid">Username</label>
@ -63,7 +63,7 @@
<button ng-disabled="creationPending" ng-show="startConfirm && !newPasswd && !createError" class="btn btn-lg btn-primary btn-block" type="submit" ng-click="confirmNewUser()">Conferma</button>
<div ng-show="newPasswd" class="alert alert-success" role="alert">
<h4>Utente creato!</h4>
<p>Quella che segue è la password temporanea. Comunicala all'utente attraverso un canale sicuro e invitalo a modificarla prima di ogni altra cosa,
<p>Quella che segue è la password temporanea. Comunicala all'utente attraverso un canale sicuro e invitalo a modificarla prima di ogni altra cosa,
accedendo a <u>https://login.lilik.it</u>. Copiala e inviala ora, non verrà mostrata in un secondo momento!</p>
<hr>
<h2 class="text-monospace text-center">{{newPasswd}}</h2>


+ 26
- 3
static/add.js View File

@ -12,6 +12,22 @@
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;
@ -19,11 +35,16 @@
$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 () {
@ -52,7 +73,8 @@
$scope.confirmNewUser = function () {
newEntry = {
"cn": $scope.newCn,
"sn": $scope.newSn
"sn": $scope.newSn,
"memberOf": $scope.newExtraGroups
};
$http.post('../user_backend/group/'+$scope.newGroup+'/create/'+$scope.newUid,
{
@ -67,7 +89,7 @@
} else {
$scope.createError = result.reason;
}
});
});
};
// Clear old user scope variable and start creating another
@ -77,6 +99,7 @@
delete $scope.newUid;
delete $scope.newCn;
delete $scope.newSn;
$scope.newExtraGroups = [];
$scope.startConfirm = false;
};


Loading…
Cancel
Save