Merge pull request #57 from AlineRinquin/sana

addMember envoi de mail ok
This commit is contained in:
AlineRinquin 2022-02-26 12:51:21 +01:00 committed by GitHub
commit cb1498a215
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { Mail } from 'src/app/models/mail';
import { Membre } from 'src/app/models/membre';
import { AuthService } from 'src/app/services/auth.service';
import { MailService } from 'src/app/services/mail.service';
import { MembreService } from 'src/app/services/membre.service';
@Component({
@ -15,6 +17,7 @@ export class PageAddMemberComponent implements OnInit {
public addMemberForm: FormGroup;
constructor(
private membreService: MembreService,
private mailService: MailService,
private authService: AuthService,
private router: Router,
private fb: FormBuilder
@ -75,9 +78,21 @@ export class PageAddMemberComponent implements OnInit {
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 !== '') {
this.membreService.addMembre(membre)?.subscribe((resp) => {
this.mailService.envoiMailText(mail)?.subscribe((respMail) =>{
console.log("Mail envoyé");
})
this.router.navigate(['compte']);
});
} 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"
});
}
}