Commit de70e395 authored by Mikaël Salson's avatar Mikaël Salson Committed by Mathieu Giraud
Browse files

controllers/user.py: edit_form: errors as a list

This is more flexible to add new errors.
parent 34046837
Pipeline #96769 passed with stages
in 6 minutes and 37 seconds
...@@ -66,23 +66,23 @@ def edit(): ...@@ -66,23 +66,23 @@ def edit():
def edit_form(): def edit_form():
if auth.can_modify_user(int(request.vars['id'])): if auth.can_modify_user(int(request.vars['id'])):
error = "" error = []
if request.vars["first_name"] == "" : if request.vars["first_name"] == "" :
error += "first name needed, " error.append("first name needed")
if request.vars["last_name"] == "" : if request.vars["last_name"] == "" :
error += "last name needed, " error.append("last name needed")
if request.vars["email"] == "": if request.vars["email"] == "":
error += "email cannot be empty" error.append("email cannot be empty")
elif not re.match(r"[^@]+@[^@]+\.[^@]+", request.vars["email"]): elif not re.match(r"[^@]+@[^@]+\.[^@]+", request.vars["email"]):
error += "incorrect email format" error.append("incorrect email format")
if request.vars["password"] != "": if request.vars["password"] != "":
if request.vars["confirm_password"] != request.vars["password"]: if request.vars["confirm_password"] != request.vars["password"]:
error += "password fields must match" error.append("password fields must match")
else: else:
password = db.auth_user.password.validate(request.vars["password"])[0] password = db.auth_user.password.validate(request.vars["password"])[0]
if error == "": if len(error) == 0:
data = dict(first_name = request.vars["first_name"], data = dict(first_name = request.vars["first_name"],
last_name = request.vars["last_name"], last_name = request.vars["last_name"],
email = request.vars["email"]) email = request.vars["email"])
...@@ -98,7 +98,7 @@ def edit_form(): ...@@ -98,7 +98,7 @@ def edit_form():
return gluon.contrib.simplejson.dumps(res, separators=(',',':')) return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else : else :
res = {"success" : "false", "message" : error} res = {"success" : "false", "message" : ', '.join(error)}
log.error(res) log.error(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':')) return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else : else :
......
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