Modif sigin
This commit is contained in:
parent
f54cdf8365
commit
34777f7a5e
|
@ -1,6 +1,6 @@
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { BrowserModule } from '@angular/platform-browser';
|
import { BrowserModule } from '@angular/platform-browser';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
import { AppRoutingModule } from './app-routing.module';
|
import { AppRoutingModule } from './app-routing.module';
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
import { NavBarComponent } from './header/components/nav-bar/nav-bar.component';
|
import { NavBarComponent } from './header/components/nav-bar/nav-bar.component';
|
||||||
|
@ -11,7 +11,7 @@ import { FooterComponent } from './footer/footer.component';
|
||||||
import { HomePageComponent } from './pages/home-page/home-page.component';
|
import { HomePageComponent } from './pages/home-page/home-page.component';
|
||||||
import { HttpClientModule } from '@angular/common/http';
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
import { ListCategoriesComponent } from './pages/list-categories/list-categories.component';
|
import { ListCategoriesComponent } from './pages/list-categories/list-categories.component';
|
||||||
|
import { SigninComponent } from './pages/signin/signin.component';
|
||||||
import { RestoPageComponent } from './pages/resto-page/resto-page.component';
|
import { RestoPageComponent } from './pages/resto-page/resto-page.component';
|
||||||
import { PageNotFoundComponent } from './pages/page-not-found/page-not-found.component';
|
import { PageNotFoundComponent } from './pages/page-not-found/page-not-found.component';
|
||||||
|
|
||||||
|
@ -26,12 +26,14 @@ import { PageNotFoundComponent } from './pages/page-not-found/page-not-found.com
|
||||||
HomePageComponent,
|
HomePageComponent,
|
||||||
ListCategoriesComponent,
|
ListCategoriesComponent,
|
||||||
RestoPageComponent,
|
RestoPageComponent,
|
||||||
PageNotFoundComponent
|
PageNotFoundComponent,
|
||||||
|
SigninComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
AppRoutingModule,
|
AppRoutingModule,
|
||||||
HttpClientModule
|
HttpClientModule,
|
||||||
|
FormsModule,
|
||||||
],
|
],
|
||||||
providers: [],
|
providers: [],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
export interface User {
|
||||||
|
id?:number;
|
||||||
|
firstName: string;
|
||||||
|
lastName: string;
|
||||||
|
email: string;
|
||||||
|
password?: string;
|
||||||
|
}
|
|
@ -1,13 +1,19 @@
|
||||||
<div class="signin-form text-center">
|
<div class="signin-form text-center">
|
||||||
<main class="form-signin">
|
<main class="form-signin">
|
||||||
|
<form (ngSubmit)="onSubmit(signinForm)" #signinForm="ngForm">
|
||||||
|
<h5>Merci de vous connecter</h5>
|
||||||
<img src="../../../assets/images-header/logo.png"><br>
|
<img src="../../../assets/images-header/logo.png"><br>
|
||||||
<br><h5>Le bon plan pour manger</h5>
|
<br>Le bon plan pour manger<br>
|
||||||
<div class="form-floating">
|
<div class="form-floating">
|
||||||
<input type="email"
|
<input type="email"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
id="floatingInput"
|
id="floatingInput"
|
||||||
placeholder=""
|
placeholder=""
|
||||||
name="email">
|
name="email"
|
||||||
|
ngModel
|
||||||
|
required
|
||||||
|
[ngClass]="{'is-valid': signinForm.form.touched && signinForm.form.value['email'] != '' ,
|
||||||
|
'is-invalid': signinForm.form.touched && signinForm.form.value['email'] == ''}">
|
||||||
<label for="floatingInput">Adresse email</label>
|
<label for="floatingInput">Adresse email</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-floating">
|
<div class="form-floating">
|
||||||
|
@ -15,13 +21,27 @@
|
||||||
class="form-control"
|
class="form-control"
|
||||||
id="floatingPassword"
|
id="floatingPassword"
|
||||||
placeholder=""
|
placeholder=""
|
||||||
name="password">
|
name="password"
|
||||||
|
ngModel
|
||||||
|
required
|
||||||
|
[ngClass]="{'is-valid': signinForm.form.touched && signinForm.form.value['password'] != '' ,
|
||||||
|
'is-invalid': signinForm.form.touched && signinForm.form.value['password'] == ''}">
|
||||||
<label for="floatingPassword">Mot de passe</label>
|
<label for="floatingPassword">Mot de passe</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit">Connexion</button>
|
<button class="w-100 btn btn-lg btn-danger"
|
||||||
|
type="submit"
|
||||||
|
[disabled]="signinForm.invalid">Je me connecte !</button>
|
||||||
|
<p>
|
||||||
|
Form is dirty : {{ signinForm.form.dirty }}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Form is touched : {{ signinForm.form.touched }}
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div *ngIf="errorForm">
|
||||||
|
<p class="text-danger">Il manque des informations dans le formulaire...</p>
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,42 +1,37 @@
|
||||||
.signin-form {
|
.signin-form {
|
||||||
height: 50vh;
|
height: 100vh;
|
||||||
width: 80vh;
|
|
||||||
padding-top: 40px;
|
padding-top: 40px;
|
||||||
margin-bottom: 40px;
|
|
||||||
background-image: url(../../../assets/fond_signin.png);
|
background-image: url(../../../assets/fond_signin.png);
|
||||||
|
background-position: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-signin {
|
.form-signin {
|
||||||
width: 60%;
|
width: 500px;
|
||||||
//max-width: 330px;
|
//max-width: 330px;
|
||||||
padding: 15px;
|
padding: 15px;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
background-color: #f0f0f0;
|
background-color: #f0f0f0;
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
|
box-shadow: 10px 10px 10px grey;
|
||||||
|
margin-top: 25vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-floating:focus-within {
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
|
||||||
input[type="email"] {
|
input[type="email"] {
|
||||||
//margin-top: 10px;
|
margin-top: 10px;
|
||||||
//border-bottom-right-radius: 0;
|
margin-bottom: 5px;
|
||||||
//border-bottom-left-radius: 0;
|
border-bottom-right-radius: 0;
|
||||||
border-radius: 10px;
|
border-bottom-left-radius: 0;
|
||||||
margin-bottom: 10px;
|
|
||||||
border-color: red;
|
border-color: red;
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type="password"] {
|
input[type="password"] {
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
//border-top-left-radius: 0;
|
border-top-left-radius: 0;
|
||||||
//border-top-right-radius: 0;
|
border-top-right-radius: 0;
|
||||||
margin-top: 10px;
|
|
||||||
border-radius: 10px;
|
|
||||||
border-color: red;
|
border-color: red;
|
||||||
}
|
}
|
||||||
|
|
||||||
button{
|
|
||||||
color: white;
|
|
||||||
background-color: red;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { AuthService } from '../../services/auth.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-signin',
|
selector: 'app-signin',
|
||||||
|
@ -6,10 +7,27 @@ import { Component, OnInit } from '@angular/core';
|
||||||
styleUrls: ['./signin.component.scss']
|
styleUrls: ['./signin.component.scss']
|
||||||
})
|
})
|
||||||
export class SigninComponent implements OnInit {
|
export class SigninComponent implements OnInit {
|
||||||
|
public errorForm: boolean;
|
||||||
constructor() { }
|
constructor(private authService: AuthService) {
|
||||||
|
this.errorForm = false;
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public onSubmit(submittedForm: any): void {
|
||||||
|
console.log(submittedForm.form.value);
|
||||||
|
const email = submittedForm.form.value['email'];
|
||||||
|
const password = submittedForm.form.value['password'];
|
||||||
|
if(email !== '' && password !== '') {
|
||||||
|
this.authService.signin(email, password).subscribe(
|
||||||
|
resp => console.log('Component Page Signin: ', resp)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
// afficher une erreur à l'utilisateur
|
||||||
|
this.errorForm = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { AuthService } from './auth.service';
|
||||||
|
|
||||||
|
describe('AuthService', () => {
|
||||||
|
let service: AuthService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(AuthService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,67 @@
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { map, Observable } from 'rxjs';
|
||||||
|
import { environment } from 'src/environments/environment';
|
||||||
|
import { User } from 'src/app/pages/models/user';
|
||||||
|
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class AuthService {
|
||||||
|
private apiUrl: string;
|
||||||
|
private tokenKey: string;
|
||||||
|
|
||||||
|
constructor(private http: HttpClient) {
|
||||||
|
// On se sert des variables d'environnement de notre application
|
||||||
|
this.apiUrl = environment.apiUrl;
|
||||||
|
this.tokenKey = environment.tokenKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
signup(newUser: User): Observable<any> {
|
||||||
|
// const body = {
|
||||||
|
// firstName: firstName,
|
||||||
|
// lastName: lastName,
|
||||||
|
// email: email,
|
||||||
|
// password: password
|
||||||
|
// };
|
||||||
|
|
||||||
|
console.log("Mon nouvel utilisateur : ", newUser);
|
||||||
|
|
||||||
|
return this.http.post(`${this.apiUrl}/register`, newUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
signin(email: string, password: string): Observable<any> {
|
||||||
|
const body = {
|
||||||
|
email: email,
|
||||||
|
password: password
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log("Mon body : ", body);
|
||||||
|
|
||||||
|
// Modifier cette partie ci-dessous :
|
||||||
|
// - pour pouvoir stocker dans le localstorage notre accesstoken
|
||||||
|
// - Sous la clé "TOKEN-LBP"
|
||||||
|
|
||||||
|
return this.http.post(`${this.apiUrl}/login`, body).pipe(
|
||||||
|
map((x: any) => {
|
||||||
|
console.log('Service : ', x.accessToken);
|
||||||
|
// Modification à faire ici
|
||||||
|
localStorage.setItem(this.tokenKey, x.accessToken);
|
||||||
|
return x; // permet de renvoyer la réponse à l'initiateur (page Signin) après le traitement du map
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
forgotPassword(email: string, password: string): Observable<any> {
|
||||||
|
const body = {
|
||||||
|
email: email,
|
||||||
|
password: password
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log("Mon body : ", body);
|
||||||
|
|
||||||
|
return this.http.post(`${this.apiUrl}/forgot-psw`, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Binary file not shown.
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.5 MiB |
|
@ -1,4 +1,5 @@
|
||||||
export const environment = {
|
export const environment = {
|
||||||
production: true,
|
production: true,
|
||||||
apiUrl: ""
|
apiUrl: "",
|
||||||
|
tokenKey: ""
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
export const environment = {
|
export const environment = {
|
||||||
production: false,
|
production: false,
|
||||||
apiUrl: "http://localhost:8080",
|
apiUrl: "http://localhost:8080",
|
||||||
|
tokenKey: "TOKEN-SIMPLEAT"
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue