You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2015 Antiun Ingeniería, S.L.
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. import logging
  5. from openerp import _, http
  6. from openerp.addons.auth_signup.controllers.main import AuthSignupHome
  7. _logger = logging.getLogger(__name__)
  8. try:
  9. from validate_email import validate_email
  10. except ImportError:
  11. _logger.debug("Cannot import `validate_email`.")
  12. class SignupVerifyEmail(AuthSignupHome):
  13. @http.route()
  14. def web_auth_signup(self, *args, **kw):
  15. if (http.request.params.get("login") and
  16. not http.request.params.get("password")):
  17. return self.passwordless_signup(http.request.params)
  18. else:
  19. return super(SignupVerifyEmail, self).web_auth_signup(*args, **kw)
  20. def passwordless_signup(self, values):
  21. qcontext = self.get_auth_signup_qcontext()
  22. # Check good format of e-mail
  23. if not validate_email(values.get("login", "")):
  24. qcontext["error"] = _("That does not seem to be an email address.")
  25. return http.request.render("auth_signup.signup", qcontext)
  26. elif not values.get("email"):
  27. values["email"] = values.get("login")
  28. # Remove password
  29. values["password"] = False
  30. sudo_users = (http.request.env["res.users"]
  31. .with_context(create_user=True).sudo())
  32. try:
  33. sudo_users.signup(values, qcontext.get("token"))
  34. sudo_users.reset_password(values.get("login"))
  35. except Exception as error:
  36. # Duplicate key or wrong SMTP settings, probably
  37. _logger.exception(error)
  38. http.request.env.cr.rollback()
  39. # Agnostic message for security
  40. qcontext["error"] = _(
  41. "Something went wrong, please try again later or contact us.")
  42. return http.request.render("auth_signup.signup", qcontext)
  43. qcontext["message"] = _("Check your email to activate your account!")
  44. return http.request.render("auth_signup.reset_password", qcontext)