update du code
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
"src/assets"
|
||||
],
|
||||
"styles": [
|
||||
"./node_modules/@angular/material/prebuilt-themes/purple-green.css",
|
||||
"node_modules/@angular/material/prebuilt-themes/purple-green.css",
|
||||
"node_modules/ngx-toastr/toastr.css",
|
||||
"src/styles.css"
|
||||
],
|
||||
|
||||
12474
package-lock.json
generated
12474
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -27,6 +27,7 @@
|
||||
"font-awesome": "^4.7.0",
|
||||
"jquery": "^3.6.1",
|
||||
"material-icons": "^1.12.0",
|
||||
"ngx-cookie-service": "^13.2.0",
|
||||
"ngx-toastr": "^14.3.0",
|
||||
"rxjs": "~7.5.0",
|
||||
"sha.js": "^2.4.11",
|
||||
@@ -34,7 +35,7 @@
|
||||
"zone.js": "~0.11.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "~13.2.5",
|
||||
"@angular-devkit/build-angular": "^13.3.9",
|
||||
"@angular/cli": "~13.2.5",
|
||||
"@angular/compiler-cli": "~13.2.0",
|
||||
"@types/jasmine": "~3.10.0",
|
||||
|
||||
@@ -50,7 +50,8 @@ const routes: Routes = [
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
RouterModule.forRoot(routes, { relativeLinkResolution: 'legacy' })
|
||||
//RouterModule.forRoot(routes, { relativeLinkResolution: 'legacy' })
|
||||
RouterModule.forRoot(routes)
|
||||
],
|
||||
exports: [
|
||||
RouterModule
|
||||
|
||||
@@ -3,6 +3,7 @@ import { BrowserModule } from '@angular/platform-browser';
|
||||
import { HttpClientModule, HttpClientXsrfModule, HTTP_INTERCEPTORS } from '@angular/common/http';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { RouterModule } from '@angular/router';
|
||||
import { CookieService } from 'ngx-cookie-service';
|
||||
|
||||
import { MatToolbarModule } from '@angular/material/toolbar';
|
||||
import { MatSidenavModule } from '@angular/material/sidenav';
|
||||
@@ -27,7 +28,7 @@ import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import { ToastrModule } from 'ngx-toastr';
|
||||
|
||||
import { HttpXsrfInterceptorService } from './interceptors/http-xsrf-interceptor.service';
|
||||
import { HttpXsrfInterceptorService } from './interceptors/http-xsrf-interceptor/http-xsrf-interceptor.service';
|
||||
import { AppRoutingModule } from './app-routing.module';
|
||||
import { AppComponent } from './app.component';
|
||||
import { LoginComponent } from './components/login/login.component';
|
||||
|
||||
@@ -1,31 +1,27 @@
|
||||
<div class="container"
|
||||
fxLayout="column"
|
||||
fxLayoutAlign="space-around center">
|
||||
<!-- Password Form -->
|
||||
<form [formGroup]="passwdFG"
|
||||
fxLayout="column">
|
||||
<mat-form-field>
|
||||
<mat-label>Ancien mot de passe</mat-label>
|
||||
<input matInput type="password" formControlName="old_passwd" class="form-control" name="old_passwd" placeholder="Ancien mot de passe" [ngClass]="{'is-invalid':submitted && passwdFG.controls['old_passwd'].errors}">
|
||||
<mat-error class="myError" *ngIf="passwdFG.controls['old_passwd'].hasError('required')">L'ancien mot de passe est requis !</mat-error>
|
||||
</mat-form-field>
|
||||
<mat-form-field>
|
||||
<mat-label>Nouveau mot de passe</mat-label>
|
||||
<input matInput type="password" formControlName="new_passwd" class="form-control" name="new_password" placeholder="Nouveau mot de passe" [ngClass]="{'is-invalid':submitted && passwdFG.controls['new_passwd'].errors}">
|
||||
<mat-error class="myError" *ngIf="passwdFG.controls['new_passwd'].hasError('required')">Le nouveau mot de passe est requis !</mat-error>
|
||||
<mat-error class="myError" *ngIf="passwdFG.controls['new_passwd'].hasError('pattern')">Le mot de passe doit avoir minimum {{minPw}} caractères et maximum {{maxPw}} avec 1 caratère minuscule, 1 majuscule et 1 chiffre</mat-error>
|
||||
</mat-form-field>
|
||||
<mat-form-field>
|
||||
<mat-label>Confirmation</mat-label>
|
||||
<input matInput type="password" formControlName="confirmation" class="form-control" name="confirmation" placeholder="Confirmation" [ngClass]="{'is-invalid':submitted && passwdFG.controls['confirmation'].errors}">
|
||||
<mat-error class="myError" *ngIf="passwdFG.controls['confirmation'].hasError('required')">La confirmation du nouveau mot de passe est requis !</mat-error>
|
||||
<mat-error class="myError" *ngIf="passwdFG.controls['confirmation'].hasError('pattern')">Le mot de passe doit avoir minimum {{minPw}} caractères et maximum {{maxPw}} avec 1 caratère minuscule, 1 majuscule et 1 chiffre</mat-error>
|
||||
<mat-error class="myError" *ngIf="passwdFG.controls['confirmation'].hasError('mismatch')">La confirmation doit correspondre au mot de passe</mat-error>
|
||||
</mat-form-field>
|
||||
<button mat-raised-button color="primary" (click)="onUpdate()">Mise à jour</button>
|
||||
<!-- <mat-error class="cred" *ngIf="wrongCredentials">Mauvais couple Identifiant/Mot de passe, Recommencez ....</mat-error>
|
||||
<mat-error class="cred" *ngIf="userConnected">Un autre utilisateur ({{usernameConn}}) est déjà connecté, veuillez recommencer ultérieurement ...</mat-error>
|
||||
<mat-error class="cred" *ngIf="errorProcess">Erreur de connexion avec le backend ...</mat-error>
|
||||
-->
|
||||
</form>
|
||||
<!-- Password Form -->
|
||||
<form [formGroup]="passwdFG"
|
||||
fxLayout="column">
|
||||
<mat-form-field>
|
||||
<mat-label>Ancien mot de passe</mat-label>
|
||||
<input matInput type="password" formControlName="old_passwd" class="form-control" name="old_passwd" placeholder="Ancien mot de passe" [ngClass]="{'is-invalid':submitted && passwdFG.controls['old_passwd'].errors}">
|
||||
<mat-error class="myError" *ngIf="passwdFG.controls['old_passwd'].hasError('required')">L'ancien mot de passe est requis !</mat-error>
|
||||
</mat-form-field>
|
||||
<mat-form-field>
|
||||
<mat-label>Nouveau mot de passe</mat-label>
|
||||
<input matInput type="password" formControlName="new_passwd" class="form-control" name="new_password" placeholder="Nouveau mot de passe" [ngClass]="{'is-invalid':submitted && passwdFG.controls['new_passwd'].errors}">
|
||||
<mat-error class="myError" *ngIf="passwdFG.controls['new_passwd'].hasError('required')">Le nouveau mot de passe est requis !</mat-error>
|
||||
<mat-error class="myError" *ngIf="passwdFG.controls['new_passwd'].hasError('pattern')">Le mot de passe doit avoir minimum {{minPw}} caractères et maximum {{maxPw}} avec 1 caratère minuscule, 1 majuscule et 1 chiffre</mat-error>
|
||||
</mat-form-field>
|
||||
<mat-form-field>
|
||||
<mat-label>Confirmation</mat-label>
|
||||
<input matInput type="password" formControlName="confirmation" class="form-control" name="confirmation" placeholder="Confirmation" [ngClass]="{'is-invalid':submitted && passwdFG.controls['confirmation'].errors}">
|
||||
<mat-error class="myError" *ngIf="passwdFG.controls['confirmation'].hasError('required')">La confirmation du nouveau mot de passe est requis !</mat-error>
|
||||
<mat-error class="myError" *ngIf="passwdFG.controls['confirmation'].hasError('pattern')">Le mot de passe doit avoir minimum {{minPw}} caractères et maximum {{maxPw}} avec 1 caratère minuscule, 1 majuscule et 1 chiffre</mat-error>
|
||||
<mat-error class="myError" *ngIf="passwdFG.controls['confirmation'].hasError('mismatch')">La confirmation doit correspondre au mot de passe</mat-error>
|
||||
</mat-form-field>
|
||||
<button mat-raised-button color="primary" (click)="onUpdate()">Mise à jour</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -15,7 +15,8 @@ export class AccountComponent implements OnInit {
|
||||
submitted:boolean=false;
|
||||
minPw:number = 8;
|
||||
maxPw:number = 24;
|
||||
hash:string = '';
|
||||
hash_new:string = '';
|
||||
hash_old:string = '';
|
||||
|
||||
constructor(private fb:FormBuilder,
|
||||
private bs:BackendService,
|
||||
@@ -42,8 +43,10 @@ export class AccountComponent implements OnInit {
|
||||
console.log("Form invalid !!");
|
||||
return;
|
||||
}
|
||||
this.hash = shajs('sha256').update(this.passwdFG.get('new_passwd').value).digest('hex');
|
||||
this.bs.updatePasswd(this.hash).subscribe(
|
||||
this.hash_new = shajs('sha256').update(this.passwdFG.get('new_passwd').value).digest('hex');
|
||||
this.hash_old = shajs('sha256').update(this.passwdFG.get('old_passwd').value).digest('hex');
|
||||
const data = {'old':this.hash_old, 'new':this.hash_new};
|
||||
this.bs.updatePasswd(data).subscribe(
|
||||
data => {
|
||||
this.toast.success("Mise à jour réussie");
|
||||
}, error => {
|
||||
|
||||
@@ -1 +1,20 @@
|
||||
<p>parametres works!</p>
|
||||
<div class="container"
|
||||
fxLayout="column"
|
||||
fxLayoutAlign="space-around center">
|
||||
<!-- Password Form -->
|
||||
<form [formGroup]="paramsFG"
|
||||
fxLayout="column">
|
||||
<mat-form-field>
|
||||
<mat-label>Code PIN</mat-label>
|
||||
<input matInput type="text" formControlName="pin" class="form-control" name="pin" placeholder="Code PIN" [ngClass]="{'is-invalid':submitted && paramsFG.controls['pin'].errors}">
|
||||
<mat-error class="myError" *ngIf="paramsFG.controls['pin'].hasError('required')">Le code PIN est requis !</mat-error>
|
||||
</mat-form-field>
|
||||
<mat-form-field>
|
||||
<mat-label>Numéro accepté</mat-label>
|
||||
<input matInput type="text" formControlName="num_accepted" class="form-control" name="num_accepted" placeholder="Numéro accepté" [ngClass]="{'is-invalid':submitted && paramsFG.controls['num_accepted'].errors}">
|
||||
<mat-error class="myError" *ngIf="paramsFG.controls['num_accepted'].hasError('required')">Le numéro est requis !</mat-error>
|
||||
<mat-error class="myError" *ngIf="paramsFG.controls['num_accepted'].hasError('pattern')">Le numéro est composé de {{Pw}} chiffres</mat-error>
|
||||
</mat-form-field>
|
||||
<button mat-raised-button color="primary" (click)="onUpdate()">Mise à jour</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -1,15 +1,39 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, Validators, ValidatorFn, ValidationErrors, AbstractControl } from '@angular/forms';
|
||||
import { Router } from '@angular/router';
|
||||
import { BackendService } from '../../../../services/backend/backend.service';
|
||||
import { ToastrService } from 'ngx-toastr';
|
||||
|
||||
@Component({
|
||||
selector: 'app-parametres',
|
||||
templateUrl: './parametres.component.html',
|
||||
styleUrls: ['./parametres.component.css']
|
||||
selector: 'app-parametres',
|
||||
templateUrl: './parametres.component.html',
|
||||
styleUrls: ['./parametres.component.css']
|
||||
})
|
||||
export class ParametresComponent implements OnInit {
|
||||
paramsFG:FormGroup;
|
||||
submitted:boolean=false;
|
||||
Pw:number = 10;
|
||||
|
||||
constructor() { }
|
||||
constructor(private fb:FormBuilder,
|
||||
private bs:BackendService,
|
||||
private router:Router,
|
||||
private toast:ToastrService) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
ngOnInit(): void {
|
||||
this.paramsFG=this.fb.group({
|
||||
pin:["", [
|
||||
Validators.required,
|
||||
Validators.pattern('(?=\\D*\\d)(?=[^a-z])(?=[^A-Z]*[A-Z]).{' + this.Pw + '}')
|
||||
]],
|
||||
num_accepted:["", [
|
||||
Validators.required,
|
||||
Validators.pattern('(?=\\D*\\d)(?=[^a-z])(?=[^A-Z]*[A-Z]).{' + this.Pw + '}'),
|
||||
]],
|
||||
});
|
||||
}
|
||||
|
||||
onUpdate(): void {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { Router } from '@angular/router';
|
||||
import { BackendService } from '../../services/backend/backend.service';
|
||||
import { CookieService } from 'ngx-cookie-service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-login',
|
||||
@@ -18,14 +19,14 @@ export class LoginComponent implements OnInit {
|
||||
|
||||
constructor(private fb:FormBuilder,
|
||||
private bs:BackendService,
|
||||
private router:Router) { }
|
||||
private router:Router,
|
||||
private cs:CookieService) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loginFG=this.fb.group({
|
||||
login:["", Validators.required],
|
||||
password:["", Validators.required],
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
onLogin(): void {
|
||||
@@ -34,22 +35,12 @@ export class LoginComponent implements OnInit {
|
||||
return;
|
||||
}
|
||||
|
||||
this.bs.isConnected().subscribe(
|
||||
(data) => {
|
||||
if(data['message'] === 'oui') {
|
||||
this.userConnected = true;
|
||||
this.usernameConn = data['uid'];
|
||||
} else {
|
||||
this.bs.loginUser(this.loginFG.value).subscribe(
|
||||
data => {
|
||||
this.router.navigateByUrl("/");
|
||||
}, err => {
|
||||
this.wrongCredentials = true;
|
||||
});
|
||||
}
|
||||
this.bs.loginUser(this.loginFG.value).subscribe(
|
||||
data => {
|
||||
console.log(data);
|
||||
this.router.navigateByUrl("/");
|
||||
}, err => {
|
||||
this.errorProcess = true;
|
||||
}
|
||||
);
|
||||
this.wrongCredentials = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ export class HttpXsrfInterceptorService {
|
||||
|
||||
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||
// DEBUG
|
||||
console.log("[Interceptor]", req);
|
||||
console.log("[Interceptor] => REQ:", req);
|
||||
// END DEBUG
|
||||
const headerName = 'X-CSRF-TOKEN';
|
||||
const token = this.tokenExtractor.getToken() as string;
|
||||
// DEBUG
|
||||
console.log('[Interceptor] token : ' + token);
|
||||
console.log('[Interceptor] => token : ', token);
|
||||
// END DEBUG
|
||||
|
||||
if (token != null && !req.headers.has(headerName)) {
|
||||
@@ -7,7 +7,8 @@ import { Utilisateur } from '../../models/utilisateur.model';
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ProfileService implements CanActivate, CanActivateChild {
|
||||
//export class ProfileService implements CanActivate, CanActivateChild {
|
||||
export class ProfileService implements CanActivate {
|
||||
profile:Utilisateur;
|
||||
|
||||
constructor( private bs:BackendService,
|
||||
@@ -39,16 +40,16 @@ export class ProfileService implements CanActivate, CanActivateChild {
|
||||
});
|
||||
}
|
||||
|
||||
canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
|
||||
return new Observable((observer) => {
|
||||
this.getProfile().subscribe(profile => {
|
||||
observer.next(true);
|
||||
observer.complete();
|
||||
}, error => {
|
||||
this.router.navigateByUrl("/login");
|
||||
observer.next(false);
|
||||
observer.complete();
|
||||
})
|
||||
});
|
||||
}
|
||||
// canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
|
||||
// return new Observable((observer) => {
|
||||
// this.getProfile().subscribe(profile => {
|
||||
// observer.next(true);
|
||||
// observer.complete();
|
||||
// }, error => {
|
||||
// this.router.navigateByUrl("/login");
|
||||
// observer.next(false);
|
||||
// observer.complete();
|
||||
// })
|
||||
// });
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user