-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
324 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,40 @@ | ||
import { | ||
CanActivate, | ||
Router, | ||
ActivatedRouteSnapshot, | ||
RouterStateSnapshot, | ||
} from '@angular/router'; | ||
import {Injectable, OnDestroy} from '@angular/core'; | ||
import {Subscription} from 'rxjs'; | ||
import {Injectable} from '@angular/core'; | ||
import {Observable, of} from 'rxjs'; | ||
import {map} from 'rxjs/operators'; | ||
|
||
import {AuthService} from './service/auth.service'; | ||
|
||
@Injectable({providedIn: 'root'}) | ||
export class AuthGard implements CanActivate, OnDestroy { | ||
subs: Subscription[] = []; | ||
constructor(private auth: AuthService, private router: Router) {} | ||
|
||
ngOnDestroy(): void { | ||
this.subs.forEach(subscription => subscription.unsubscribe()); | ||
} | ||
export class AuthGard implements CanActivate { | ||
constructor(private auth: AuthService) {} | ||
|
||
canActivate( | ||
route: ActivatedRouteSnapshot, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
_route: ActivatedRouteSnapshot, | ||
state: RouterStateSnapshot | ||
): Promise<boolean> { | ||
): Observable<boolean> { | ||
console.log('canActivate', state.url); | ||
try { | ||
return this.auth.isAuthenticated().then(isAuth => { | ||
console.log('isAuth', isAuth); | ||
if (!isAuth) { | ||
console.log('not isAuthenticated'); | ||
this.router.navigate(['/login']); | ||
return false; | ||
} | ||
console.log('logged'); | ||
// this.router.navigate([state.url]); | ||
return true; | ||
}); | ||
return this.auth.isAuthenticated().pipe( | ||
map(isAuth => { | ||
console.log('isAuth', isAuth); | ||
if (!isAuth) { | ||
console.log('not isAuthenticated'); | ||
this.auth.redirectToLogin(true); | ||
return false; | ||
} | ||
console.log('logged'); | ||
return true; | ||
}) | ||
); | ||
} catch (err) { | ||
console.log(err); | ||
return new Promise(() => {}); | ||
return of(false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 85 additions & 71 deletions
156
src/app/application-modules/login/connect/connect.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,87 @@ | ||
<h2>{{ 'login.connect.title' | translate }}:</h2> | ||
<div class="connect-content"> | ||
<form #connectForm="ngForm"> | ||
<mat-error>{{ message }}</mat-error> | ||
<mat-form-field> | ||
<input | ||
matInput | ||
[(ngModel)]="name" | ||
placeholder="{{ 'global.username' | translate }}" | ||
type="text" | ||
#inputName="ngModel" | ||
name="inputName" | ||
required | ||
/> | ||
<mat-error | ||
*ngIf=" | ||
inputName.errors != null && | ||
inputName.errors.required && | ||
!inputName.pristine | ||
" | ||
>{{ 'global.username_required' | translate }}</mat-error | ||
> | ||
</mat-form-field> | ||
<ng-container> | ||
<h2 *ngIf="feature$ | async; else regular"> | ||
{{ 'login.connect.feature' | translate }}: | ||
</h2> | ||
<ng-template #regular> | ||
<h2>{{ 'login.connect.title' | translate }}:</h2> | ||
</ng-template> | ||
<div class="connect-content"> | ||
<form #connectForm="ngForm"> | ||
<mat-error>{{ message }}</mat-error> | ||
<mat-form-field> | ||
<input | ||
matInput | ||
[(ngModel)]="name" | ||
placeholder="{{ 'global.username' | translate }}" | ||
type="text" | ||
#inputName="ngModel" | ||
name="inputName" | ||
required | ||
/> | ||
<mat-error | ||
*ngIf=" | ||
inputName.errors != null && | ||
inputName.errors.required && | ||
!inputName.pristine | ||
" | ||
>{{ 'global.username_required' | translate }}</mat-error | ||
> | ||
</mat-form-field> | ||
|
||
<mat-form-field> | ||
<input | ||
matInput | ||
[(ngModel)]="password" | ||
placeholder="{{ 'login.password' | translate }}" | ||
type="password" | ||
#inputPassword="ngModel" | ||
name="inputPassword" | ||
required | ||
/> | ||
<mat-error | ||
*ngIf=" | ||
inputPassword.errors != null && | ||
inputPassword.errors.required && | ||
!inputPassword.pristine | ||
" | ||
>{{ 'login.password_required' | translate }}</mat-error | ||
> | ||
</mat-form-field> | ||
<mat-form-field> | ||
<input | ||
matInput | ||
[(ngModel)]="password" | ||
placeholder="{{ 'login.password' | translate }}" | ||
type="password" | ||
#inputPassword="ngModel" | ||
name="inputPassword" | ||
required | ||
/> | ||
<mat-error | ||
*ngIf=" | ||
inputPassword.errors != null && | ||
inputPassword.errors.required && | ||
!inputPassword.pristine | ||
" | ||
>{{ 'login.password_required' | translate }}</mat-error | ||
> | ||
</mat-form-field> | ||
|
||
<div class="connect-footer"> | ||
<button | ||
type="submit" | ||
class="btn btn-outline-primary" | ||
(click)="login()" | ||
[disabled]="connectForm.invalid" | ||
> | ||
{{ 'login.connect.log_in' | translate }} | ||
</button> | ||
<button | ||
type="button" | ||
class="btn btn-outline-primary" | ||
routerLink="/login/forgot" | ||
[queryParams]="{name: name}" | ||
> | ||
{{ 'login.connect.forgot' | translate }} | ||
</button> | ||
<button | ||
type="button" | ||
class="btn btn-outline-primary" | ||
routerLink="/login/register" | ||
[queryParams]="{name: name}" | ||
> | ||
{{ 'login.connect.sign_up' | translate }} | ||
</button> | ||
<app-dropdown-language class="dropdown-center"></app-dropdown-language> | ||
</div> | ||
</form> | ||
</div> | ||
<div class="connect-footer"> | ||
<button | ||
type="submit" | ||
class="btn btn-outline-primary" | ||
(click)="login()" | ||
[disabled]="connectForm.invalid" | ||
> | ||
{{ 'login.connect.log_in' | translate }} | ||
</button> | ||
<button | ||
class="btn btn-outline-primary" | ||
(click)="cancel()" | ||
*ngIf="cancel$ | async" | ||
> | ||
{{ 'global.cancel' | translate }} | ||
</button> | ||
<button | ||
type="button" | ||
class="btn btn-outline-primary" | ||
routerLink="/login/forgot" | ||
[queryParams]="{name: name}" | ||
> | ||
{{ 'login.connect.forgot' | translate }} | ||
</button> | ||
<button | ||
type="button" | ||
class="btn btn-outline-primary" | ||
routerLink="/login/register" | ||
[queryParams]="{name: name}" | ||
> | ||
{{ 'login.connect.sign_up' | translate }} | ||
</button> | ||
<app-dropdown-language class="dropdown-center"></app-dropdown-language> | ||
</div> | ||
</form> | ||
</div> | ||
</ng-container> |
Oops, something went wrong.