Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

register enhancement #2575

Merged
merged 6 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -44,17 +52,18 @@ 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 = [
{"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)
Expand Down Expand Up @@ -151,7 +160,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
25 changes: 24 additions & 1 deletion backend/geonature/core/users/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,32 @@ 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()

txt_champs_addi = ""
for key in new_user["champs_addi"]:
txt_champs_addi += (
f"&nbsp;&nbsp;&nbsp;&nbsp;- <b>{key}</b>: {new_user['champs_addi'][key]}<br>"
)

return (
f"""Le compte suivant à bien été ajouté à l'application GeoNature<br>
<br>
- <b>Nom</b>: {new_user['nom_role']}<br>
- <b>Prénom</b>: {new_user['prenom_role']}<br>
- <b>Identifiant</b>: {new_user['identifiant']}<br>
- <b>Email</b>: {new_user['email']}<br>
- <b>Champs additionnels</b>:<br>
{txt_champs_addi}
<br>
<a href="{config["URL_APPLICATION"]}">Retour à l'application GeoNature</a>
""",
200,
)


@routes.route("/after_confirmation", methods=["POST"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<li><b>Prénom :</b> {{user.prenom_role}}</li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Voir si ce n'est pas plus pertinent d'avoir un champ organisme basé sur bib_organisme + champ texte autre organisme

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pour l'instant on reste sur un champs texte dans le formulaire de création de compte.
Mais oui, ça serait bien à terme.

<li><b>Identifiant :</b> {{user.identifiant}}</li>
<li><b>Email :</b> {{user.email}}</li>
{% if user.remarques %}
<li><b>Remarques :</b> {{user.remarques}}</li>
{% endif%}

</ul>

{% if additional_fields | length > 0 %}
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 @@ -214,6 +214,9 @@ <h5>Informations complémentaires</h5>
</button>
</div>
</form>
<ngb-alert type="danger" *ngIf="errorMsg">
{{errorMsg}}
</ngb-alert>
</div>
</div>
</div>
Expand Down
28 changes: 20 additions & 8 deletions frontend/src/app/modules/login/sign-up/sign-up.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
Expand Down Expand Up @@ -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'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enlever organisme des champs prédéfinis et le mettre dans les champs additionnels

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Les champs additionels sont optionnels et à définir dans la config

c'est pas mal au final de garder ce champs dans les champs prédéfinis

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oui on peut se demander si au final on n'en fait pas juste un champs additionnel optionnel et que chacun se le met ou pas...
Mais c'est vrai aussi que c'est un champs classique qui est pertinent dans toute demande de création de compte, à priori.
Donc ça me va de le laisser de base.

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;
});
Expand Down