mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.4 KiB
87 lines
2.4 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
|
|
*/
|
|
|
|
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core';
|
|
import { ApiUrlConfig, AuthService, Cookies, fadeAnimation, ModalModel, StatefulComponent, UILanguages, UIOptions, UIState } from '@app/shared';
|
|
|
|
interface State {
|
|
// The display name of the user.
|
|
profileDisplayName: string;
|
|
|
|
// The id of the user.
|
|
profileId: string;
|
|
|
|
// The email address of the user.
|
|
profileEmail: string;
|
|
|
|
// The url to the user profile.
|
|
profileUrl: string;
|
|
}
|
|
|
|
@Component({
|
|
selector: 'sqx-profile-menu',
|
|
styleUrls: ['./profile-menu.component.scss'],
|
|
templateUrl: './profile-menu.component.html',
|
|
animations: [
|
|
fadeAnimation
|
|
],
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
})
|
|
export class ProfileMenuComponent extends StatefulComponent<State> implements OnInit {
|
|
public modalMenu = new ModalModel();
|
|
|
|
public showSubmenu = false;
|
|
|
|
public language = this.uiOptions.get('more.culture');
|
|
public languages = UILanguages.ALL;
|
|
|
|
constructor(changeDetector: ChangeDetectorRef, apiUrl: ApiUrlConfig,
|
|
public readonly uiState: UIState,
|
|
public readonly uiOptions: UIOptions,
|
|
public readonly authService: AuthService
|
|
) {
|
|
super(changeDetector, {
|
|
profileDisplayName: '',
|
|
profileEmail: '',
|
|
profileId: '',
|
|
profileUrl: apiUrl.buildUrl('/identity-server/account/profile')
|
|
});
|
|
}
|
|
|
|
public ngOnInit() {
|
|
this.own(
|
|
this.authService.userChanges
|
|
.subscribe(user => {
|
|
if (user) {
|
|
const profileId = user.id;
|
|
const profileEmail = user.email;
|
|
const profileDisplayName = user.displayName;
|
|
|
|
this.next(s => ({ ...s,
|
|
profileId,
|
|
profileEmail,
|
|
profileDisplayName
|
|
}));
|
|
}
|
|
}));
|
|
}
|
|
|
|
public changeLanguage(code: string) {
|
|
Cookies.remove('.AspNetCore.Culture');
|
|
Cookies.set('.AspNetCore.Culture', `c=${code}|uic=${code}`, 365);
|
|
|
|
location.reload();
|
|
}
|
|
|
|
public toggle() {
|
|
this.showSubmenu = !this.showSubmenu;
|
|
}
|
|
|
|
public logout() {
|
|
this.authService.logoutRedirect();
|
|
}
|
|
}
|