Skip to content
Snippets Groups Projects
Verified Commit 00c57845 authored by Alex ORLUC's avatar Alex ORLUC
Browse files

FEAT #1730 TIME 4:30 hide admin button when no admin + add guard + interceptor...

FEAT #1730 TIME 4:30 hide admin button when no admin + add guard + interceptor + remove access profile in admin
parent ab13c3f4
No related branches found
No related tags found
No related merge requests found
...@@ -24,24 +24,5 @@ export class AppComponent { ...@@ -24,24 +24,5 @@ export class AppComponent {
this.cookieService.set( 'maarchParapheurLang', 'fr' ); this.cookieService.set( 'maarchParapheurLang', 'fr' );
translate.setDefaultLang('fr'); translate.setDefaultLang('fr');
} }
if (this.cookieService.check('maarchParapheurAuth')) {
const cookieInfo = JSON.parse(atob(this.cookieService.get('maarchParapheurAuth')));
this.http.get('../rest/users/' + cookieInfo.id)
.subscribe((data: any) => {
this.signaturesService.userLogged = data.user;
if (this.signaturesService.signaturesList.length === 0) {
this.http.get('../rest/users/' + this.signaturesService.userLogged.id + '/signatures')
.subscribe((dataSign: any) => {
this.signaturesService.signaturesList = dataSign.signatures;
});
}
this.translate.use(this.signaturesService.userLogged.preferences.lang);
},
(err: any) => {
this.notificationService.handleErrors(err);
});
}
} }
} }
import { BrowserModule } from '@angular/platform-browser'; import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule, HttpClient } from '@angular/common/http'; import { HttpClientModule, HttpClient, HTTP_INTERCEPTORS } from '@angular/common/http';
import { RouterModule } from '@angular/router'; import { RouterModule } from '@angular/router';
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { HammerGestureConfig, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser'; import { HammerGestureConfig, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
import { AuthGuard } from './service/auth.guard';
import { AuthInterceptor } from './service/auth-interceptor.service';
// import ngx-translate and the http loader // import ngx-translate and the http loader
import { TranslateLoader, TranslateModule } from '@ngx-translate/core'; import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader'; import { TranslateHttpLoader } from '@ngx-translate/http-loader';
...@@ -119,12 +122,12 @@ import { ConfirmComponent } from './plugins/confirm.component'; ...@@ -119,12 +122,12 @@ import { ConfirmComponent } from './plugins/confirm.component';
AngularDraggableModule, AngularDraggableModule,
AppMaterialModule, AppMaterialModule,
RouterModule.forRoot([ RouterModule.forRoot([
{ path: 'administration', component: AdministrationComponent }, { path: 'administration', canActivate: [AuthGuard], component: AdministrationComponent },
{ path: 'administration/users', component: UsersListComponent }, { path: 'administration/users', canActivate: [AuthGuard], component: UsersListComponent },
{ path: 'administration/users/new', component: UserComponent }, { path: 'administration/users/new', canActivate: [AuthGuard], component: UserComponent },
{ path: 'administration/users/:id', component: UserComponent }, { path: 'administration/users/:id', canActivate: [AuthGuard], component: UserComponent },
{ path: 'documents/:id', component: DocumentComponent }, { path: 'documents/:id', component: DocumentComponent },
{ path: 'documents', component: DocumentComponent }, { path: 'documents', canActivate: [AuthGuard], component: DocumentComponent },
{ path: 'login', component: LoginComponent }, { path: 'login', component: LoginComponent },
{ path: 'forgot-password', component: ForgotPasswordComponent }, { path: 'forgot-password', component: ForgotPasswordComponent },
{ path: 'update-password', component: UpdatePasswordComponent }, { path: 'update-password', component: UpdatePasswordComponent },
...@@ -140,7 +143,9 @@ import { ConfirmComponent } from './plugins/confirm.component'; ...@@ -140,7 +143,9 @@ import { ConfirmComponent } from './plugins/confirm.component';
SignaturesComponent, SignaturesComponent,
ConfirmComponent ConfirmComponent
], ],
providers: [SignaturesContentService, providers: [
{ provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true },
SignaturesContentService,
FiltersService, FiltersService,
NotificationService, NotificationService,
{ {
......
...@@ -143,10 +143,6 @@ export class DocumentComponent implements OnInit { ...@@ -143,10 +143,6 @@ export class DocumentComponent implements OnInit {
private cookieService: CookieService, private cookieService: CookieService,
private sanitizer: DomSanitizer, public dialog: MatDialog, private bottomSheet: MatBottomSheet) { private sanitizer: DomSanitizer, public dialog: MatDialog, private bottomSheet: MatBottomSheet) {
this.draggable = false; this.draggable = false;
if (!this.cookieService.check('maarchParapheurAuth')) {
this.router.navigate(['/login']);
}
} }
ngOnInit(): void { ngOnInit(): void {
......
...@@ -64,21 +64,10 @@ export class ProfileComponent implements OnInit { ...@@ -64,21 +64,10 @@ export class ProfileComponent implements OnInit {
msgButton = 'lang.validate'; msgButton = 'lang.validate';
loading: boolean = false; loading: boolean = false;
constructor(private translate: TranslateService, public http: HttpClient, private router: Router, public sanitizer: DomSanitizer, public notificationService: NotificationService, public signaturesService: SignaturesContentService, private cookieService: CookieService, public filtersService: FiltersService) { } constructor(private translate: TranslateService, public http: HttpClient, private router: Router, public sanitizer: DomSanitizer, public notificationService: NotificationService, public signaturesService: SignaturesContentService, private cookieService: CookieService, public filtersService: FiltersService) { }
ngOnInit(): void { ngOnInit(): void {
if (this.cookieService.check('maarchParapheurAuth')) { this.profileInfo = this.signaturesService.userLogged;
this.loading = true;
const cookieInfo = JSON.parse(atob(this.cookieService.get('maarchParapheurAuth')));
this.http.get('../rest/users/' + cookieInfo.id)
.subscribe((data: any) => {
this.profileInfo = data.user;
this.loading = false;
},
(err: any) => {
this.notificationService.handleErrors(err);
});
}
} }
closeProfile() { closeProfile() {
...@@ -93,7 +82,6 @@ export class ProfileComponent implements OnInit { ...@@ -93,7 +82,6 @@ export class ProfileComponent implements OnInit {
} }
} }
changePasswd() { changePasswd() {
this.showPassword = true; this.showPassword = true;
this.getPassRules(); this.getPassRules();
...@@ -113,7 +101,7 @@ export class ProfileComponent implements OnInit { ...@@ -113,7 +101,7 @@ export class ProfileComponent implements OnInit {
this.passwordRules.minLength.enabled = rule.enabled; this.passwordRules.minLength.enabled = rule.enabled;
this.passwordRules.minLength.value = rule.value; this.passwordRules.minLength.value = rule.value;
if (rule.enabled) { if (rule.enabled) {
this.translate.get('lang.minLengthChar', {charLength: rule.value}).subscribe((res: string) => { this.translate.get('lang.minLengthChar', { charLength: rule.value }).subscribe((res: string) => {
ruleTextArr.push(res); ruleTextArr.push(res);
}); });
} }
...@@ -142,7 +130,7 @@ export class ProfileComponent implements OnInit { ...@@ -142,7 +130,7 @@ export class ProfileComponent implements OnInit {
this.passwordRules.renewal.enabled = rule.enabled; this.passwordRules.renewal.enabled = rule.enabled;
this.passwordRules.renewal.value = rule.value; this.passwordRules.renewal.value = rule.value;
if (rule.enabled) { if (rule.enabled) {
this.translate.get('lang.renewalInfo', {time: rule.value}).subscribe((res: string) => { this.translate.get('lang.renewalInfo', { time: rule.value }).subscribe((res: string) => {
otherRuleTextArr.push(res); otherRuleTextArr.push(res);
}); });
} }
...@@ -150,7 +138,7 @@ export class ProfileComponent implements OnInit { ...@@ -150,7 +138,7 @@ export class ProfileComponent implements OnInit {
this.passwordRules.historyLastUse.enabled = rule.enabled; this.passwordRules.historyLastUse.enabled = rule.enabled;
this.passwordRules.historyLastUse.value = rule.value; this.passwordRules.historyLastUse.value = rule.value;
if (rule.enabled) { if (rule.enabled) {
this.translate.get('lang.historyUseInfo', {countPwd: rule.value}).subscribe((res: string) => { this.translate.get('lang.historyUseInfo', { countPwd: rule.value }).subscribe((res: string) => {
otherRuleTextArr.push(res); otherRuleTextArr.push(res);
}); });
} }
...@@ -174,7 +162,7 @@ export class ProfileComponent implements OnInit { ...@@ -174,7 +162,7 @@ export class ProfileComponent implements OnInit {
} else if (!password.match(/[^A-Za-z0-9]/g) && this.passwordRules.complexitySpecial.enabled) { } else if (!password.match(/[^A-Za-z0-9]/g) && this.passwordRules.complexitySpecial.enabled) {
this.handlePassword.errorMsg = 'lang.specialCharRequired'; this.handlePassword.errorMsg = 'lang.specialCharRequired';
} else if (password.length < this.passwordRules.minLength.value && this.passwordRules.minLength.enabled) { } else if (password.length < this.passwordRules.minLength.value && this.passwordRules.minLength.enabled) {
this.translate.get('lang.minLengthChar', {charLength: this.passwordRules.minLength.value}).subscribe((res: string) => { this.translate.get('lang.minLengthChar', { charLength: this.passwordRules.minLength.value }).subscribe((res: string) => {
this.handlePassword.errorMsg = res; this.handlePassword.errorMsg = res;
}); });
} else { } else {
...@@ -222,55 +210,62 @@ export class ProfileComponent implements OnInit { ...@@ -222,55 +210,62 @@ export class ProfileComponent implements OnInit {
this.signaturesService.userLogged.firstname = this.profileInfo.firstname; this.signaturesService.userLogged.firstname = this.profileInfo.firstname;
this.signaturesService.userLogged.lastname = this.profileInfo.lastname; this.signaturesService.userLogged.lastname = this.profileInfo.lastname;
this.signaturesService.userLogged.picture = data.user.picture; this.signaturesService.userLogged.picture = data.user.picture;
this.signaturesService.userLogged.preferences = data.user.preferences;
this.signaturesService.userLogged.substitute = data.user.substitute; this.signaturesService.userLogged.substitute = data.user.substitute;
this.profileInfo.picture = data.user.picture; this.profileInfo.picture = data.user.picture;
this.setLang(this.signaturesService.userLogged.preferences.lang);
this.cookieService.set( 'maarchParapheurLang', this.signaturesService.userLogged.preferences.lang );
if (this.profileInfo.substitute !== null) { this.http.put('../rest/users/' + this.signaturesService.userLogged.id + '/preferences', profileToSend.preferences)
this.filtersService.resfreshDocuments(); .subscribe(() => {
if (this.signaturesService.documentsList.length > 0 && this.signaturesService.documentsList[this.signaturesService.indexDocumentsList].owner === false) { this.signaturesService.userLogged.preferences = this.profileInfo.preferences;
this.router.navigate(['/documents']); this.setLang(this.signaturesService.userLogged.preferences.lang);
} this.cookieService.set('maarchParapheurLang', this.signaturesService.userLogged.preferences.lang);
}
$('.avatarProfile').css({ 'transform': 'rotate(0deg)' }); if (this.profileInfo.substitute !== null) {
this.filtersService.resfreshDocuments();
if (this.signaturesService.documentsList.length > 0 && this.signaturesService.documentsList[this.signaturesService.indexDocumentsList].owner === false) {
this.router.navigate(['/documents']);
}
}
if (this.showPassword) { $('.avatarProfile').css({ 'transform': 'rotate(0deg)' });
this.http.put('../rest/users/' + this.signaturesService.userLogged.id + '/password', this.password)
.subscribe(() => { if (this.showPassword) {
this.password.newPassword = ''; this.http.put('../rest/users/' + this.signaturesService.userLogged.id + '/password', this.password)
this.password.passwordConfirmation = ''; .subscribe(() => {
this.password.currentPassword = ''; this.password.newPassword = '';
this.password.passwordConfirmation = '';
this.password.currentPassword = '';
this.notificationService.success('lang.profileUpdated');
this.disableState = false;
this.msgButton = 'lang.validate';
this.closeProfile();
}, (err) => {
this.disableState = false;
this.msgButton = 'lang.validate';
if (err.status === 401) {
this.notificationService.error('lang.wrongPassword');
} else {
this.notificationService.handleErrors(err);
}
});
}
if (!this.showPassword) {
this.notificationService.success('lang.profileUpdated'); this.notificationService.success('lang.profileUpdated');
this.disableState = false; this.disableState = false;
this.msgButton = 'lang.validate'; this.msgButton = 'lang.validate';
this.closeProfile(); this.closeProfile();
}, (err) => { }
this.disableState = false;
this.msgButton = 'lang.validate'; if (this.profileInfo.substitute !== null && this.signaturesService.signaturesList.length > 0) {
if (err.status === 401) { this.http.patch('../rest/users/' + this.signaturesService.userLogged.id + '/signatures/substituted', { 'signatures': this.signaturesService.signaturesList })
this.notificationService.error('lang.wrongPassword'); .subscribe(() => { }, (err) => {
} else { this.notificationService.handleErrors(err);
this.notificationService.handleErrors(err); });
} }
});
} }, (err) => {
this.notificationService.handleErrors(err);
if (!this.showPassword) { });
this.notificationService.success('lang.profileUpdated');
this.disableState = false;
this.msgButton = 'lang.validate';
this.closeProfile();
}
if (this.profileInfo.substitute !== null && this.signaturesService.signaturesList.length > 0) {
this.http.patch('../rest/users/' + this.signaturesService.userLogged.id + '/signatures/substituted', {'signatures': this.signaturesService.signaturesList})
.subscribe(() => { }, (err) => {
this.notificationService.handleErrors(err);
});
}
}, (err) => { }, (err) => {
this.disableState = false; this.disableState = false;
...@@ -405,7 +400,7 @@ export class ProfileComponent implements OnInit { ...@@ -405,7 +400,7 @@ export class ProfileComponent implements OnInit {
this.http.put('../rest/users/' + this.currentUserRest.id + '/password', { 'newPassword': this.currentUserRestPassword }) this.http.put('../rest/users/' + this.currentUserRest.id + '/password', { 'newPassword': this.currentUserRestPassword })
.subscribe(() => { .subscribe(() => {
this.currentUserRestPassword = ''; this.currentUserRestPassword = '';
this.translate.get('lang.passwordOfUserUpdated', {user: this.currentUserRest.firstname + ' ' + this.currentUserRest.lastname}).subscribe((res: string) => { this.translate.get('lang.passwordOfUserUpdated', { user: this.currentUserRest.firstname + ' ' + this.currentUserRest.lastname }).subscribe((res: string) => {
this.notificationService.success(res); this.notificationService.success(res);
}); });
}, (err) => { }, (err) => {
......
import { Injectable } from '@angular/core';
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
constructor() {}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(req);
}
}
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
import { Observable, BehaviorSubject } from 'rxjs';
import { tap } from 'rxjs/operators';
import { CookieService } from 'ngx-cookie-service';
import { HttpClient } from '@angular/common/http';
import { SignaturesContentService } from './signatures.service';
@Injectable({
providedIn: 'root'
})
export class AuthGuard implements CanActivate {
constructor(public http: HttpClient, private router: Router, public signaturesService: SignaturesContentService, private cookieService: CookieService) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (this.cookieService.check('maarchParapheurAuth')) {
console.log('Cookie ok !');
if (this.signaturesService.userLogged.id === undefined) {
const cookieInfo = JSON.parse(atob(this.cookieService.get('maarchParapheurAuth')));
this.http.get('../rest/users/' + cookieInfo.id)
.subscribe((data: any) => {
this.signaturesService.userLogged = data.user;
if (this.signaturesService.signaturesList.length === 0) {
this.http.get('../rest/users/' + this.signaturesService.userLogged.id + '/signatures')
.subscribe((dataSign: any) => {
this.signaturesService.signaturesList = dataSign.signatures;
});
}
},
(err: any) => {
this.router.navigateByUrl('/login');
});
return true;
} else {
return true;
}
} else {
console.log('auth failed !');
this.router.navigateByUrl('/login');
return false;
}
}
}
...@@ -14,8 +14,7 @@ ...@@ -14,8 +14,7 @@
{{signaturesService.userLogged.firstname}} {{signaturesService.userLogged.lastname}} {{signaturesService.userLogged.firstname}} {{signaturesService.userLogged.lastname}}
</div> </div>
<div *ngIf="signaturesService.userLogged.picture" class="avatar" <div *ngIf="signaturesService.userLogged.picture" class="avatar"
[ngStyle]="{'background': 'url(' + signaturesService.userLogged.picture + ') no-repeat scroll center center / cover'}" [ngStyle]="{'background': 'url(' + signaturesService.userLogged.picture + ') no-repeat scroll center center / cover'}">
(click)="openProfile()">
</div> </div>
</header> </header>
<header class="sidebar-header"> <header class="sidebar-header">
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
} }
.avatar { .avatar {
cursor: pointer;
position: absolute; position: absolute;
width: 65px; width: 65px;
height: 65px; height: 65px;
...@@ -46,11 +45,6 @@ ...@@ -46,11 +45,6 @@
background-size: cover; background-size: cover;
background-repeat: no-repeat; background-repeat: no-repeat;
background-position: center; background-position: center;
transition: all 0.2s;
}
.avatar:hover {
box-shadow: 0px 0px 5px 0px #656565;
} }
.user { .user {
......
...@@ -45,18 +45,6 @@ export class AdminSidebarComponent implements OnInit { ...@@ -45,18 +45,6 @@ export class AdminSidebarComponent implements OnInit {
}); });
} }
openProfile() {
this.signaturesService.sideNavRigtDatas = {
mode : 'profile',
width : '650px',
locked : true,
};
if (this.signaturesService.mobileMode) {
this.snavLeftComponent.close();
this.snavRightComponent.open();
}
}
openHome() { openHome() {
this.router.navigate(['/documents/']); this.router.navigate(['/documents/']);
if (this.signaturesService.mobileMode) { if (this.signaturesService.mobileMode) {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<button class="logout-button" mat-icon-button (click)="logout()"> <button class="logout-button" mat-icon-button (click)="logout()">
<mat-icon fontSet="fas" fontIcon="fa-power-off"></mat-icon> <mat-icon fontSet="fas" fontIcon="fa-power-off"></mat-icon>
</button> </button>
<button class="admin-button" mat-icon-button (click)="openAdmin()"> <button *ngIf="signaturesService.userLogged.hasAdmin" class="admin-button" mat-icon-button (click)="openAdmin()">
<mat-icon fontSet="fas" fontIcon="fa-tools"></mat-icon> <mat-icon fontSet="fas" fontIcon="fa-tools"></mat-icon>
</button> </button>
<button *ngIf="checkClose()" class="closePanel" <button *ngIf="checkClose()" class="closePanel"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment