Skip to content

Commit

Permalink
feat: remove required login
Browse files Browse the repository at this point in the history
  • Loading branch information
69pmb committed Oct 27, 2023
1 parent d58de20 commit e637bd0
Show file tree
Hide file tree
Showing 30 changed files with 324 additions and 228 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
"allowedNames": ["ngOnInit", "ngOnDestroy", "ngOnChanges"]
}
],
"node/no-unpublished-import": ["error"],
"complexity": ["error", 18],
"curly": ["warn"],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error", {"args": "all"}],
"arrow-body-style": ["error", "as-needed"],
"no-duplicate-imports": ["error"],
"lines-between-class-members": [
"error",
"always",
Expand Down
6 changes: 0 additions & 6 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,34 @@ const routes: Routes = [
import('./application-modules/dashboard/dashboard.module').then(
m => m.DashboardModule
),
canActivate: [AuthGard],
},
{
path: 'movie',
loadChildren: () =>
import('./application-modules/movie-detail/movie-detail.module').then(
m => m.MovieDetailModule
),
canActivate: [AuthGard],
},
{
path: 'serie',
loadChildren: () =>
import('./application-modules/serie-detail/serie-detail.module').then(
m => m.SerieDetailModule
),
canActivate: [AuthGard],
},
{
path: 'person',
loadChildren: () =>
import('./application-modules/person-detail/person-detail.module').then(
m => m.PersonDetailModule
),
canActivate: [AuthGard],
},
{
path: 'release',
loadChildren: () =>
import('./application-modules/release/release.module').then(
m => m.ReleaseModule
),
canActivate: [AuthGard],
},
{
path: 'datas',
Expand All @@ -58,7 +53,6 @@ const routes: Routes = [
import('./application-modules/discover/discover.module').then(
m => m.DiscoverModule
),
canActivate: [AuthGard],
},
{
path: 'tags',
Expand Down
14 changes: 9 additions & 5 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {filter} from 'rxjs/operators';
import {Router, NavigationStart, NavigationEnd} from '@angular/router';
import {Router, NavigationStart} from '@angular/router';
import {Component, OnInit} from '@angular/core';
import {TranslateService} from '@ngx-translate/core';

Expand All @@ -8,6 +8,7 @@ import {TabsService} from './service/tabs.service';
import {AuthService} from './service/auth.service';
import {MyDatasService} from './service/my-datas.service';
import {MyTagsService} from './service/my-tags.service';
import {MenuService} from './service/menu.service';

@Component({
selector: 'app-root',
Expand All @@ -21,7 +22,8 @@ export class AppComponent implements OnInit {
private auth: AuthService,
private myDatasService: MyDatasService<Data>,
private myTagsService: MyTagsService,
private translate: TranslateService
private translate: TranslateService,
private menuService: MenuService
) {}

ngOnInit(): void {
Expand All @@ -30,9 +32,7 @@ export class AppComponent implements OnInit {
.subscribe((event: NavigationStart) => {
this.tabsService.onNavigation(event);
});
this.router.events
.pipe(filter(event => event instanceof NavigationEnd))
.subscribe(() => window.scrollTo(0, 0));
this.menuService.event$.subscribe(() => window.scrollTo(0, 0));
this.auth.getCurrentUser(false);
this.auth.user$.subscribe(user => {
if (user) {
Expand All @@ -44,6 +44,10 @@ export class AppComponent implements OnInit {
.then(d => this.myDatasService.removeDuplicate(d, false));
this.myTagsService.getAll();
this.translate.use(user.lang.code);
} else {
this.myDatasService.next([], true);
this.myDatasService.next([], false);
this.myTagsService.myTags$.next([]);
}
});
}
Expand Down
45 changes: 21 additions & 24 deletions src/app/app.gards.ts
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);
}
}
}
2 changes: 1 addition & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import {
import {
TranslateLoader,
TranslateModule,
TranslateService,
MissingTranslationHandler,
} from '@ngx-translate/core';
import {TranslateHttpLoader} from '@ngx-translate/http-loader';
import 'bootstrap';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {MatSnackBarModule} from '@angular/material/snack-bar';
import {TranslateService} from '@ngx-translate/core';

import {SharedModule} from './shared/shared.module';
import {AppRoutingModule} from './app-routing.module';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class DiscoverComponent implements OnInit, OnDestroy {
page: PageEvent;
nbChecked = 0;
max = 300;
adult: boolean;
adult = false;
runtimeRange: any[] = [0, this.max];
formatter: NouiFormatter;
minYear = 1890;
Expand Down
156 changes: 85 additions & 71 deletions src/app/application-modules/login/connect/connect.component.html
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>
Loading

0 comments on commit e637bd0

Please sign in to comment.