Merge pull request #57 from AlineRinquin/sana
addMember envoi de mail ok
This commit is contained in:
commit
cb1498a215
5
src/app/models/mail.ts
Normal file
5
src/app/models/mail.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export interface Mail {
|
||||
recipient: string;
|
||||
subject: string;
|
||||
message: string;
|
||||
}
|
@ -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 {
|
||||
|
16
src/app/services/mail.service.spec.ts
Normal file
16
src/app/services/mail.service.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
29
src/app/services/mail.service.ts
Normal file
29
src/app/services/mail.service.ts
Normal 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"
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user