mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-23 15:30:34 -04:00
Starting the account modal
This commit is contained in:
parent
2f6e37823e
commit
c8e145d2e5
@ -1 +1,16 @@
|
|||||||
<p>Soon</p>
|
<h1 mat-dialog-title>Account</h1>
|
||||||
|
<div mat-dialog-content>
|
||||||
|
<mat-form-field>
|
||||||
|
<mat-label>Email</mat-label>
|
||||||
|
<input matInput name="accountEmail" #accountEmail="ngModel" [(ngModel)]="account.email" required email>
|
||||||
|
</mat-form-field>
|
||||||
|
<br/>
|
||||||
|
<mat-form-field>
|
||||||
|
<mat-label>Username</mat-label>
|
||||||
|
<input matInput name="accountUsername" #accountUsername="ngModel" [(ngModel)]="account.username">
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
<div mat-dialog-actions fxFlexAlign="end" align="end" style="text-align: end">
|
||||||
|
<button mat-button (click)="cancel()">Cancel</button>
|
||||||
|
<button mat-button [mat-dialog-close]="this.account" cdkFocusInitial>Ok</button>
|
||||||
|
</div>
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import {Component, Inject} from '@angular/core';
|
||||||
|
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
||||||
|
import {Account} from "../../models/account";
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-account',
|
selector: 'app-account',
|
||||||
templateUrl: './account.component.html',
|
templateUrl: './account.component.html',
|
||||||
styleUrls: ['./account.component.scss']
|
styleUrls: ['./account.component.scss']
|
||||||
})
|
})
|
||||||
export class AccountComponent implements OnInit {
|
export class AccountComponent
|
||||||
|
{
|
||||||
constructor() { }
|
constructor(public dialogRef: MatDialogRef<AccountComponent>, @Inject(MAT_DIALOG_DATA) public account: Account) {}
|
||||||
|
|
||||||
ngOnInit() {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
cancel()
|
||||||
|
{
|
||||||
|
this.dialogRef.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@ const routes: Routes = [
|
|||||||
{ path: "search/:query", component: SearchComponent, resolve: { items: SearchResolverService } },
|
{ path: "search/:query", component: SearchComponent, resolve: { items: SearchResolverService } },
|
||||||
{ path: "login", component: LoginComponent },
|
{ path: "login", component: LoginComponent },
|
||||||
{ path: "logout", component: LogoutComponent },
|
{ path: "logout", component: LogoutComponent },
|
||||||
{ path: "account", component: AccountComponent, canActivate: [AuthenticatedGuard], canLoad: [AuthenticatedGuard] },
|
|
||||||
{ path: "unauthorized", component: UnauthorizedComponent },
|
{ path: "unauthorized", component: UnauthorizedComponent },
|
||||||
{ path: "**", component: NotFoundComponent }
|
{ path: "**", component: NotFoundComponent }
|
||||||
];
|
];
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
<mat-menu #accountMenu="matMenu">
|
<mat-menu #accountMenu="matMenu">
|
||||||
<a class="link" mat-menu-item href="/account" routerLink="/account">Settings</a>
|
<button mat-menu-item (click)="this.openAccountDialog()">Settings</button>
|
||||||
<button mat-menu-item (click)="this.authManager.logout()">Logout</button>
|
<button mat-menu-item (click)="this.authManager.logout()">Logout</button>
|
||||||
</mat-menu>
|
</mat-menu>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
@ -4,6 +4,9 @@ import { Event, Router, NavigationStart, NavigationEnd, NavigationCancel, Naviga
|
|||||||
import * as $ from "jquery";
|
import * as $ from "jquery";
|
||||||
import { Location } from "@angular/common";
|
import { Location } from "@angular/common";
|
||||||
import {AuthService} from "./services/auth.service";
|
import {AuthService} from "./services/auth.service";
|
||||||
|
import {MatDialog} from "@angular/material/dialog";
|
||||||
|
import {AccountComponent} from "./account/account.component";
|
||||||
|
import {Account} from "../models/account";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
@ -14,8 +17,9 @@ export class AppComponent
|
|||||||
{
|
{
|
||||||
libraries: Library[];
|
libraries: Library[];
|
||||||
isLoading: boolean = false;
|
isLoading: boolean = false;
|
||||||
|
account: Account;
|
||||||
|
|
||||||
constructor(http: HttpClient, private router: Router, private location: Location, private authManager: AuthService)
|
constructor(http: HttpClient, private router: Router, private location: Location, private authManager: AuthService, public dialog: MatDialog)
|
||||||
{
|
{
|
||||||
http.get<Library[]>("api/libraries").subscribe(result =>
|
http.get<Library[]>("api/libraries").subscribe(result =>
|
||||||
{
|
{
|
||||||
@ -43,6 +47,8 @@ export class AppComponent
|
|||||||
|
|
||||||
if (!navigator.userAgent.match(/Mobi/))
|
if (!navigator.userAgent.match(/Mobi/))
|
||||||
document.body.classList.add("hoverEnabled");
|
document.body.classList.add("hoverEnabled");
|
||||||
|
|
||||||
|
this.account = this.authManager.getAccount();
|
||||||
}
|
}
|
||||||
|
|
||||||
openSearch()
|
openSearch()
|
||||||
@ -72,6 +78,11 @@ export class AppComponent
|
|||||||
{
|
{
|
||||||
return this.authManager.isAuthenticated;
|
return this.authManager.isAuthenticated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openAccountDialog()
|
||||||
|
{
|
||||||
|
this.dialog.open(AccountComponent, {width: "500px", data: this.account});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Library
|
interface Library
|
||||||
|
@ -41,6 +41,7 @@ import { AccountComponent } from './account/account.component';
|
|||||||
import {AuthenticatedGuard} from "./guards/authenticated-guard.service";
|
import {AuthenticatedGuard} from "./guards/authenticated-guard.service";
|
||||||
import { UnauthorizedComponent } from './unauthorized/unauthorized.component';
|
import { UnauthorizedComponent } from './unauthorized/unauthorized.component';
|
||||||
import { LogoutComponent } from './logout/logout.component';
|
import { LogoutComponent } from './logout/logout.component';
|
||||||
|
import {MatDialogModule} from '@angular/material/dialog';
|
||||||
|
|
||||||
export function loadConfig(oidcConfigService: OidcConfigService)
|
export function loadConfig(oidcConfigService: OidcConfigService)
|
||||||
{
|
{
|
||||||
@ -83,11 +84,15 @@ export function loadConfig(oidcConfigService: OidcConfigService)
|
|||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
MatInputModule,
|
MatInputModule,
|
||||||
MatFormFieldModule,
|
MatFormFieldModule,
|
||||||
|
MatDialogModule,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
MatTabsModule,
|
MatTabsModule,
|
||||||
MatCheckboxModule,
|
MatCheckboxModule,
|
||||||
AuthModule.forRoot()
|
AuthModule.forRoot()
|
||||||
],
|
],
|
||||||
|
entryComponents: [
|
||||||
|
AccountComponent
|
||||||
|
],
|
||||||
providers: [
|
providers: [
|
||||||
OidcConfigService,
|
OidcConfigService,
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {OidcSecurityService} from "angular-auth-oidc-client";
|
import {OidcSecurityService} from "angular-auth-oidc-client";
|
||||||
import {HttpClient} from "@angular/common/http";
|
import {HttpClient} from "@angular/common/http";
|
||||||
|
import {Account} from "../../models/account";
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@ -28,6 +29,8 @@ export class AuthService
|
|||||||
this.oidcSecurityService.getUserData().subscribe(userData =>
|
this.oidcSecurityService.getUserData().subscribe(userData =>
|
||||||
{
|
{
|
||||||
this.user = userData;
|
this.user = userData;
|
||||||
|
console.log("Got user data:");
|
||||||
|
console.log(this.user);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,4 +51,12 @@ export class AuthService
|
|||||||
{
|
{
|
||||||
this.oidcSecurityService.authorizedCallbackWithCode(window.location.toString());
|
this.oidcSecurityService.authorizedCallbackWithCode(window.location.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getAccount(): Account
|
||||||
|
{
|
||||||
|
if (!this.isAuthenticated)
|
||||||
|
return null;
|
||||||
|
console.log(this.user);
|
||||||
|
return {email: this.user.email, username: this.user.username};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
5
src/models/account.ts
Normal file
5
src/models/account.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export interface Account
|
||||||
|
{
|
||||||
|
username: string;
|
||||||
|
email: string;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user