Commit ec32762f authored by Mikaël Salson's avatar Mikaël Salson Committed by Mathieu Giraud

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

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