mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-25 10:44:30 +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]
|
ret[attrid] = tmp[attr]
|
||||||
return ret
|
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):
|
def _check_admin(self):
|
||||||
if self.auth_mode == 'none':
|
if self.auth_mode == 'none':
|
||||||
@ -391,25 +401,26 @@ class LdapCherry(object):
|
|||||||
raise cherrypy.HTTPRedirect("/signin")
|
raise cherrypy.HTTPRedirect("/signin")
|
||||||
|
|
||||||
def _adduser(self, params):
|
def _adduser(self, params):
|
||||||
|
params = self._parse_params(params)
|
||||||
badd = {}
|
badd = {}
|
||||||
for attr in self.attributes.get_attributes():
|
for attr in self.attributes.get_attributes():
|
||||||
if self.attributes.attributes[attr]['type'] == 'password':
|
if self.attributes.attributes[attr]['type'] == 'password':
|
||||||
pwd1 = attr + '1'
|
pwd1 = attr + '1'
|
||||||
pwd2 = attr + '2'
|
pwd2 = attr + '2'
|
||||||
if params[pwd1] != params[pwd2]:
|
if params['attrs'][pwd1] != params['attrs'][pwd2]:
|
||||||
raise Exception()
|
raise Exception()
|
||||||
params[attr] = params[pwd1]
|
params['attrs'][attr] = params['attrs'][pwd1]
|
||||||
if attr in params:
|
if attr in params['attrs']:
|
||||||
backends = self.attributes.get_backends_attributes(attr)
|
backends = self.attributes.get_backends_attributes(attr)
|
||||||
for b in backends:
|
for b in backends:
|
||||||
if not b in badd:
|
if not b in badd:
|
||||||
badd[b] = {}
|
badd[b] = {}
|
||||||
badd[b][backends[b]] = params[attr]
|
badd[b][backends[b]] = params['attrs'][attr]
|
||||||
for b in badd:
|
for b in badd:
|
||||||
self.backends[b].add_user(badd[b])
|
self.backends[b].add_user(badd[b])
|
||||||
|
|
||||||
key = self.attributes.get_key()
|
key = self.attributes.get_key()
|
||||||
username = params[key]
|
username = params['attrs'][key]
|
||||||
sess = cherrypy.session
|
sess = cherrypy.session
|
||||||
admin = str(sess.get(SESSION_KEY, None))
|
admin = str(sess.get(SESSION_KEY, None))
|
||||||
|
|
||||||
@ -425,7 +436,7 @@ class LdapCherry(object):
|
|||||||
|
|
||||||
roles = []
|
roles = []
|
||||||
for r in self.roles.get_allroles():
|
for r in self.roles.get_allroles():
|
||||||
if r in params:
|
if r in params['roles']:
|
||||||
roles.append(r)
|
roles.append(r)
|
||||||
groups = self.roles.get_groups(roles)
|
groups = self.roles.get_groups(roles)
|
||||||
for b in groups:
|
for b in groups:
|
||||||
@ -442,6 +453,7 @@ class LdapCherry(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def _modify(self, params):
|
def _modify(self, params):
|
||||||
|
params = self._parse_params(params)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _deleteuser(self, username):
|
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>
|
<span class="input-group-addon" id="basic-addon1">${attr['display_name']}</span>
|
||||||
% if attr['type'] == 'string':
|
% 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':
|
% 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':
|
% 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':
|
% 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>
|
<span class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon1">${attr['value']}</span>
|
||||||
% elif attr['type'] == 'stringlist':
|
% elif attr['type'] == 'stringlist':
|
||||||
<select class="form-control" name="${a}">
|
<select class="form-control" name="attr.${a}">
|
||||||
${value2}
|
${value2}
|
||||||
%for val in attr['values']:
|
%for val in attr['values']:
|
||||||
<option>${val}</option>
|
<option>${val}</option>
|
||||||
%endfor
|
%endfor
|
||||||
</select>
|
</select>
|
||||||
% elif attr['type'] == 'password':
|
% 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>
|
<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
|
% endif
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -39,8 +39,8 @@
|
|||||||
<td>
|
<td>
|
||||||
<input data-on-color="success" data-off-color="danger" data-on-text="Enabled"
|
<input data-on-color="success" data-off-color="danger" data-on-text="Enabled"
|
||||||
data-off-text="Disabled" data-handle-width="75" type="checkbox"
|
data-off-text="Disabled" data-handle-width="75" type="checkbox"
|
||||||
name="${group}" data-size="mini" id="${group}" checked>
|
name="group.${backend}.${group}" data-size="mini" id="group.${backend}.${group}" checked>
|
||||||
<script>$("[name='${group}']").bootstrapSwitch();</script>
|
<script>$("[name='group.${backend}.${group}']").bootstrapSwitch();</script>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
% endfor
|
% endfor
|
||||||
|
@ -8,15 +8,14 @@
|
|||||||
for (var i = 0; i < len; i++) {
|
for (var i = 0; i < len; i++) {
|
||||||
var role = parentRoles[i];
|
var role = parentRoles[i];
|
||||||
var DnParentRole = roles[role];
|
var DnParentRole = roles[role];
|
||||||
var checked = document.getElementById(role).checked;
|
var checked = document.getElementById('role.'+ role).checked;
|
||||||
$('input[name=' + role +']').bootstrapSwitch('state', true, true);
|
$('input[name="role.' + role +'"]').bootstrapSwitch('state', true, true);
|
||||||
if ( ! checked){
|
if ( ! checked){
|
||||||
$.notify("Enable Role '" + DnParentRole + "' (Parent Role of '" + DnRole +"')",
|
$.notify("Enable Role '" + DnParentRole + "' (Parent Role of '" + DnRole +"')",
|
||||||
{
|
{
|
||||||
type: 'info',
|
type: 'info',
|
||||||
delay: 6500,
|
delay: 6500,
|
||||||
}
|
}
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -28,8 +27,8 @@
|
|||||||
for (var i = 0; i < len; i++) {
|
for (var i = 0; i < len; i++) {
|
||||||
var role = parentRoles[i];
|
var role = parentRoles[i];
|
||||||
var DnParentRole = roles[role];
|
var DnParentRole = roles[role];
|
||||||
var checked = document.getElementById(role).checked;
|
var checked = document.getElementById('role.'+role).checked;
|
||||||
$('input[name=' + role +']').bootstrapSwitch('state', false, true);
|
$('input[name="role.' + role +'"]').bootstrapSwitch('state', false, true);
|
||||||
if (checked){
|
if (checked){
|
||||||
$.notify("Disable Role '" + DnParentRole + "' (Sub Role of '" + DnRole +"')",
|
$.notify("Disable Role '" + DnParentRole + "' (Sub Role of '" + DnRole +"')",
|
||||||
{
|
{
|
||||||
@ -86,9 +85,9 @@
|
|||||||
<td>
|
<td>
|
||||||
<input data-on-color="success" data-off-color="danger" data-on-text="Enabled"
|
<input data-on-color="success" data-off-color="danger" data-on-text="Enabled"
|
||||||
data-off-text="Disabled" data-handle-width="75" type="checkbox"
|
data-off-text="Disabled" data-handle-width="75" type="checkbox"
|
||||||
name="${role}" data-size="mini" id="${role}" ${checked}>
|
name="role.${role}" data-size="mini" id="role.${role}" ${checked}>
|
||||||
<script>$("[name='${role}']").bootstrapSwitch();
|
<script>$("[name='role.${role}']").bootstrapSwitch();
|
||||||
$('input[name="${role}"]').on('switchChange.bootstrapSwitch', function(event, state) {
|
$('input[name="role.${role}"]').on('switchChange.bootstrapSwitch', function(event, state) {
|
||||||
if (state) {
|
if (state) {
|
||||||
enableParentRoles('${role}');
|
enableParentRoles('${role}');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user