This commit is contained in:
AlineRinquin 2022-02-26 12:58:57 +01:00
commit 1d4a2c957c
4 changed files with 65 additions and 0 deletions

5
src/app/models/mail.ts Normal file
View File

@ -0,0 +1,5 @@
export interface Mail {
recipient: string;
subject: string;
message: string;
}

View File

@ -1,8 +1,10 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { Mail } from 'src/app/models/mail';
import { Membre } from 'src/app/models/membre'; import { Membre } from 'src/app/models/membre';
import { AuthService } from 'src/app/services/auth.service'; import { AuthService } from 'src/app/services/auth.service';
import { MailService } from 'src/app/services/mail.service';
import { MembreService } from 'src/app/services/membre.service'; import { MembreService } from 'src/app/services/membre.service';
@Component({ @Component({
@ -15,6 +17,7 @@ export class PageAddMemberComponent implements OnInit {
public addMemberForm: FormGroup; public addMemberForm: FormGroup;
constructor( constructor(
private membreService: MembreService, private membreService: MembreService,
private mailService: MailService,
private authService: AuthService, private authService: AuthService,
private router: Router, private router: Router,
private fb: FormBuilder private fb: FormBuilder
@ -75,9 +78,21 @@ export class PageAddMemberComponent implements OnInit {
roleList: [roleValue] roleList: [roleValue]
}; };
const mail: Mail = {
recipient: emailValue,
subject: "Votre mot de passe Organizee",
//message: 'Votre mot de passe'
message: `Bonjour ${firstNameValue}!\n Voici vos identifiants de connexion : \n
Identifiant : ${emailValue}
Mot de passe : ${passwordValue}`
};
if (membre.email !== '' && membre.password !== '') { if (membre.email !== '' && membre.password !== '') {
this.membreService.addMembre(membre)?.subscribe((resp) => { this.membreService.addMembre(membre)?.subscribe((resp) => {
this.mailService.envoiMailText(mail)?.subscribe((respMail) =>{
console.log("Mail envoyé");
})
this.router.navigate(['compte']); this.router.navigate(['compte']);
}); });
} else { } else {

View File

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { MailService } from './mail.service';
describe('MailService', () => {
let service: MailService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(MailService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,29 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Observable } from 'rxjs';
import { environment } from 'src/environments/environment';
import { Mail } from '../models/mail';
import { TokenService } from './token.service';
@Injectable({
providedIn: 'root'
})
export class MailService {
apiUrl: string;
tokenKey: string;
constructor(private http: HttpClient, private tokenService: TokenService, private router: Router) {
this.apiUrl = environment.apiUrl;
this.tokenKey = environment.tokenKey;
}
envoiMailText(mail: Mail): Observable<any> | void{
return this.http.post(`${this.apiUrl}/sendmail/text`, mail, {
responseType: "text"
});
}
}