mirror of
https://github.com/kakwa/ldapcherry
synced 2024-12-22 21:00:04 +01:00
prefixing all form attributes to differenciate between types
This commit is contained in:
parent
314e0fc02b
commit
117d18bc92
@ -362,7 +362,17 @@ class LdapCherry(object):
|
||||
ret[attrid] = tmp[attr]
|
||||
return ret
|
||||
|
||||
|
||||
def _parse_params(self, params):
|
||||
ret = {'attrs': {}, 'roles': {}, 'groups': {}}
|
||||
for p in params:
|
||||
p_type, sep, param = p.partition('.')
|
||||
if p_type == 'attr':
|
||||
ret['attrs'][param] = params[p]
|
||||
elif p_type == 'role':
|
||||
ret['roles'][param] = params[p]
|
||||
elif p_type == 'group':
|
||||
ret['groups'][param] = params[p]
|
||||
return ret
|
||||
|
||||
def _check_admin(self):
|
||||
if self.auth_mode == 'none':
|
||||
@ -391,25 +401,26 @@ class LdapCherry(object):
|
||||
raise cherrypy.HTTPRedirect("/signin")
|
||||
|
||||
def _adduser(self, params):
|
||||
params = self._parse_params(params)
|
||||
badd = {}
|
||||
for attr in self.attributes.get_attributes():
|
||||
if self.attributes.attributes[attr]['type'] == 'password':
|
||||
pwd1 = attr + '1'
|
||||
pwd2 = attr + '2'
|
||||
if params[pwd1] != params[pwd2]:
|
||||
if params['attrs'][pwd1] != params['attrs'][pwd2]:
|
||||
raise Exception()
|
||||
params[attr] = params[pwd1]
|
||||
if attr in params:
|
||||
params['attrs'][attr] = params['attrs'][pwd1]
|
||||
if attr in params['attrs']:
|
||||
backends = self.attributes.get_backends_attributes(attr)
|
||||
for b in backends:
|
||||
if not b in badd:
|
||||
badd[b] = {}
|
||||
badd[b][backends[b]] = params[attr]
|
||||
badd[b][backends[b]] = params['attrs'][attr]
|
||||
for b in badd:
|
||||
self.backends[b].add_user(badd[b])
|
||||
|
||||
key = self.attributes.get_key()
|
||||
username = params[key]
|
||||
username = params['attrs'][key]
|
||||
sess = cherrypy.session
|
||||
admin = str(sess.get(SESSION_KEY, None))
|
||||
|
||||
@ -425,7 +436,7 @@ class LdapCherry(object):
|
||||
|
||||
roles = []
|
||||
for r in self.roles.get_allroles():
|
||||
if r in params:
|
||||
if r in params['roles']:
|
||||
roles.append(r)
|
||||
groups = self.roles.get_groups(roles)
|
||||
for b in groups:
|
||||
@ -442,6 +453,7 @@ class LdapCherry(object):
|
||||
)
|
||||
|
||||
def _modify(self, params):
|
||||
params = self._parse_params(params)
|
||||
pass
|
||||
|
||||
def _deleteuser(self, username):
|
||||
|
@ -37,25 +37,25 @@ for a in sorted(attributes.keys(), key=lambda attr: attributes[attr]['weight']):
|
||||
|
||||
<span class="input-group-addon" id="basic-addon1">${attr['display_name']}</span>
|
||||
% if attr['type'] == 'string':
|
||||
<input type="text" name="${a}" class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon1" ${required} ${value}>
|
||||
<input type="text" name="attr.${a}" class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon1" ${required} ${value}>
|
||||
% elif attr['type'] == 'email':
|
||||
<input type="email" name="${a}" class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon1" ${required} ${value} data-error="email address is invalid">
|
||||
<input type="email" name="attr.${a}" class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon1" ${required} ${value} data-error="email address is invalid">
|
||||
% elif attr['type'] == 'int':
|
||||
<input type="number" name="${a}" class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon1" ${required} ${value}>
|
||||
<input type="number" name="attr.${a}" class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon1" ${required} ${value}>
|
||||
% elif attr['type'] == 'fix':
|
||||
<input type="hidden" name="${a}" class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon1" ${required} value="${attr['value']}">
|
||||
<input type="hidden" name="attr.${a}" class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon1" ${required} value="${attr['value']}">
|
||||
<span class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon1">${attr['value']}</span>
|
||||
% elif attr['type'] == 'stringlist':
|
||||
<select class="form-control" name="${a}">
|
||||
<select class="form-control" name="attr.${a}">
|
||||
${value2}
|
||||
%for val in attr['values']:
|
||||
<option>${val}</option>
|
||||
%endfor
|
||||
</select>
|
||||
% elif attr['type'] == 'password':
|
||||
<input type="password" class="form-control" name="${a}1" id="${a}1" placeholder="${attr['description']}" ${required}>
|
||||
<input type="password" class="form-control" name="attr.${a}1" id="${a}1" placeholder="${attr['description']}" ${required}>
|
||||
<span class="input-group-addon" id="basic-addon1">Retype ${attr['display_name']}</span>
|
||||
<input type="password" class="form-control" name="${a}2" id="#${a}2" data-match="#${a}1" placeholder="Confirm" ${required}>
|
||||
<input type="password" class="form-control" name="attr.${a}2" id="#${a}2" data-match="#${a}1" placeholder="Confirm" ${required}>
|
||||
% endif
|
||||
</div>
|
||||
</div>
|
||||
|
@ -39,8 +39,8 @@
|
||||
<td>
|
||||
<input data-on-color="success" data-off-color="danger" data-on-text="Enabled"
|
||||
data-off-text="Disabled" data-handle-width="75" type="checkbox"
|
||||
name="${group}" data-size="mini" id="${group}" checked>
|
||||
<script>$("[name='${group}']").bootstrapSwitch();</script>
|
||||
name="group.${backend}.${group}" data-size="mini" id="group.${backend}.${group}" checked>
|
||||
<script>$("[name='group.${backend}.${group}']").bootstrapSwitch();</script>
|
||||
</td>
|
||||
</tr>
|
||||
% endfor
|
||||
|
@ -8,15 +8,14 @@
|
||||
for (var i = 0; i < len; i++) {
|
||||
var role = parentRoles[i];
|
||||
var DnParentRole = roles[role];
|
||||
var checked = document.getElementById(role).checked;
|
||||
$('input[name=' + role +']').bootstrapSwitch('state', true, true);
|
||||
var checked = document.getElementById('role.'+ role).checked;
|
||||
$('input[name="role.' + role +'"]').bootstrapSwitch('state', true, true);
|
||||
if ( ! checked){
|
||||
$.notify("Enable Role '" + DnParentRole + "' (Parent Role of '" + DnRole +"')",
|
||||
{
|
||||
type: 'info',
|
||||
delay: 6500,
|
||||
}
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -28,8 +27,8 @@
|
||||
for (var i = 0; i < len; i++) {
|
||||
var role = parentRoles[i];
|
||||
var DnParentRole = roles[role];
|
||||
var checked = document.getElementById(role).checked;
|
||||
$('input[name=' + role +']').bootstrapSwitch('state', false, true);
|
||||
var checked = document.getElementById('role.'+role).checked;
|
||||
$('input[name="role.' + role +'"]').bootstrapSwitch('state', false, true);
|
||||
if (checked){
|
||||
$.notify("Disable Role '" + DnParentRole + "' (Sub Role of '" + DnRole +"')",
|
||||
{
|
||||
@ -86,9 +85,9 @@
|
||||
<td>
|
||||
<input data-on-color="success" data-off-color="danger" data-on-text="Enabled"
|
||||
data-off-text="Disabled" data-handle-width="75" type="checkbox"
|
||||
name="${role}" data-size="mini" id="${role}" ${checked}>
|
||||
<script>$("[name='${role}']").bootstrapSwitch();
|
||||
$('input[name="${role}"]').on('switchChange.bootstrapSwitch', function(event, state) {
|
||||
name="role.${role}" data-size="mini" id="role.${role}" ${checked}>
|
||||
<script>$("[name='role.${role}']").bootstrapSwitch();
|
||||
$('input[name="role.${role}"]').on('switchChange.bootstrapSwitch', function(event, state) {
|
||||
if (state) {
|
||||
enableParentRoles('${role}');
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user