[IMP] auth_signup: display meaningfull and translated error messages

Since 5425316eff errors when signing up will only display two
messages:

 * "Another user is already registered using this email address." or
 * "Could not create a new account."

While Odoo creates a multitude of other comprehensible error messages
such as

 * "Passwords do not match; please retype them."
 * "Signup token '%s' is no longer valid"

This commit now separate UserError and AssertionError from SignupErrors.
Those are still hidden in a general message (see 5425316eff for reasons) while
the other ones are fully displayed.

This commit also improves translations of messages.
This commit is contained in:
Denis Vermylen
2017-07-06 12:53:39 +02:00
committed by Thibault Delavallée
parent 689d6d6829
commit 676022e3af
4 changed files with 14 additions and 9 deletions
+2 -2
View File
@@ -6,7 +6,7 @@ import json
import requests
from odoo import api, fields, models
from odoo.exceptions import AccessDenied
from odoo.exceptions import AccessDenied, UserError
from odoo.addons.auth_signup.models.res_users import SignupError
from odoo.addons import base
@@ -82,7 +82,7 @@ class ResUsers(models.Model):
try:
_, login, _ = self.signup(values, token)
return login
except SignupError:
except (SignupError, UserError):
raise access_denied_exception
@api.model
+8 -3
View File
@@ -6,6 +6,7 @@ import werkzeug
from odoo import http, _
from odoo.addons.auth_signup.models.res_users import SignupError
from odoo.addons.web.controllers.main import ensure_db, Home
from odoo.exceptions import UserError
from odoo.http import request
from odoo.tools import pycompat
@@ -34,6 +35,8 @@ class AuthSignupHome(Home):
try:
self.do_signup(qcontext)
return super(AuthSignupHome, self).web_login(*args, **kw)
except UserError as e:
qcontext['error'] = str(e)
except (SignupError, AssertionError) as e:
if request.env["res.users"].sudo().search([("login", "=", qcontext.get("login"))]):
qcontext["error"] = _("Another user is already registered using this email address.")
@@ -57,7 +60,7 @@ class AuthSignupHome(Home):
return super(AuthSignupHome, self).web_login(*args, **kw)
else:
login = qcontext.get('login')
assert login, "No login provided."
assert login, _("No login provided.")
_logger.info(
"Password reset attempt for <%s> by user <%s> from %s",
login, request.env.user.login, request.httprequest.remote_addr)
@@ -100,8 +103,10 @@ class AuthSignupHome(Home):
def do_signup(self, qcontext):
""" Shared helper that creates a res.partner out of a token """
values = { key: qcontext.get(key) for key in ('login', 'name', 'password') }
assert values, "The form was not properly filled in."
assert values.get('password') == qcontext.get('confirm_password'), "Passwords do not match; please retype them."
if not values:
raise UserError(_("The form was not properly filled in."))
if values.get('password') != qcontext.get('confirm_password'):
raise UserError(_("Passwords do not match; please retype them."))
supported_langs = [lang['code'] for lang in request.env['res.lang'].sudo().search_read([], ['code'])]
if request.lang in supported_langs:
values['lang'] = request.lang
+3 -3
View File
@@ -6,7 +6,7 @@ import werkzeug.urls
from datetime import datetime, timedelta
from odoo import api, fields, models, _
from odoo import api, exceptions, fields, models, _
from odoo.tools import pycompat
@@ -125,11 +125,11 @@ class ResPartner(models.Model):
partner = self.search([('signup_token', '=', token)], limit=1)
if not partner:
if raise_exception:
raise SignupError("Signup token '%s' is not valid" % token)
raise exceptions.UserError(_("Signup token '%s' is not valid") % token)
return False
if check_validity and not partner.signup_valid:
if raise_exception:
raise SignupError("Signup token '%s' is no longer valid" % token)
raise exceptions.UserError(_("Signup token '%s' is no longer valid") % token)
return False
return partner
+1 -1
View File
@@ -85,7 +85,7 @@ class ResUsers(models.Model):
# check that uninvited users may sign up
if 'partner_id' not in values:
if not literal_eval(get_param('auth_signup.allow_uninvited', 'False')):
raise SignupError('Signup is not allowed for uninvited users')
raise SignupError(_('Signup is not allowed for uninvited users'))
assert values.get('login'), "Signup: no login given for new user"
assert values.get('partner_id') or values.get('name'), "Signup: no name or partner given for new user"