Skip to content

Commit

Permalink
fix(sign-up): register organism, display error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
joelclems authored and jpm-cbna committed Apr 24, 2024
1 parent 661324e commit d431ff0
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 11 deletions.
22 changes: 16 additions & 6 deletions backend/geonature/core/users/register_post_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
from geonature.utils.env import db, DB


def validators_emails():
"""
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):
"""
Send an email after the action of account creation.
Expand All @@ -46,21 +54,22 @@ def validate_temp_user(data):
template = "email_admin_validate_account.html"
recipients = current_app.config["ACCOUNT_MANAGEMENT"]["VALIDATOR_EMAIL"]
url_validation = url_for("users.confirmation", token=user.token_role, _external=True)

if current_app.config["URL_USERSHUB"]:
url_usershub=current_app.config.get("URL_USERSHUB") + "/temp_users/list"
else:
url_usershub=None

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,
url_usershub=url_usershub,
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)
Expand Down Expand Up @@ -157,7 +166,8 @@ 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"]]
send_mail(recipients, subject, msg_html)


def send_email_for_recovery(data):
Expand Down
9 changes: 7 additions & 2 deletions backend/geonature/core/users/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json


from flask import Blueprint, request, current_app, Response, redirect
from flask import Blueprint, request, current_app, Response, redirect, g, render_template
from sqlalchemy.sql import distinct, and_

from geonature.utils.env import DB
Expand Down Expand Up @@ -278,9 +278,14 @@ 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

return redirect(config["URL_APPLICATION"], code=302)
new_user = r.json()
return render_template(
"account_created.html", user=new_user, redirect_url=config["URL_APPLICATION"]
)


@routes.route("/after_confirmation", methods=["POST"])
Expand Down
21 changes: 21 additions & 0 deletions backend/geonature/core/users/templates/account_created.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<html>

<body>
<h2>Création de compte validée</h2>
<p>Le compte suivant a bien été validé: </p>
<ul>
<li> <b> Nom : </b> {{user.nom_role}} </li>
<li> <b> Prénom : </b> {{user.prenom_role}} </li>
<li> <b> Identifiant : </b> {{user.identifiant}} </li>
<li> <b> Email : </b> {{user.email}} </li>
{% for key, value in user.champs_addi.items() %}
<li>
<b> {{key}} : </b> {{value}}
</li>
{% endfor %}
</ul>

<a href=" {{redirect_url}} ">Retour à l'application GeoNature</a>

</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
<li><b>Prénom :</b> {{user.prenom_role}}</li>
<li><b>Identifiant :</b> {{user.identifiant}}</li>
<li><b>Email :</b> {{user.email}}</li>
{% if user.organisme %}
<li><b>Organisme :</b> {{user.organisme}}</li>
<li><b>Remarque :</b> {{user.remarques}}</li>
{% endif%}
{% if user.remarques %}
<li><b>Remarques :</b> {{user.remarques}}</li>
{% endif%}

</ul>

{% if additional_fields | length > 0 %}
Expand Down
2 changes: 1 addition & 1 deletion backend/geonature/utils/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/app/modules/login/sign-up/sign-up.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ <h5>Informations complémentaires</h5>
</button>
</div>
</form>
<ngb-alert type="danger" *ngIf="errorMsg">
{{errorMsg}}
</ngb-alert>
</div>
</div>
</div>
Expand Down
13 changes: 12 additions & 1 deletion frontend/src/app/modules/login/sign-up/sign-up.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class SignUpComponent implements OnInit {
public disableSubmit = false;
public formControlBuilded = false;
public FORM_CONFIG = AppConfig.ACCOUNT_MANAGEMENT.ACCOUNT_FORM;
public errorMsg = '';

constructor(
private fb: FormBuilder,
Expand Down Expand Up @@ -59,22 +60,32 @@ 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 (AppConfig.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(
res => {
() => {
const callbackMessage = AppConfig.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;
Expand Down

0 comments on commit d431ff0

Please sign in to comment.