Commit acbea875 authored by RyanHerb's avatar RyanHerb

user* add user edit form

closes #1179
parent d87e9da0
import gluon.contrib.simplejson
import re
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
ACCESS_DENIED = 'access denied'
## return user list
def index():
......@@ -52,6 +55,42 @@ def index():
return dict(query=query,
reverse=reverse)
def edit():
if auth.is_admin():
user = db.auth_user[request.vars["id"]]
return dict(message=T("Edit user"), user=user)
return error_message(ACCESS_DENIED)
def edit_form():
if auth.is_admin():
error = ""
if request.vars["first_name"] == "" :
error += "first name needed, "
if request.vars["last_name"] == "" :
error += "last name needed, "
if request.vars["email"] == "":
error += "email cannot be empty"
elif not re.match(r"[^@]+@[^@]+\.[^@]+", request.vars["email"]):
error += "incorrect email format"
if error == "":
db.auth_user[request.vars['id']] = dict(first_name = request.vars["first_name"],
last_name = request.vars["last_name"],
email = request.vars["email"])
res = {"redirect": "back",
"message": "%s (%s) user edited" % (request.vars["email"], request.vars["id"])}
log.info(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else :
res = {"success" : "false", "message" : error}
log.error(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else :
res = {"message": ACCESS_DENIED}
log.error(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
## return user information
## need ["id"]
def info():
......
......@@ -18,6 +18,7 @@
{{if not reverse and request.vars["sort"]=="patients" :}} , 'reverse' : true {{pass}} })">patients created </td>
<td class="column_100" onclick="db.call('user/index', {'sort' :'files'
{{if not reverse and request.vars["sort"]=="files" :}} , 'reverse' : true {{pass}} })">files uploaded </td>
<td class="column5"> </td>
</tr>
</thead>
......@@ -32,6 +33,7 @@
<td> {{=row.last_login}} </td>
<td> {{=row.created}} </td>
<td> {{=row.files}} ({{=vidjil_utils.format_size(row.size)}}) </td>
<td onclick="db.call('user/edit', {'id' :'{{=row.id}}'} )" > <i class="icon-pencil-2" title="edit user information"></i> </td>
</tr>
{{pass}}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment