Skip to content

Commit

Permalink
[MIG][11] auth_signup_verify_email
Browse files Browse the repository at this point in the history
  • Loading branch information
simahawk authored and em230418 committed May 15, 2020
1 parent 562fddf commit 946ca3b
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 45 deletions.
18 changes: 8 additions & 10 deletions auth_signup_verify_email/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
Verify email at signup
======================

This module extends the functionality of public sign up, and forces users to
This module extends the functionality of public sign up to force users to
provide a valid email address.

To achieve this requirement, the user does not need to provide a password at
sign up, but when logging in later for the first time.
To achieve this, users are not required to provide a password at
sign up: they are asked for only at first login attempt.

Installation
============

* Install validate_email_ with ``pip install validate_email`` or equivalent.
* Install `validate_email <https://pypi.python.org/pypi/validate_email>`_ with ``pip install validate_email`` or equivalent.

Configuration
=============
Expand All @@ -24,8 +24,7 @@ To configure this module, you need to:

* `Properly configure your outgoing email server(s)
<https://www.odoo.com/es_ES/forum/help-1/question/how-to-configure-email-gateway-282#answer_290>`_.
* Go to *Settings > General Settings* and enable *Allow
external users to sign up*.
* Go to *Settings > General Settings -> General settings*, search for the *Users* section and enable *Free sign up* in *Customer account*.

Usage
=====
Expand All @@ -37,7 +36,7 @@ To use this module, you need to:

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/149/9.0
:target: https://runbot.odoo-community.org/runbot/149/11.0

Known issues / Roadmap
======================
Expand All @@ -51,7 +50,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
help us smash it by providing detailed and welcomed feedback.


Credits
Expand All @@ -68,6 +67,7 @@ Contributors

* Rafael Blasco <rafaelbn@antiun.com>
* Jairo Llopis <yajo.sk8@gmail.com>
* Simone Orsi <simone.orsi@camptocamp.com>

Maintainer
----------
Expand All @@ -83,5 +83,3 @@ mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.

.. _validate_email: https://pypi.python.org/pypi/validate_email
3 changes: 1 addition & 2 deletions auth_signup_verify_email/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# © 2015 Antiun Ingeniería, S.L.
# Copyright 2015 Antiun Ingeniería, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import controllers
16 changes: 7 additions & 9 deletions auth_signup_verify_email/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
# -*- coding: utf-8 -*-
# © 2015 Antiun Ingeniería, S.L.
# Copyright 2015 Antiun Ingeniería, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Verify email at signup",
"summary": "Force uninvited users to use a good email for signup",
"version": "10.0.1.0.0",
"version": "11.0.1.0.0",
"category": "Authentication",
"website": "http://www.tecnativa.com",
"website": "https://github.com/OCA/server-auth",
"author": "Antiun Ingeniería S.L., "
"Tecnativa, "
"Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
'installable': True,
"depends": [
"auth_signup",
],
"external_dependencies": {
"python": [
"lxml",
"validate_email",
],
},
"depends": [
"auth_signup",
],
"data": [
"views/signup.xml",
],
'installable': True,
}
3 changes: 1 addition & 2 deletions auth_signup_verify_email/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# © 2015 Antiun Ingeniería, S.L.
# Copyright 2015 Antiun Ingeniería, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import main
24 changes: 14 additions & 10 deletions auth_signup_verify_email/controllers/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
# © 2015 Antiun Ingeniería, S.L.
# Copyright 2015 Antiun Ingeniería, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
from odoo import _, http
from odoo.http import request
from odoo.addons.auth_signup.controllers.main import AuthSignupHome

_logger = logging.getLogger(__name__)
Expand All @@ -15,11 +15,12 @@


class SignupVerifyEmail(AuthSignupHome):

@http.route()
def web_auth_signup(self, *args, **kw):
if (http.request.params.get("login") and
not http.request.params.get("password")):
return self.passwordless_signup(http.request.params)
if (request.params.get("login") and
not request.params.get("password")):
return self.passwordless_signup(request.params)
else:
return super(SignupVerifyEmail, self).web_auth_signup(*args, **kw)

Expand All @@ -29,17 +30,20 @@ def passwordless_signup(self, values):
# Check good format of e-mail
if not validate_email(values.get("login", "")):
qcontext["error"] = _("That does not seem to be an email address.")
return http.request.render("auth_signup.signup", qcontext)
return request.render("auth_signup.signup", qcontext)
elif not values.get("email"):
values["email"] = values.get("login")

# preserve user lang
values['lang'] = request.lang

# Remove password
values["password"] = ""
sudo_users = (http.request.env["res.users"]
sudo_users = (request.env["res.users"]
.with_context(create_user=True).sudo())

try:
with http.request.cr.savepoint():
with request.cr.savepoint():
sudo_users.signup(values, qcontext.get("token"))
sudo_users.reset_password(values.get("login"))
except Exception as error:
Expand All @@ -49,7 +53,7 @@ def passwordless_signup(self, values):
# Agnostic message for security
qcontext["error"] = _(
"Something went wrong, please try again later or contact us.")
return http.request.render("auth_signup.signup", qcontext)
return request.render("auth_signup.signup", qcontext)

qcontext["message"] = _("Check your email to activate your account!")
return http.request.render("auth_signup.reset_password", qcontext)
return request.render("auth_signup.reset_password", qcontext)
2 changes: 1 addition & 1 deletion auth_signup_verify_email/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import test_verify_email
15 changes: 7 additions & 8 deletions auth_signup_verify_email/tests/test_verify_email.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from urllib import urlencode
from lxml.html import document_fromstring
from openerp import _
from openerp.tests.common import HttpCase
from odoo import _
from odoo.tests.common import HttpCase
from odoo.tools.misc import mute_logger


class UICase(HttpCase):
Expand Down Expand Up @@ -39,9 +38,8 @@ def tearDown(self):

def html_doc(self, url="/web/signup", data=None, timeout=10):
"""Get an HTML LXML document."""
if data:
data = bytes(urlencode(data))
return document_fromstring(self.url_open(url, data, timeout).read())
resp = self.url_open(url, data=data, timeout=timeout)
return document_fromstring(resp.content)

def csrf_token(self):
"""Get a valid CSRF token."""
Expand All @@ -58,6 +56,7 @@ def test_bad_email(self):
doc = self.html_doc(data=self.data)
self.assertTrue(self.search_text(doc, self.msg["badmail"]))

@mute_logger('odoo.addons.auth_signup_verify_email.controllers.main')
def test_good_email(self):
"""Test acceptance of good emails.
Expand Down
6 changes: 3 additions & 3 deletions auth_signup_verify_email/views/signup.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
<!-- Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>

<template id="signup_fields" inherit_id="auth_signup.fields">
<xpath expr="//div[@class='form-group field-password']"
<xpath expr="//div[hasclass('field-password')]"
position="attributes">
<attribute name="t-if">only_passwords</attribute>
</xpath>
<xpath expr="//div[@class='form-group field-confirm_password']"
<xpath expr="//div[hasclass('field-confirm_password')]"
position="attributes">
<attribute name="t-if">only_passwords</attribute>
</xpath>
Expand Down

0 comments on commit 946ca3b

Please sign in to comment.