From b5fdd66be94b8ec438db854a224ad8afa046dec3 Mon Sep 17 00:00:00 2001 From: houssine Date: Thu, 27 Jun 2019 20:41:45 +0200 Subject: [PATCH] [IMP] add fields on the create sign on form --- easy_my_coop/__openerp__.py | 4 +- easy_my_coop/controllers/AuthSignupHome.py | 89 ++++++++++++++++++++++ easy_my_coop/controllers/__init__.py | 1 + easy_my_coop/view/auth_signup_template.xml | 48 ++++++++++++ 4 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 easy_my_coop/controllers/AuthSignupHome.py create mode 100644 easy_my_coop/view/auth_signup_template.xml diff --git a/easy_my_coop/__openerp__.py b/easy_my_coop/__openerp__.py index 5447350..07cd752 100644 --- a/easy_my_coop/__openerp__.py +++ b/easy_my_coop/__openerp__.py @@ -20,8 +20,9 @@ ############################################################################## { "name": "Easy My Coop", - "version": "9.0.1.3.1", + "version": "9.1.0.0.1", "depends": ["base", + 'auth_signup', "sale", "purchase", "account_accountant", @@ -56,6 +57,7 @@ 'view/cooperator_register_view.xml', 'view/operation_request_view.xml', 'view/account_invoice_view.xml', + 'view/auth_signup_template.xml', 'view/subscription_template.xml', 'view/product_view.xml', 'view/res_company_view.xml', diff --git a/easy_my_coop/controllers/AuthSignupHome.py b/easy_my_coop/controllers/AuthSignupHome.py new file mode 100644 index 0000000..ed448f6 --- /dev/null +++ b/easy_my_coop/controllers/AuthSignupHome.py @@ -0,0 +1,89 @@ +# -*- coding: utf-8 -*- +# © 2019 Coop IT Easy (http://www.coopiteasy.be) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import logging +from openerp import tools +from openerp.tools.translate import _ + +from openerp import http +from openerp.http import request +from openerp.addons.auth_signup.res_users import SignupError +from openerp.addons.auth_signup.controllers.main import AuthSignupHome +from openerp.addons.base_iban import base_iban +from openerp.exceptions import ValidationError + +_logger = logging.getLogger(__name__) + +FORM_FIELDS = ['login', 'name', 'password', 'phone', 'street', + 'city', 'zip_code', 'country_id'] + + +class AuthSignupHome(AuthSignupHome): + def _signup_with_values(self, token, values): + user_obj = request.env['res.users'] + db, login, password = user_obj.sudo().signup(values, token) + # as authenticate will use its own cursor we need to commit + # the current transaction + request.cr.commit() + uid = request.session.authenticate(db, login, password) + if not uid: + raise SignupError(_('Authentication Failed.')) + return uid + + def do_signup(self, qcontext): + """ Shared helper that creates a res.partner out of a token """ + bank_obj = request.env['res.partner.bank'] + lang_obj = request.env['res.lang'] + + values = dict((key, qcontext.get(key)) for key in FORM_FIELDS) + assert any([k for k in values.values()]),"The form was not properly filled in." + assert values.get('password') == qcontext.get('confirm_password'), "Passwords do not match; please retype them." + supported_langs = [lang['code'] for lang + in lang_obj.sudo().search_read([], ['code'])] + if request.lang in supported_langs: + values['lang'] = request.lang + values['zip'] = values['zip_code'] + uid = self._signup_with_values(qcontext.get('token'), values) + iban = qcontext.get('iban') + user = request.env['res.users'].sudo().search([('id', '=', uid)]) + bank_obj.sudo().create({'partner_id': user.partner_id.id, + 'acc_number': iban}) + request.cr.commit() + + @http.route('/web/signup', type='http', auth='public', website=True) + def web_auth_signup(self, *args, **kw): + qcontext = self.get_auth_signup_qcontext() + users_obj = request.env["res.users"] + country_obj = request.env['res.country'] + + if qcontext.get("login", False) and not tools.single_email_re.match(qcontext.get("login", "")): + qcontext["error"] = _("That does not seem to be an email address.") + if qcontext.get("iban", False): + try: + base_iban.validate_iban(qcontext.get("iban")) + except ValidationError: + qcontext["error"] = _("Please give a correct IBAN number.") + if not qcontext.get('token') and not qcontext.get('signup_enabled'): + raise werkzeug.exceptions.NotFound() + + if 'error' not in qcontext and request.httprequest.method == 'POST': + try: + self.do_signup(qcontext) + return super(AuthSignupHome, self).web_login(*args, **kw) + except (SignupError, AssertionError), e: + domain = [("login", "=", qcontext.get("login"))] + if users_obj.sudo().search(domain): + qcontext["error"] = _("Another user is already registered " + "using this email address.") + else: + _logger.error(e.message) + qcontext['error'] = _("Could not create a new account.") + if not qcontext.get('raliment_point_id', False): + qcontext['raliment_point_id'] = 0 + if not qcontext.get('delivery_point_id', False): + qcontext['delivery_point_id'] = 0 + qcontext['countries'] = country_obj.sudo().search([]) + qcontext['country_id'] = '21' + + return request.render('auth_signup.signup', qcontext) diff --git a/easy_my_coop/controllers/__init__.py b/easy_my_coop/controllers/__init__.py index 12a7e52..e37faca 100644 --- a/easy_my_coop/controllers/__init__.py +++ b/easy_my_coop/controllers/__init__.py @@ -1 +1,2 @@ from . import main +from . import AuthSignupHome diff --git a/easy_my_coop/view/auth_signup_template.xml b/easy_my_coop/view/auth_signup_template.xml new file mode 100644 index 0000000..f949ce0 --- /dev/null +++ b/easy_my_coop/view/auth_signup_template.xml @@ -0,0 +1,48 @@ + + + + + + \ No newline at end of file