From 80ff10e1dc5b7ee2af796648db5fae1654b48cf6 Mon Sep 17 00:00:00 2001 From: "joel.clement" Date: Wed, 31 May 2023 14:28:59 +0200 Subject: [PATCH 1/6] register enhancement --- .../core/users/register_post_actions.py | 9 +++--- backend/geonature/core/users/routes.py | 23 ++++++++++++++- .../email_admin_validate_account.html | 4 +++ .../login/sign-up/sign-up.component.html | 3 ++ .../login/sign-up/sign-up.component.ts | 28 +++++++++++++------ 5 files changed, 54 insertions(+), 13 deletions(-) diff --git a/backend/geonature/core/users/register_post_actions.py b/backend/geonature/core/users/register_post_actions.py index 7889da92a7..0f8c8fa9e2 100644 --- a/backend/geonature/core/users/register_post_actions.py +++ b/backend/geonature/core/users/register_post_actions.py @@ -47,14 +47,15 @@ def validate_temp_user(data): recipients = [current_app.config["ACCOUNT_MANAGEMENT"]["VALIDATOR_EMAIL"]] url_validation = url_for("users.confirmation", token=user.token_role, _external=True) + additional_fields = [ + {"key": key, "value": value} for key, value in (user_dict.get("champs_addi") or {}).items() + ] + msg_html = render_template( template, url_validation=url_validation, user=user_dict, - additional_fields=[ - {"key": key, "value": value} - for key, value in (user_dict.get("champs_addi") or {}).items() - ], + additional_fields=additional_fields, ) send_mail(recipients, subject, msg_html) diff --git a/backend/geonature/core/users/routes.py b/backend/geonature/core/users/routes.py index 55d2fdece5..1194fede50 100644 --- a/backend/geonature/core/users/routes.py +++ b/backend/geonature/core/users/routes.py @@ -300,7 +300,28 @@ def confirmation(): if r.status_code != 200: return Response(r), r.status_code - return redirect(config["URL_APPLICATION"], code=302) + new_user = r.json() + + txt_champs_addi = "" + for key in new_user["champs_addi"]: + txt_champs_addi += ( + f"    - {key}: {new_user['champs_addi'][key]}
" + ) + + return ( + f"""Le compte suivant à bien été ajouté à l'application GeoNature
+
+ - Nom: {new_user['nom_role']}
+ - Prénom: {new_user['prenom_role']}
+ - Identifiant: {new_user['identifiant']}
+ - Email: {new_user['email']}
+ - Champs additionnels:
+ {txt_champs_addi} +
+ Retour à l'application GeoNature + """, + 200, + ) @routes.route("/after_confirmation", methods=["POST"]) diff --git a/backend/geonature/core/users/templates/email_admin_validate_account.html b/backend/geonature/core/users/templates/email_admin_validate_account.html index a92c44d413..7379afc5b2 100644 --- a/backend/geonature/core/users/templates/email_admin_validate_account.html +++ b/backend/geonature/core/users/templates/email_admin_validate_account.html @@ -10,6 +10,10 @@
  • Prénom : {{user.prenom_role}}
  • Identifiant : {{user.identifiant}}
  • Email : {{user.email}}
  • +{% if user.remarques %} +
  • Remarques : {{user.remarques}}
  • +{% endif%} + {% if additional_fields | length > 0 %} diff --git a/frontend/src/app/modules/login/sign-up/sign-up.component.html b/frontend/src/app/modules/login/sign-up/sign-up.component.html index ea6e1dd8c0..d3a38b78ed 100644 --- a/frontend/src/app/modules/login/sign-up/sign-up.component.html +++ b/frontend/src/app/modules/login/sign-up/sign-up.component.html @@ -214,6 +214,9 @@
    Informations complémentaires
    + + {{errorMsg}} + diff --git a/frontend/src/app/modules/login/sign-up/sign-up.component.ts b/frontend/src/app/modules/login/sign-up/sign-up.component.ts index b3674c79fb..c421b0478a 100644 --- a/frontend/src/app/modules/login/sign-up/sign-up.component.ts +++ b/frontend/src/app/modules/login/sign-up/sign-up.component.ts @@ -7,7 +7,6 @@ import { CommonService } from '@geonature_common/service/common.service'; import { AuthService } from '../../../components/auth/auth.service'; import { ConfigService } from '@geonature/services/config.service'; - @Component({ selector: 'pnx-signup', templateUrl: './sign-up.component.html', @@ -19,6 +18,7 @@ export class SignUpComponent implements OnInit { public disableSubmit = false; public formControlBuilded = false; public FORM_CONFIG = null; + public errorMsg = ''; constructor( private fb: UntypedFormBuilder, @@ -57,21 +57,33 @@ export class SignUpComponent implements OnInit { save() { if (this.form.valid) { + this.errorMsg = ''; // raz de l'erreur this.disableSubmit = true; const finalForm = Object.assign({}, this.form.value); // concatenate two forms + finalForm['champs_addi'] = {}; if (this.config.ACCOUNT_MANAGEMENT.ACCOUNT_FORM.length > 0) { finalForm['champs_addi'] = this.dynamicFormGroup.value; } + // ajout de organisme aux champs addi + finalForm['champs_addi']['organisme'] = this.form.value['organisme']; this._authService .signupUser(finalForm) - .subscribe(() => { - const callbackMessage = this.config.ACCOUNT_MANAGEMENT.AUTO_ACCOUNT_CREATION - ? 'AutoAccountEmailConfirmation' - : 'AdminAccountEmailConfirmation'; - this._commonService.translateToaster('info', callbackMessage); - this._router.navigate(['/login']); - }) + .subscribe( + () => { + const callbackMessage = this.config.ACCOUNT_MANAGEMENT.AUTO_ACCOUNT_CREATION + ? 'AutoAccountEmailConfirmation' + : 'AdminAccountEmailConfirmation'; + this._commonService.translateToaster('info', callbackMessage); + this._router.navigate(['/login']); + }, + (error) => { + // affichage de l'erreur renvoyé par l'api + if (error.error.msg) { + this.errorMsg = error.error.msg; + } + } + ) .add(() => { this.disableSubmit = false; }); From de3c8fe5b9bfeb86c49fac0e177217cbf24ee2b5 Mon Sep 17 00:00:00 2001 From: "joel.clement" Date: Wed, 31 May 2023 14:57:53 +0200 Subject: [PATCH 2/6] fix send mail to multiple validators ref #2389 --- .../core/users/register_post_actions.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/backend/geonature/core/users/register_post_actions.py b/backend/geonature/core/users/register_post_actions.py index 0f8c8fa9e2..5332bb2a9b 100644 --- a/backend/geonature/core/users/register_post_actions.py +++ b/backend/geonature/core/users/register_post_actions.py @@ -20,6 +20,15 @@ from geonature.utils.env import db, DB +def validators_emails(): + return ( + current_app.config["ACCOUNT_MANAGEMENT"]["VALIDATOR_EMAIL"] + .replace(" ", "") + .replace("\n", "") + .split(",") + ) + + def validate_temp_user(data): """ Send an email after the action of account creation. @@ -44,7 +53,7 @@ def validate_temp_user(data): recipients = [user.email] else: template = "email_admin_validate_account.html" - recipients = [current_app.config["ACCOUNT_MANAGEMENT"]["VALIDATOR_EMAIL"]] + recipients = validators_emails() url_validation = url_for("users.confirmation", token=user.token_role, _external=True) additional_fields = [ @@ -152,7 +161,11 @@ def inform_user(user): text_addon=html_text_addon, ) subject = f"Confirmation inscription {app_name}" - send_mail([user["email"]], subject, msg_html) + recipients = [user["email"]] + # dans le cas ou on a plusieurs validateurs et on veut prévenir tout le monde + # de la validation du compte ???????? + # recipients + validators_emails() + send_mail(recipients, subject, msg_html) def send_email_for_recovery(data): From 585767b34517cee20489adf0aa8c560968243672 Mon Sep 17 00:00:00 2001 From: "joel.clement" Date: Thu, 1 Jun 2023 12:16:39 +0200 Subject: [PATCH 3/6] error validation temp user return msg if exists --- backend/geonature/core/users/routes.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/geonature/core/users/routes.py b/backend/geonature/core/users/routes.py index 1194fede50..c952c511b5 100644 --- a/backend/geonature/core/users/routes.py +++ b/backend/geonature/core/users/routes.py @@ -298,6 +298,8 @@ def confirmation(): ) if r.status_code != 200: + if r.json() and r.json().get("msg"): + return r.json().get("msg"), r.status_code return Response(r), r.status_code new_user = r.json() From fc4365121fa2c387960a305b4b65b711f1988529 Mon Sep 17 00:00:00 2001 From: "joel.clement" Date: Mon, 12 Jun 2023 10:12:19 +0200 Subject: [PATCH 4/6] fix validators mails --- .../geonature/core/users/register_post_actions.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/backend/geonature/core/users/register_post_actions.py b/backend/geonature/core/users/register_post_actions.py index 5332bb2a9b..df0a8c477e 100644 --- a/backend/geonature/core/users/register_post_actions.py +++ b/backend/geonature/core/users/register_post_actions.py @@ -21,12 +21,11 @@ def validators_emails(): - return ( - current_app.config["ACCOUNT_MANAGEMENT"]["VALIDATOR_EMAIL"] - .replace(" ", "") - .replace("\n", "") - .split(",") - ) + """ + On souhaite récupérer une liste de mails + """ + emails = current_app.config["ACCOUNT_MANAGEMENT"]["VALIDATOR_EMAIL"] + return emails if isinstance(emails, list) else [emails] def validate_temp_user(data): @@ -162,9 +161,6 @@ def inform_user(user): ) subject = f"Confirmation inscription {app_name}" recipients = [user["email"]] - # dans le cas ou on a plusieurs validateurs et on veut prévenir tout le monde - # de la validation du compte ???????? - # recipients + validators_emails() send_mail(recipients, subject, msg_html) From afb79587c656434157ecfaeb593e4ab749e505a9 Mon Sep 17 00:00:00 2001 From: TheoLechemia Date: Thu, 22 Jun 2023 16:53:06 +0200 Subject: [PATCH 5/6] render template for account validation --- backend/geonature/core/users/routes.py | 24 +++---------------- .../core/users/templates/account_created.html | 21 ++++++++++++++++ 2 files changed, 24 insertions(+), 21 deletions(-) create mode 100644 backend/geonature/core/users/templates/account_created.html diff --git a/backend/geonature/core/users/routes.py b/backend/geonature/core/users/routes.py index c952c511b5..0ade5c3937 100644 --- a/backend/geonature/core/users/routes.py +++ b/backend/geonature/core/users/routes.py @@ -3,7 +3,7 @@ import json -from flask import Blueprint, request, current_app, Response, redirect, g +from flask import Blueprint, request, current_app, Response, redirect, g, render_template from sqlalchemy.sql import distinct, and_ from werkzeug.exceptions import NotFound, BadRequest, Forbidden @@ -303,26 +303,8 @@ def confirmation(): return Response(r), r.status_code new_user = r.json() - - txt_champs_addi = "" - for key in new_user["champs_addi"]: - txt_champs_addi += ( - f"    - {key}: {new_user['champs_addi'][key]}
    " - ) - - return ( - f"""Le compte suivant à bien été ajouté à l'application GeoNature
    -
    - - Nom: {new_user['nom_role']}
    - - Prénom: {new_user['prenom_role']}
    - - Identifiant: {new_user['identifiant']}
    - - Email: {new_user['email']}
    - - Champs additionnels:
    - {txt_champs_addi} -
    - Retour à l'application GeoNature - """, - 200, + return render_template( + "account_created.html", user=new_user, redirect_url=config["URL_APPLICATION"] ) diff --git a/backend/geonature/core/users/templates/account_created.html b/backend/geonature/core/users/templates/account_created.html new file mode 100644 index 0000000000..b9f6d96b7c --- /dev/null +++ b/backend/geonature/core/users/templates/account_created.html @@ -0,0 +1,21 @@ + + + +

    Création de compte validée

    +

    Le compte suivant a bien été validé:

    +
      +
    • Nom : {{user.nom_role}}
    • +
    • Prénom : {{user.prenom_role}}
    • +
    • Identifiant : {{user.identifiant}}
    • +
    • Email : {{user.email}}
    • + {% for key, value in user.champs_addi.items() %} +
    • + {{key}} : {{value}} +
    • + {% endfor %} +
    + + Retour à l'application GeoNature + + + \ No newline at end of file From 90faf938fbea406896fa8981aa7507ca0ed75e5f Mon Sep 17 00:00:00 2001 From: TheoLechemia Date: Thu, 22 Jun 2023 17:14:24 +0200 Subject: [PATCH 6/6] fix email validation --- backend/geonature/core/users/register_post_actions.py | 2 +- backend/geonature/utils/config_schema.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/geonature/core/users/register_post_actions.py b/backend/geonature/core/users/register_post_actions.py index df0a8c477e..caa223cd6c 100644 --- a/backend/geonature/core/users/register_post_actions.py +++ b/backend/geonature/core/users/register_post_actions.py @@ -52,7 +52,7 @@ def validate_temp_user(data): recipients = [user.email] else: template = "email_admin_validate_account.html" - recipients = validators_emails() + recipients = current_app.config["ACCOUNT_MANAGEMENT"]["VALIDATOR_EMAIL"] url_validation = url_for("users.confirmation", token=user.token_role, _external=True) additional_fields = [ diff --git a/backend/geonature/utils/config_schema.py b/backend/geonature/utils/config_schema.py index 4afe91bc2d..018d6ca5bd 100644 --- a/backend/geonature/utils/config_schema.py +++ b/backend/geonature/utils/config_schema.py @@ -28,7 +28,7 @@ class EmailStrOrListOfEmailStrField(fields.Field): def _deserialize(self, value, attr, data, **kwargs): if isinstance(value, str): self._check_email(value) - return value + return [value] elif isinstance(value, list) and all(isinstance(x, str) for x in value): self._check_email(value) return value