*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects
Commit 16463f45 authored by Moser, Maximilian's avatar Moser, Maximilian
Browse files

Enable sending of registration mails

* enable sending of registration mails to give our users a warm welcome
  and a kickstart into the system's usage
* change some default configuration related to email sending
* also, rework the auto-confirmation of new accounts to use the new-ish
  mechanism provided by Invenio-OAuthClient
parent 978e053a
No related branches found
No related tags found
1 merge request!40Enable sending of registration mails
# -*- coding: utf-8 -*-
#
# Copyright (C) 2020 - 2021 TU Wien.
# Copyright (C) 2020-2023 TU Wien.
#
# Invenio-Config-TUW is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.
......@@ -14,6 +14,19 @@ from invenio_oauthclient.contrib.keycloak import KeycloakSettingsHelper
class TUWSSOSettingsHelper(KeycloakSettingsHelper):
"""KeycloakSettingsHelper, adjusted for the needs of TU Data."""
def __init__(
self, title, description, base_url, realm, app_key=None, icon=None, **kwargs
):
"""Constructor."""
signup_options = kwargs.get("signup_options", None) or {}
signup_options.setdefault("send_register_msg", True)
signup_options.setdefault("auto_confirm", True)
kwargs["signup_options"] = signup_options
super().__init__(
title, description, base_url, realm, app_key=None, icon=None, **kwargs
)
def get_handlers(self):
return {
"authorized_handler": "invenio_config_tuw.auth:authorized_signup_handler",
......
......@@ -171,7 +171,10 @@ def base_authorized_signup_handler(resp, remote, *args, **kwargs):
remote_apps = current_app.config["OAUTHCLIENT_REMOTE_APPS"]
precedence_mask = remote_apps[remote.name].get("precedence_mask")
user = oauth_register(form, account_info["user"], precedence_mask)
signup_options = remote_apps[remote.name].get("signup_options")
user = oauth_register(
form, account_info["user"], precedence_mask, signup_options
)
# if registration fails ...
if user is None:
......
# -*- coding: utf-8 -*-
#
# Copyright (C) 2020-2021 TU Wien.
# Copyright (C) 2020-2023 TU Wien.
#
# Invenio-Config-TUW is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.
......@@ -53,15 +53,26 @@ CONFIG_TUW_DISABLE_ERROR_MAILS = False
MAIL_SERVER = "localhost"
"""Domain ip where mail server is running."""
SECURITY_EMAIL_SENDER = "no-reply@researchdata.tuwien.ac.at"
SECURITY_EMAIL_SENDER = "no-reply@tuwien.ac.at"
"""Email address used as sender of account registration emails."""
SECURITY_EMAIL_SUBJECT_REGISTER = _("Welcome to TU Data!")
"""Email subject for account registration emails."""
MAIL_SUPPRESS_SEND = True
"""Disable email sending by default."""
SECURITY_SEND_REGISTER_EMAIL = True
"""Enable sending emails after user registration."""
SECURITY_EMAIL_SUBJECT_REGISTER = _("Welcome to TU Wien Research Data!")
"""Email subject for account registration emails."""
SECURITY_EMAIL_HTML = True
"""Send the HTML version of the email."""
# disable sending of emails related to local login
SECURITY_SEND_PASSWORD_CHANGE_EMAIL = False
SECURITY_SEND_PASSWORD_RESET_EMAIL = False
SECURITY_SEND_PASSWORD_RESET_NOTICE_EMAIL = False
# Invenio-Previewer
# =================
......
......@@ -16,21 +16,6 @@ from wtforms.fields.core import FormField
_security = LocalProxy(lambda: current_app.extensions["security"])
def calculate_confirmed_at():
"""Calculate the default value of ``confirmed_at``.
If the application is configured in a way that it doesn't send out confirmation
e-mails (``SECURITY_CONFIRMABLE=False``), then this will give back the
current UTC time to auto-confirm users' e-mail addresses.
Otherwise (confirmation is required), it will return ``None`` to mark that the
e-mail addresses still need confirmation.
"""
if not current_app.extensions["security"].confirmable:
return datetime.utcnow()
else:
return None
def tuw_registration_form(*args, **kwargs):
"""Create the registration form for TU Wien.
......@@ -71,7 +56,6 @@ def tuw_registration_form(*args, **kwargs):
username = HiddenField()
user_profile = FormField(UserProfileForm, separator=".")
preferences = FormField(UserPreferenceForm, separator=".")
confirmed_at = None
password = None
recaptcha = None
profile = None # disable the default 'profile' form from invenio
......@@ -84,7 +68,6 @@ def tuw_registration_form(*args, **kwargs):
"email": self.email.data,
"username": self.username.data,
"password": None,
"confirmed_at": calculate_confirmed_at(),
"user_profile": {
"full_name": self.user_profile.full_name.data,
"affiliations": self.user_profile.affiliations.data,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment