Making the login works without the need of a reload

This commit is contained in:
Zoe Roux 2020-03-17 00:12:38 +01:00
parent 04944c5164
commit 81b30950e3
3 changed files with 12 additions and 15 deletions

View File

@ -26,7 +26,7 @@
</li>
<ng-template #accountDrop>
<li #accountParent class="nav-item icon" style="opacity: 1 !important;">
<img matRipple [src]="authManager.user.picture" [matMenuTriggerFor]="accountMenu" class="profilePicture" matTooltipPosition="below" [matTooltip]="authManager.user.name" fallback="more.svg" (error)="accountParent.style.removeProperty('opacity');" />
<img matRipple [src]="authManager.user.picture" [matMenuTriggerFor]="accountMenu" class="profilePicture" matTooltipPosition="below" [matTooltip]="authManager.user.username" fallback="more.svg" (error)="accountParent.style.removeProperty('opacity');" />
</li>
<mat-menu #accountMenu="matMenu">
<button class="dropButton" mat-menu-item (click)="this.openAccountDialog()">Settings</button>

View File

@ -17,7 +17,6 @@ export class AppComponent
{
libraries: Library[];
isLoading: boolean = false;
account: Account;
constructor(private http: HttpClient, private router: Router, private location: Location, private authManager: AuthService, public dialog: MatDialog)
{
@ -47,8 +46,6 @@ export class AppComponent
if (!navigator.userAgent.match(/Mobi/))
document.body.classList.add("hoverEnabled");
this.account = this.authManager.getAccount();
}
openSearch()
@ -81,11 +78,10 @@ export class AppComponent
openAccountDialog()
{
const dialog = this.dialog.open(AccountComponent, {width: "500px", data: this.account});
const dialog = this.dialog.open(AccountComponent, {width: "500px", data: this.authManager.getAccount()});
dialog.afterClosed().subscribe((result: Account) =>
{
if (result)
this.account = result;
this.authManager.getUser();
});
}
}

View File

@ -26,14 +26,17 @@ export class AuthService
this.isAuthenticated = auth;
});
this.oidcSecurityService.getUserData().subscribe(userData =>
{
this.user = userData;
console.log("Got user data:");
console.log(this.user);
});
this.getUser();
}
getUser()
{
this.oidcSecurityService.getUserData().subscribe(userData =>
{
this.user = userData;
});
}
login()
{
this.oidcSecurityService.authorize();
@ -56,8 +59,6 @@ export class AuthService
{
if (!this.isAuthenticated)
return null;
console.log("Running get account");
console.log(this.user);
return {email: this.user.email, username: this.user.username, picture: this.user.picture};
}
}