Skip to content

Commit

Permalink
register enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
joelclems committed May 31, 2023
1 parent 863ecb7 commit e199647
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 13 deletions.
9 changes: 5 additions & 4 deletions backend/geonature/core/users/register_post_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 22 additions & 1 deletion backend/geonature/core/users/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"&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>
<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'];
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

0 comments on commit e199647

Please sign in to comment.