upload avatar
parent
92a5ebac2f
commit
e01267c49f
|
@ -72,6 +72,7 @@ admin_required = set()
|
|||
|
||||
default_field = (wtforms.fields.StringField, {})
|
||||
fields = {
|
||||
'jpegphoto': (wtforms.fields.FileField, {'validators': []}),
|
||||
'mobiletelephonenumber': (wtforms.fields.StringField, {'validators': [wtforms.validators.Regexp(r'[+0-9 ]+')]}),
|
||||
'telephonenumber': (wtforms.fields.StringField, {'validators': [wtforms.validators.Regexp(r'[+0-9 ]+')]}),
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
<div class="modal fade" tabindex="-1" role="dialog">
|
||||
<form action="/vcard/add/{{ attr_name }}" method="POST" class="form-signin">
|
||||
<form action="/vcard/add/{{ attr_name }}" method="POST" class="form-signin"
|
||||
{% if attr_name == 'jpegphoto' %}
|
||||
enctype="multipart/form-data"
|
||||
{% endif %}
|
||||
>
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
|
|
|
@ -47,12 +47,13 @@
|
|||
</div>
|
||||
<div>
|
||||
<h4>{{ name|readable }}</h4>
|
||||
{% if profile[name] %}
|
||||
{% with field = profile[name]|first %}
|
||||
{% set field = profile[name]|first %}
|
||||
{% if field and (field.value | length) %}
|
||||
{% if name in can_delete %}
|
||||
<a class="modalLink" href="/vcard/delete/{{ field.uid }}"><span class="glyphicon glyphicon-minus-sign" aria-hidden="true"></span> Remove</a>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% else %}
|
||||
<a class="modalLink" href="/vcard/add/{{ name }}"><span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span> Upload</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import ldap
|
||||
import flask
|
||||
import flask_wtf
|
||||
import io
|
||||
import base64
|
||||
|
||||
from webapp import app, context, config, validation
|
||||
from webapp.auth import login_required
|
||||
|
@ -46,10 +48,14 @@ def attr_op(op, attrName, uid = None, success_redirect='/vcard',
|
|||
if op == 'mod' and attrName not in ['commonname']:
|
||||
op = 'modreadd'
|
||||
|
||||
# Temporary workaround: deleting jpegPhoto doesn't work, set to empty instead
|
||||
if op == 'del' and attrName == 'jpegphoto':
|
||||
op = 'mod'
|
||||
new_value = ''
|
||||
if attrName == 'jpegphoto':
|
||||
# Temporary workaround: deleting jpegPhoto doesn't work, set to empty instead
|
||||
if op == 'del':
|
||||
op = 'mod'
|
||||
new_value = ''
|
||||
else:
|
||||
op = 'mod'
|
||||
new_value = base64.b64encode(new_value.read()).decode('utf-8')
|
||||
|
||||
if op in ['del', 'modreadd']:
|
||||
conn.modify_s(dn, [(ldap.MOD_DELETE, attrName, str_to_ldap(old_value))])
|
||||
|
|
Loading…
Reference in New Issue