Fixed up logic, now on login, we restore if you're already logged in and we redirect you to libraries page.
This commit is contained in:
parent
79a23ac406
commit
e06e34083c
9 changed files with 50 additions and 16 deletions
5
package-lock.json
generated
5
package-lock.json
generated
|
|
@ -7657,6 +7657,11 @@
|
||||||
"integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=",
|
"integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"ngx-bootstrap": {
|
||||||
|
"version": "6.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ngx-bootstrap/-/ngx-bootstrap-6.2.0.tgz",
|
||||||
|
"integrity": "sha512-5WKHo6/ltkenw4UyXZwED8rODCgp2RGbWurzYzZsF/gH1JO5SN7TJ+AL6kXYk6XM42sDA2WhN9Db+ZPNjiyHnA=="
|
||||||
|
},
|
||||||
"ngx-toastr": {
|
"ngx-toastr": {
|
||||||
"version": "13.2.0",
|
"version": "13.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/ngx-toastr/-/ngx-toastr-13.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/ngx-toastr/-/ngx-toastr-13.2.0.tgz",
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
"@ng-bootstrap/ng-bootstrap": "^8.0.0",
|
"@ng-bootstrap/ng-bootstrap": "^8.0.0",
|
||||||
"bootstrap": "^4.5.0",
|
"bootstrap": "^4.5.0",
|
||||||
"font-awesome": "^4.7.0",
|
"font-awesome": "^4.7.0",
|
||||||
|
"ngx-bootstrap": "^6.2.0",
|
||||||
"ngx-toastr": "^13.2.0",
|
"ngx-toastr": "^13.2.0",
|
||||||
"rxjs": "~6.6.0",
|
"rxjs": "~6.6.0",
|
||||||
"tslib": "^2.0.0",
|
"tslib": "^2.0.0",
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,8 @@ export class AccountService {
|
||||||
private currentUserSource = new ReplaySubject<User>(1);
|
private currentUserSource = new ReplaySubject<User>(1);
|
||||||
currentUser$ = this.currentUserSource.asObservable(); // $ at end is because this is observable
|
currentUser$ = this.currentUserSource.asObservable(); // $ at end is because this is observable
|
||||||
|
|
||||||
constructor(private httpClient: HttpClient) { }
|
constructor(private httpClient: HttpClient) {
|
||||||
|
}
|
||||||
|
|
||||||
login(model: any): Observable<any> {
|
login(model: any): Observable<any> {
|
||||||
return this.httpClient.post<User>(this.baseUrl + 'account/login', model).pipe(
|
return this.httpClient.post<User>(this.baseUrl + 'account/login', model).pipe(
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,26 @@
|
||||||
import { Component } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { User } from './_models/user';
|
||||||
|
import { AccountService } from './_services/account.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
templateUrl: './app.component.html',
|
templateUrl: './app.component.html',
|
||||||
styleUrls: ['./app.component.scss']
|
styleUrls: ['./app.component.scss']
|
||||||
})
|
})
|
||||||
export class AppComponent {
|
export class AppComponent implements OnInit {
|
||||||
title = 'kavita-webui';
|
|
||||||
|
constructor(private accountService: AccountService) { }
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.setCurrentUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
setCurrentUser() {
|
||||||
|
const userString = localStorage.getItem('user');
|
||||||
|
if (userString !== '' || localStorage.getItem('user') !== undefined) {
|
||||||
|
const user: User = JSON.parse(userString + '');
|
||||||
|
this.accountService.setCurrentUser(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,14 @@
|
||||||
<ng-container *ngIf="firstTimeFlow">
|
<ng-container *ngIf="firstTimeFlow">
|
||||||
<!-- NOTE: We don't need a first time user flow. We just need a simple component to register a new admin. Once registered, we can put them on admin/ route -->
|
<!-- NOTE: We don't need a first time user flow. We just need a simple component to register a new admin. Once registered, we can put them on admin/ route -->
|
||||||
<p>Please create an admin account for yourself to start your reading journey.</p>
|
<p>Please create an admin account for yourself to start your reading journey.</p>
|
||||||
|
<div class="text-warning">
|
||||||
|
<p>Error:</p>
|
||||||
|
<ul>
|
||||||
|
<!-- <li *ngFor="let error of errors">
|
||||||
|
{{error}}
|
||||||
|
</li> -->
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
<form [formGroup]="registerForm" (ngSubmit)="register()">
|
<form [formGroup]="registerForm" (ngSubmit)="register()">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Username</label>
|
<label>Username</label>
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,17 @@ export class HomeComponent implements OnInit {
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
|
||||||
this.memberService.getMembers().subscribe(members => {
|
// TODO: Clean up this logic
|
||||||
this.firstTimeFlow = members.filter(m => m.isAdmin).length === 0;
|
this.accountService.currentUser$.pipe(take(1)).subscribe(user => {
|
||||||
console.log('First time user flow: ', this.firstTimeFlow);
|
if (user) {
|
||||||
|
// User is logged in, redirect to libraries
|
||||||
|
this.router.navigateByUrl('/library');
|
||||||
|
} else {
|
||||||
|
this.memberService.getMembers().subscribe(members => {
|
||||||
|
this.firstTimeFlow = members.filter(m => m.isAdmin).length === 0;
|
||||||
|
console.log('First time user flow: ', this.firstTimeFlow);
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -41,6 +49,7 @@ export class HomeComponent implements OnInit {
|
||||||
this.router.navigateByUrl('/library');
|
this.router.navigateByUrl('/library');
|
||||||
}, err => {
|
}, err => {
|
||||||
console.log('validation errors from interceptor', err);
|
console.log('validation errors from interceptor', err);
|
||||||
|
//this.errors = err;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,11 @@
|
||||||
|
|
||||||
<!-- TODO: Put SignalR notification button dropdown here. -->
|
<!-- TODO: Put SignalR notification button dropdown here. -->
|
||||||
|
|
||||||
<div class="dropdown" *ngIf="(accountService.currentUser$ | async) as user" dropdown>
|
<div class=" nav-item dropdown" *ngIf="(accountService.currentUser$ | async) as user" dropdown>
|
||||||
<a dropdownToggle class="dropdown-toggle text-light ml-2">{{user.username | titlecase}}</a>
|
<a dropdownToggle class="dropdown-toggle text-light ml-2">{{user.username | titlecase}}</a>
|
||||||
<div class="dropdown-menu mt-3" *dropdownMenu>
|
<div class="dropdown-menu mt-3" *dropdownMenu>
|
||||||
<a (click)="logout()" class="dropdown-item">Logout</a>
|
<a *ngIf="user.isAdmin" class="dropdown-item" routerLink="/admin/users">Logout</a>
|
||||||
|
<a (click)="logout()" class="dropdown-item">Logout</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
<button class="btn btn-secondary mr-3" type="button" (click)="cancel()">Cancel</button>
|
|
||||||
<button class="btn btn-primary" type="submit">Login</button>
|
<button class="btn btn-primary" type="submit">Login</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,4 @@ export class UserLoginComponent implements OnInit {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
cancel() {
|
|
||||||
this.loginForm.reset();
|
|
||||||
// Goes back to previous router state (using back in history)
|
|
||||||
//this.router.p
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue