feat(console): getuserbyid, fix password policy validation, read iam (#233)

* remove displayname, show policy desc on patternerr

* provide password complexity string, org create

* user getuserbyid in userdetail, remove displayname

* show multiple org domains

* show zitadel project warnings, read iam

* add missing ngondestroy impl
This commit is contained in:
Max Peintner
2020-06-17 14:30:21 +02:00
committed by GitHub
parent 1c59d18fee
commit 4688543d07
44 changed files with 8307 additions and 770 deletions
@@ -6,6 +6,8 @@
<h1>{{ 'APP.PAGES.TITLE' | translate }} {{app?.name}}</h1>
<p class="desc">{{ 'APP.PAGES.DESCRIPTION' | translate }}</p>
<p *ngIf="isZitadel" class="zitadel-warning">This belongs to Zitadel project. If you change something, Zitadel
may not behave as intended!</p>
</div>
<span *ngIf="errorMessage" class="err-container">{{errorMessage}}</span>
@@ -86,7 +88,7 @@
<mat-form-field class="full-width" appearance="outline">
<mat-label>{{ 'APP.OIDC.REDIRECT' | translate }}</mat-label>
<mat-chip-list #chipRedirectList [disabled]="isZitadel">
<mat-chip-list #chipRedirectList>
<mat-chip *ngFor="let redirect of redirectUrisList" [selectable]="selectable"
(removed)="remove(redirect, RedirectType.REDIRECT)">
{{redirect}}
@@ -100,7 +102,7 @@
<mat-form-field class="full-width" appearance="outline">
<mat-label>{{ 'APP.OIDC.POSTLOGOUTREDIRECT' | translate }}</mat-label>
<mat-chip-list #chipPostRedirectList [disabled]="isZitadel">
<mat-chip-list #chipPostRedirectList>
<mat-chip *ngFor="let redirect of postLogoutRedirectUrisList" [selectable]="selectable"
(removed)="remove(redirect, RedirectType.POSTREDIRECT)">
{{redirect}}
@@ -21,6 +21,11 @@
font-size: .9rem;
color: #81868a;
}
.zitadel-warning {
font-size: 14px;
color: rgb(201,51,71);
}
}
.err-container {
@@ -18,6 +18,7 @@ import {
OIDCResponseType,
} from 'src/app/proto/generated/management_pb';
import { GrpcService } from 'src/app/services/grpc.service';
import { OrgService } from 'src/app/services/org.service';
import { ProjectService } from 'src/app/services/project.service';
import { ToastService } from 'src/app/services/toast.service';
@@ -84,6 +85,7 @@ export class AppDetailComponent implements OnInit, OnDestroy {
private _location: Location,
private dialog: MatDialog,
private grpcService: GrpcService,
private orgService: OrgService,
) {
this.appNameForm = this.fb.group({
state: ['', []],
@@ -108,12 +110,8 @@ export class AppDetailComponent implements OnInit, OnDestroy {
private async getData({ projectid, id }: Params): Promise<void> {
this.projectId = projectid;
this.projectService.GetProjectById(this.projectId).then(project => {
this.isZitadel = project.toObject().name === 'Zitadel';
if (this.isZitadel) {
this.appNameForm.disable();
this.appForm.disable();
}
this.orgService.GetIam().then(iam => {
this.isZitadel = iam.toObject().iamProjectId === this.projectId;
});
@@ -122,8 +120,7 @@ export class AppDetailComponent implements OnInit, OnDestroy {
this.appNameForm.patchValue(this.app);
console.log(this.grpcService.clientid, this.app.oidcConfig?.clientId);
console.log(this.isZitadel);
if (this.app.state !== AppState.APPSTATE_ACTIVE || this.isZitadel) {
if (this.app.state !== AppState.APPSTATE_ACTIVE) {
this.appNameForm.controls['name'].disable();
this.appForm.disable();
} else {
@@ -74,13 +74,6 @@
{{ 'USER.VALIDATION.REQUIRED' | translate }}
</mat-error>
</mat-form-field>
<mat-form-field class="formfield">
<mat-label>{{ 'USER.PROFILE.DISPLAYNAME' | translate }}</mat-label>
<input matInput formControlName="displayName" />
<mat-error *ngIf="displayName?.invalid && displayName?.errors?.required">
{{ 'USER.VALIDATION.REQUIRED' | translate }}
</mat-error>
</mat-form-field>
<p class="section">{{ 'USER.CREATE.GENDERLANGSECTION' | translate }}</p>
@@ -115,7 +108,10 @@
type="password" />
<mat-error *ngIf="password?.errors?.required">{{ 'USER.VALIDATION.REQUIRED' | translate }}
</mat-error>
<mat-error *ngIf="password?.errors?.pattern">{{ 'USER.VALIDATION.INVALIDPATTERN' | translate }}
<mat-error *ngIf="password?.errors?.pattern">{{ policy | passwordPattern | translate }}
</mat-error>
<mat-error *ngIf="password?.errors?.minlength">
{{ 'USER.VALIDATION.MINLENGTH' | translate:policy }}
</mat-error>
</mat-form-field>
<mat-form-field class="formfield">
@@ -125,6 +121,11 @@
<mat-error *ngIf="confirmPassword?.errors?.required">
{{ 'USER.VALIDATION.REQUIRED' | translate }}
</mat-error>
<mat-error *ngIf="password?.errors?.pattern">{{ policy | passwordPattern | translate }}
</mat-error>
<mat-error *ngIf="password?.errors?.minlength">
{{ 'USER.VALIDATION.MINLENGTH' | translate:policy }}
</mat-error>
</mat-form-field>
</div>
@@ -4,7 +4,9 @@ import { Component } from '@angular/core';
import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { CreateOrgRequest, CreateUserRequest, Gender, OrgSetUpResponse } from 'src/app/proto/generated/admin_pb';
import { PasswordComplexityPolicy } from 'src/app/proto/generated/management_pb';
import { AdminService } from 'src/app/services/admin.service';
import { OrgService } from 'src/app/services/org.service';
import { ToastService } from 'src/app/services/toast.service';
function passwordConfirmValidator(c: AbstractControl): any {
@@ -44,28 +46,65 @@ export class OrgCreateComponent {
public genders: Gender[] = [Gender.GENDER_FEMALE, Gender.GENDER_MALE, Gender.GENDER_UNSPECIFIED];
public languages: string[] = ['de', 'en'];
public policy!: PasswordComplexityPolicy.AsObject;
constructor(
private router: Router,
private toast: ToastService,
private adminService: AdminService,
private _location: Location,
private fb: FormBuilder,
private orgService: OrgService,
) {
const validators: Validators[] = [Validators.required];
this.orgForm = this.fb.group({
name: ['', [Validators.required]],
domain: ['', [Validators.required]],
});
this.orgService.GetPasswordComplexityPolicy().then(data => {
this.policy = data.toObject();
if (this.policy.minLength) {
validators.push(Validators.minLength(this.policy.minLength));
}
if (this.policy.hasLowercase) {
validators.push(Validators.pattern(/[a-z]/g));
}
if (this.policy.hasUppercase) {
validators.push(Validators.pattern(/[A-Z]/g));
}
if (this.policy.hasNumber) {
validators.push(Validators.pattern(/[0-9]/g));
}
if (this.policy.hasSymbol) {
// All characters that are not a digit or an English letter \W or a whitespace \S
validators.push(Validators.pattern(/[\W\S]/));
}
this.userForm = this.fb.group({
firstName: ['', [Validators.required]],
lastName: ['', [Validators.required]],
displayName: [''],
email: ['', [Validators.required]],
gender: [''],
nickName: [''],
preferredLanguage: [''],
password: ['', [Validators.required]],
confirmPassword: ['', [Validators.required, passwordConfirmValidator]],
this.userForm = this.fb.group({
firstName: ['', [Validators.required]],
lastName: ['', [Validators.required]],
email: ['', [Validators.required]],
gender: [''],
nickName: [''],
preferredLanguage: [''],
password: ['', validators],
confirmPassword: ['', [...validators, passwordConfirmValidator]],
});
}).catch(error => {
console.log('no password complexity policy defined!');
console.error(error);
this.userForm = this.fb.group({
firstName: ['', [Validators.required]],
lastName: ['', [Validators.required]],
email: ['', [Validators.required]],
gender: [''],
nickName: [''],
preferredLanguage: [''],
password: ['', validators],
confirmPassword: ['', [...validators, passwordConfirmValidator]],
});
});
}
@@ -82,7 +121,6 @@ export class OrgCreateComponent {
registerUserRequest.setFirstName(this.firstName?.value);
registerUserRequest.setLastName(this.lastName?.value);
registerUserRequest.setNickName(this.nickName?.value);
registerUserRequest.setDisplayName(this.displayName?.value);
registerUserRequest.setGender(this.gender?.value);
registerUserRequest.setPassword(this.password?.value);
registerUserRequest.setPreferredLanguage(this.preferredLanguage?.value);
@@ -122,10 +160,6 @@ export class OrgCreateComponent {
return this.userForm.get('lastName');
}
public get displayName(): AbstractControl | null {
return this.userForm.get('displayName');
}
public get email(): AbstractControl | null {
return this.userForm.get('email');
}
@@ -9,6 +9,7 @@ import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { HttpLoaderFactory } from 'src/app/app.module';
import { PipesModule } from 'src/app/pipes/pipes.module';
import { OrgCreateRoutingModule } from './org-create-routing.module';
import { OrgCreateComponent } from './org-create.component';
@@ -25,6 +26,7 @@ import { OrgCreateComponent } from './org-create.component';
MatButtonModule,
MatIconModule,
MatSelectModule,
PipesModule,
TranslateModule.forChild({
loader: {
provide: TranslateLoader,
@@ -11,8 +11,8 @@
<metainfo class="side">
<div class="details">
<div class="row">
<span class="first">Domain:</span>
<span class="second" *ngIf="org?.domain">{{org.domain}}</span>
<span class="first">Domains:</span>
<span *ngFor="let domain of domains" class="second">{{domain.domain}}</span>
</div>
<div class="row">
<span class="first">State:</span>
@@ -6,7 +6,7 @@ import { ActivatedRoute, Params } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { Subscription } from 'rxjs';
import { ChangeType } from 'src/app/modules/changes/changes.component';
import { Org, OrgMember, OrgMemberSearchResponse, OrgState } from 'src/app/proto/generated/management_pb';
import { Org, OrgDomainView, OrgMember, OrgMemberSearchResponse, OrgState } from 'src/app/proto/generated/management_pb';
import { OrgService } from 'src/app/services/org.service';
import { ToastService } from 'src/app/services/toast.service';
@@ -29,6 +29,8 @@ export class OrgDetailComponent implements OnInit, OnDestroy {
private subscription: Subscription = new Subscription();
public domains: OrgDomainView.AsObject[] = [];
constructor(
public translate: TranslateService,
private route: ActivatedRoute,
@@ -52,6 +54,11 @@ export class OrgDetailComponent implements OnInit, OnDestroy {
}).catch(error => {
this.toast.showError(error.message);
});
this.orgService.SearchMyOrgDomains(0, 100).then(result => {
console.log(result.toObject().resultList);
this.domains = result.toObject().resultList;
});
}
public changeState(event: MatButtonToggleChange | any): void {
@@ -8,13 +8,15 @@
<div class="full-width">
<p class="desc">{{ 'PROJECT.PAGES.DESCRIPTION' | translate }}</p>
<p *ngIf="isZitadel" class="zitadel-warning">This belongs to Zitadel project. If you change something,
Zitadel
may not behave as intended!</p>
</div>
</div>
<app-card>
<app-project-grant-members *ngIf="project && project.projectId && project.id"
[disabled]="project?.state !== ProjectState.PROJECTSTATE_ACTIVE || (isZitadel$ | async)"
[project]="project">
[disabled]="project?.state !== ProjectState.PROJECTSTATE_ACTIVE || isZitadel" [project]="project">
</app-project-grant-members>
</app-card>
</div>
@@ -33,6 +33,11 @@
font-size: .9rem;
color: #81868a;
}
.zitadel-warning {
font-size: 14px;
color: rgb(201,51,71);
}
}
}
@@ -4,7 +4,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core';
import { MatTableDataSource } from '@angular/material/table';
import { ActivatedRoute, Params } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { from, Observable, of, Subscription } from 'rxjs';
import { Subscription } from 'rxjs';
import { ChangeType } from 'src/app/modules/changes/changes.component';
import {
Application,
@@ -17,7 +17,7 @@ import {
ProjectState,
ProjectType,
} from 'src/app/proto/generated/management_pb';
import { GrpcService } from 'src/app/services/grpc.service';
import { OrgService } from 'src/app/services/org.service';
import { ProjectService } from 'src/app/services/project.service';
import { ToastService } from 'src/app/services/toast.service';
@@ -55,8 +55,7 @@ export class GrantedProjectDetailComponent implements OnInit, OnDestroy {
private subscription?: Subscription;
public editstate: boolean = false;
public isZitadel$: Observable<boolean> = of(false);
private zitadelsub: Subscription = new Subscription();
public isZitadel: boolean = false;
constructor(
public translate: TranslateService,
@@ -64,7 +63,7 @@ export class GrantedProjectDetailComponent implements OnInit, OnDestroy {
private toast: ToastService,
private projectService: ProjectService,
private _location: Location,
private grpcService: GrpcService,
private orgService: OrgService,
) {
}
@@ -74,28 +73,24 @@ export class GrantedProjectDetailComponent implements OnInit, OnDestroy {
public ngOnDestroy(): void {
this.subscription?.unsubscribe();
this.zitadelsub.unsubscribe();
}
private async getData({ id, grantId }: Params): Promise<void> {
this.projectId = id;
this.grantId = grantId;
this.orgService.GetIam().then(iam => {
this.isZitadel = iam.toObject().iamProjectId === this.projectId;
});
if (this.projectId && this.grantId) {
this.projectService.GetGrantedProjectByID(this.projectId, this.grantId).then(proj => {
this.project = proj.toObject();
console.log(this.project);
this.isZitadel$ = from(this.projectService.SearchApplications(this.project.id, 100, 0).then(appsResp => {
const ret = appsResp.toObject().resultList
.filter(app => app.oidcConfig?.clientId === this.grpcService.clientid).length > 0;
return ret;
}));
}).catch(error => {
this.toast.showError(error.message);
});
}
this.zitadelsub = this.isZitadel$.subscribe(isZita => console.log(`zitade: ${isZita}`));
}
public navigateBack(): void {
@@ -7,7 +7,7 @@
<h1>{{ 'PROJECT.PAGES.TITLE' | translate }} {{project?.name}}</h1>
<ng-template appHasRole [appHasRole]="['project.write:'+projectId, 'project.write']">
<button mat-icon-button (click)="editstate = !editstate" aria-label="Edit project name"
*ngIf="(isZitadel$ | async) === false">
*ngIf="isZitadel === false">
<mat-icon *ngIf="!editstate">edit</mat-icon>
<mat-icon *ngIf="editstate">close</mat-icon>
</button>
@@ -23,14 +23,17 @@
<button class="icon-button" *ngIf="editstate" mat-icon-button (click)="updateName()">
<mat-icon>check</mat-icon>
</button>
<button mat-stroked-button color="accent" [disabled]="(isZitadel$ | async)"
<button mat-stroked-button color="accent" [disabled]="isZitadel"
*ngIf="project?.state === ProjectState.PROJECTSTATE_ACTIVE" class="second"
(click)="changeState(ProjectState.PROJECTSTATE_INACTIVE)">{{'PROJECT.TABLE.DEACTIVATE' | translate}}</button>
<button mat-stroked-button color="accent" [disabled]="(isZitadel$ | async)"
<button mat-stroked-button color="accent" [disabled]="isZitadel"
*ngIf="project?.state === ProjectState.PROJECTSTATE_INACTIVE" class="second"
(click)="changeState(ProjectState.PROJECTSTATE_ACTIVE)">{{'PROJECT.TABLE.ACTIVATE' | translate}}</button>
</ng-container>
<p class="desc">{{ 'PROJECT.PAGES.DESCRIPTION' | translate }}</p>
<p *ngIf="isZitadel" class="zitadel-warning">This belongs to Zitadel project. If you change something,
Zitadel
may not behave as intended!</p>
</div>
</div>
@@ -38,7 +41,7 @@
<ng-container *ngIf="project">
<ng-template appHasRole [appHasRole]="['project.app.read:' + project.id, 'project.app.read']">
<app-project-application-grid *ngIf="grid"
[disabled]="project?.state !== ProjectState.PROJECTSTATE_ACTIVE || (isZitadel$ | async)"
[disabled]="project?.state !== ProjectState.PROJECTSTATE_ACTIVE || isZitadel"
(changeView)="grid = false" [projectId]="projectId"></app-project-application-grid>
<app-card *ngIf="!grid" title="{{ 'PROJECT.APP.TITLE' | translate }}">
<card-actions class="card-actions">
@@ -47,12 +50,12 @@
</button>
</card-actions>
<app-project-applications
[disabled]="project?.state !== ProjectState.PROJECTSTATE_ACTIVE || (isZitadel$ | async)"
[disabled]="project?.state !== ProjectState.PROJECTSTATE_ACTIVE || isZitadel"
[projectId]="projectId"></app-project-applications>
</app-card>
</ng-template>
<ng-container *ngIf="(isZitadel$ | async) == false">
<ng-container *ngIf="isZitadel == false">
<ng-template appHasRole [appHasRole]="['project.grant.read:' + project.id, 'project.grant.read']">
<app-card title="{{ 'PROJECT.GRANT.TITLE' | translate }}"
description="{{ 'PROJECT.GRANT.DESCRIPTION' | translate }}">
@@ -33,6 +33,11 @@
font-size: .9rem;
color: #81868a;
}
.zitadel-warning {
font-size: 14px;
color: rgb(201,51,71);
}
}
}
@@ -4,7 +4,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core';
import { MatTableDataSource } from '@angular/material/table';
import { ActivatedRoute, Params } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { from, Observable, of, Subscription } from 'rxjs';
import { Subscription } from 'rxjs';
import { ChangeType } from 'src/app/modules/changes/changes.component';
import {
Application,
@@ -17,7 +17,7 @@ import {
ProjectState,
ProjectType,
} from 'src/app/proto/generated/management_pb';
import { GrpcService } from 'src/app/services/grpc.service';
import { OrgService } from 'src/app/services/org.service';
import { ProjectService } from 'src/app/services/project.service';
import { ToastService } from 'src/app/services/toast.service';
@@ -55,8 +55,7 @@ export class OwnedProjectDetailComponent implements OnInit, OnDestroy {
private subscription?: Subscription;
public editstate: boolean = false;
public isZitadel$: Observable<boolean> = of(false);
private zitadelsub: Subscription = new Subscription();
public isZitadel: boolean = false;
constructor(
public translate: TranslateService,
@@ -64,7 +63,7 @@ export class OwnedProjectDetailComponent implements OnInit, OnDestroy {
private toast: ToastService,
private projectService: ProjectService,
private _location: Location,
private grpcService: GrpcService,
private orgService: OrgService,
) {
}
@@ -74,27 +73,23 @@ export class OwnedProjectDetailComponent implements OnInit, OnDestroy {
public ngOnDestroy(): void {
this.subscription?.unsubscribe();
this.zitadelsub.unsubscribe();
}
private async getData({ id }: Params): Promise<void> {
this.projectId = id;
this.orgService.GetIam().then(iam => {
this.isZitadel = iam.toObject().iamProjectId === this.projectId;
});
if (this.projectId) {
this.projectService.GetProjectById(id).then(proj => {
this.project = proj.toObject();
console.log(this.project);
this.isZitadel$ = from(this.projectService.SearchApplications(this.project.id, 100, 0).then(appsResp => {
const ret = appsResp.toObject().resultList
.filter(app => app.oidcConfig?.clientId === this.grpcService.clientid).length > 0;
return ret;
}));
}).catch(error => {
this.toast.showError(error.message);
});
}
this.zitadelsub = this.isZitadel$.subscribe(isZita => console.log(`zitade: ${isZita}`));
}
public changeState(newState: ProjectState): void {
@@ -52,13 +52,6 @@
{{ 'USER.VALIDATION.REQUIRED' | translate }}
</mat-error>
</mat-form-field>
<mat-form-field class="formfield">
<mat-label>{{ 'USER.PROFILE.DISPLAYNAME' | translate }}</mat-label>
<input matInput formControlName="displayName" />
<mat-error *ngIf="displayName?.invalid && displayName?.errors?.required">
{{ 'USER.VALIDATION.REQUIRED' | translate }}
</mat-error>
</mat-form-field>
<p class="section">{{ 'USER.CREATE.GENDERLANGSECTION' | translate }}</p>
@@ -28,7 +28,6 @@ export class UserCreateComponent implements OnDestroy {
firstName: ['', Validators.required],
lastName: ['', Validators.required],
nickName: [''],
displayName: [{ value: '', disabled: false }],
gender: [Gender.GENDER_UNSPECIFIED],
preferredLanguage: [''],
phone: [''],
@@ -75,9 +74,6 @@ export class UserCreateComponent implements OnDestroy {
public get nickName(): AbstractControl | null {
return this.userForm.get('nickName');
}
public get displayName(): AbstractControl | null {
return this.userForm.get('displayName');
}
public get gender(): AbstractControl | null {
return this.userForm.get('gender');
}
@@ -36,10 +36,10 @@
formControlName="newPassword" />
<mat-error *ngIf="newPassword?.errors?.required">{{ 'USER.VALIDATION.REQUIRED' | translate }}
</mat-error>
<mat-error *ngIf="newPassword?.errors?.pattern">{{ 'USER.VALIDATION.INVALIDPATTERN' | translate }}
<mat-error *ngIf="newPassword?.errors?.pattern">{{ policy | passwordPattern | translate }}
</mat-error>
<mat-error *ngIf="newPassword?.errors?.minlength">
{{ 'USER.PASSWORD.MINLENGTHERROR' | translate: minLengthPassword }}
{{ 'USER.VALIDATION.MINLENGTH' | translate:policy }}
</mat-error>
</mat-form-field>
<mat-form-field class="formfield">
@@ -49,10 +49,10 @@
<mat-error *ngIf="confirmPassword?.errors?.required">{{ 'USER.VALIDATION.REQUIRED' | translate }}
</mat-error>
<mat-error *ngIf="confirmPassword?.errors?.pattern">
{{ 'USER.VALIDATION.INVALIDPATTERN' | translate }}
{{ policy | passwordPattern | translate }}
</mat-error>
<mat-error *ngIf="confirmPassword?.errors?.minlength">
{{ 'USER.PASSWORD.MINLENGTHERROR' | translate: minLengthPassword }}
{{ 'USER.VALIDATION.MINLENGTH' | translate:policy }}
</mat-error>
<mat-error *ngIf="confirmPassword?.errors?.notequal">{{ 'USER.PASSWORD.NOTEQUAL' | translate }}
</mat-error>
@@ -3,9 +3,10 @@ import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/fo
import { MatDialog } from '@angular/material/dialog';
import { TranslateService } from '@ngx-translate/core';
import { Subscription } from 'rxjs';
import { Gender, UserAddress, UserEmail, UserPhone, UserProfile } from 'src/app/proto/generated/auth_pb';
import { Gender, User, UserAddress, UserEmail, UserPhone, UserProfile } from 'src/app/proto/generated/auth_pb';
import { PasswordComplexityPolicy } from 'src/app/proto/generated/management_pb';
import { AuthUserService } from 'src/app/services/auth-user.service';
import { MgmtUserService } from 'src/app/services/mgmt-user.service';
import { OrgService } from 'src/app/services/org.service';
import { ToastService } from 'src/app/services/toast.service';
@@ -32,6 +33,8 @@ function passwordConfirmValidator(c: AbstractControl): any {
styleUrls: ['./auth-user-detail.component.scss'],
})
export class AuthUserDetailComponent implements OnDestroy {
public user!: User.AsObject;
public profile!: UserProfile.AsObject;
public email: UserEmail.AsObject = { email: '' } as any;
public phone: UserPhone.AsObject = { phone: '' } as any;
@@ -48,13 +51,12 @@ export class AuthUserDetailComponent implements OnDestroy {
public loading: boolean = false;
public minLengthPassword: any = {
value: 0,
};
public policy!: PasswordComplexityPolicy.AsObject;
constructor(
public translate: TranslateService,
private toast: ToastService,
private mgmtUserService: MgmtUserService,
private userService: AuthUserService,
private fb: FormBuilder,
private dialog: MatDialog,
@@ -62,21 +64,20 @@ export class AuthUserDetailComponent implements OnDestroy {
) {
const validators: Validators[] = [Validators.required];
this.orgService.GetPasswordComplexityPolicy().then(data => {
const policy: PasswordComplexityPolicy.AsObject = data.toObject();
this.minLengthPassword.value = data.toObject().minLength;
if (policy.minLength) {
validators.push(Validators.minLength(policy.minLength));
this.policy = data.toObject();
if (this.policy.minLength) {
validators.push(Validators.minLength(this.policy.minLength));
}
if (policy.hasLowercase) {
if (this.policy.hasLowercase) {
validators.push(Validators.pattern(/[a-z]/g));
}
if (policy.hasUppercase) {
if (this.policy.hasUppercase) {
validators.push(Validators.pattern(/[A-Z]/g));
}
if (policy.hasNumber) {
if (this.policy.hasNumber) {
validators.push(Validators.pattern(/[0-9]/g));
}
if (policy.hasSymbol) {
if (this.policy.hasSymbol) {
// All characters that are not a digit or an English letter \W or a whitespace \S
validators.push(Validators.pattern(/[\W\S]/));
}
@@ -266,6 +267,12 @@ export class AuthUserDetailComponent implements OnDestroy {
}
private async getData(): Promise<void> {
// this.mgmtUserService.GetUserByID(id).then(user => {
// console.log(user.toObject());
// this.user = user.toObject();
// }).catch(err => {
// console.error(err);
// });
this.profile = (await this.userService.GetMyUserProfile()).toObject();
this.email = (await this.userService.GetMyUserEmail()).toObject();
this.phone = (await this.userService.GetMyUserPhone()).toObject();
@@ -16,10 +16,6 @@
<mat-label>{{ 'USER.PROFILE.NICKNAME' | translate }}</mat-label>
<input matInput formControlName="nickName" />
</mat-form-field>
<mat-form-field class="formfield">
<mat-label>{{ 'USER.PROFILE.DISPLAYNAME' | translate }}</mat-label>
<input matInput formControlName="displayName" />
</mat-form-field>
<mat-form-field class="formfield">
<mat-label>{{ 'USER.PROFILE.GENDER' | translate }}</mat-label>
<mat-select formControlName="gender">
@@ -27,7 +27,6 @@ export class DetailFormComponent implements OnInit, OnDestroy {
firstName: [{ value: '', disabled: this.disabled }, Validators.required],
lastName: [{ value: '', disabled: this.disabled }, Validators.required],
nickName: [{ value: '', disabled: this.disabled }],
displayName: [{ value: '', disabled: this.disabled }],
gender: [{ value: 0 }, { disabled: this.disabled }],
preferredLanguage: [{ value: '', disabled: this.disabled }],
});
@@ -62,9 +61,6 @@ export class DetailFormComponent implements OnInit, OnDestroy {
public get nickName(): AbstractControl | null {
return this.profileForm.get('nickName');
}
public get displayName(): AbstractControl | null {
return this.profileForm.get('displayName');
}
public get gender(): AbstractControl | null {
return this.profileForm.get('gender');
}
@@ -16,6 +16,7 @@ import { HasRoleModule } from 'src/app/directives/has-role/has-role.module';
import { CardModule } from 'src/app/modules/card/card.module';
import { ChangesModule } from 'src/app/modules/changes/changes.module';
import { MetaLayoutModule } from 'src/app/modules/meta-layout/meta-layout.module';
import { PipesModule } from 'src/app/pipes/pipes.module';
import { AuthUserDetailComponent } from './auth-user-detail/auth-user-detail.component';
import { AuthUserMfaComponent } from './auth-user-mfa/auth-user-mfa.component';
@@ -47,6 +48,7 @@ import { UserMfaComponent } from './user-mfa/user-mfa.component';
MatDialogModule,
QRCodeModule,
MetaLayoutModule,
PipesModule,
MatFormFieldModule,
UserGrantsModule,
CodeDialogModule,
@@ -1,23 +1,23 @@
<app-meta-layout>
<div *ngIf="profile" class="max-width-container">
<div *ngIf="user" class="max-width-container">
<div class="head">
<a (click)="navigateBack()" mat-icon-button>
<mat-icon class="icon">arrow_back</mat-icon>
</a>
<h1>{{ 'USER.PROFILE.TITLE' | translate }} {{profile?.firstName}}</h1>
<h1>{{ 'USER.PROFILE.TITLE' | translate }} {{user?.firstName}}</h1>
<p class="desc">{{ 'USER.PROFILE.DESCRIPTION' | translate }}</p>
</div>
<mat-progress-bar *ngIf="loading" color="accent" mode="indeterminate"></mat-progress-bar>
<ng-template appHasRole [appHasRole]="['user.read', 'user.read:'+profile?.id]">
<ng-template appHasRole [appHasRole]="['user.read', 'user.read:'+user?.id]">
<app-card title="{{ 'USER.PROFILE.TITLE' | translate }}"
description="{{'USER.PROFILE.DESCRIPTION' | translate}}">
<app-detail-form
*ngIf="((authUserService.isAllowed(['user.write:' + profile?.id, 'user.write']) | async) || false) as canwrite"
[disabled]="canwrite" [genders]="genders" [languages]="languages" [profile]="profile"
*ngIf="((authUserService.isAllowed(['user.write:' + user?.id, 'user.write']) | async) || false) as canwrite"
[disabled]="canwrite" [genders]="genders" [languages]="languages" [profile]="user"
(submitData)="saveProfile($event)">
</app-detail-form>
</app-card>
@@ -26,11 +26,12 @@
<app-card title="{{'USER.PASSWORD.TITLE' | translate}}"
description="{{'USER.PASSWORD.DESCRIPTION' | translate}}">
<card-actions class="card-actions">
<button mat-stroked-button color="primary"
<button *ngIf="user.state === UserState.USERSTATE_INITIAL" mat-stroked-button color="primary"
(click)="sendSetPasswordNotification()">{{ 'USER.PASSWORD.RESENDNOTIFICATION' | translate }}</button>
</card-actions>
<form *ngIf="passwordForm" autocomplete="new-password" [formGroup]="passwordForm"
(ngSubmit)="setInitialPassword()">
<!-- {{USERSTATE_INITIAL}} -->
<div class="content center">
<mat-form-field class="formfield">
<mat-label>{{ 'USER.PASSWORD.NEW' | translate }}</mat-label>
@@ -38,9 +39,9 @@
<mat-error *ngIf="password?.errors?.required">{{ 'USER.VALIDATION.REQUIRED' | translate }}
</mat-error>
<mat-error *ngIf="password?.errors?.minlength">
{{ 'USER.PASSWORD.MINLENGTHERROR' | translate: minLengthPassword }}
{{ 'USER.VALIDATION.MINLENGTH' | translate: policy }}
</mat-error>
<mat-error *ngIf="password?.errors?.pattern">{{ 'USER.VALIDATION.INVALIDPATTERN' | translate }}
<mat-error *ngIf="password?.errors?.pattern">{{ policy | passwordPattern | translate }}
</mat-error>
</mat-form-field>
<mat-form-field class="formfield">
@@ -51,7 +52,9 @@
{{ 'USER.VALIDATION.REQUIRED' | translate }}
</mat-error>
<mat-error *ngIf="confirmPassword?.errors?.minlength">
{{ 'USER.PASSWORD.MINLENGTHERROR' | translate: minLengthPassword }}
{{ 'USER.VALIDATION.MINLENGTH' | translate: policy }}
</mat-error>
<mat-error *ngIf="confirmPassword?.errors?.pattern">{{ policy | passwordPattern | translate }}
</mat-error>
<mat-error *ngIf="confirmPassword?.errors?.notequal">{{ 'USER.PASSWORD.NOTEQUAL' | translate }}
</mat-error>
@@ -72,11 +75,11 @@
<ng-container *ngIf="!emailEditState; else emailEdit">
<div class="actions">
<span class="name">{{email?.email}}</span>
<mat-icon *ngIf="email?.isEmailVerified" color="primary" aria-hidden="false"
<span class="name">{{user?.email}}</span>
<mat-icon *ngIf="user?.isEmailVerified" color="primary" aria-hidden="false"
aria-label="verified icon">
check_circle_outline</mat-icon>
<ng-container *ngIf="email?.email && !email?.isEmailVerified">
<ng-container *ngIf="user?.email && !user?.isEmailVerified">
<mat-icon color="warn" aria-hidden="false" aria-label="not verified icon">highlight_off
</mat-icon>
<a class="verify" matTooltip="{{'USER.LOGINMETHODS.EMAIL.RESEND' | translate}}"
@@ -93,12 +96,12 @@
<ng-template #emailEdit>
<mat-form-field class="name">
<mat-label>{{ 'USER.EMAIL' | translate }}</mat-label>
<input matInput [(ngModel)]="email.email" />
<input matInput [(ngModel)]="user.email" />
</mat-form-field>
<button (click)="emailEditState = false" mat-icon-button>
<mat-icon>close</mat-icon>
</button>
<button [disabled]="!email.email" class="submit-button" type="button" color="primary"
<button [disabled]="!user.email" class="submit-button" type="button" color="primary"
(click)="saveEmail()" mat-raised-button>{{ 'ACTIONS.SAVE' | translate }}</button>
</ng-template>
</div>
@@ -108,11 +111,11 @@
<ng-container *ngIf="!phoneEditState; else phoneEdit">
<div class="actions">
<span class="name">{{phone?.phone}}</span>
<mat-icon *ngIf="phone?.isPhoneVerified" color="primary" aria-hidden="false"
<span class="name">{{user?.phone}}</span>
<mat-icon *ngIf="user?.isPhoneVerified" color="primary" aria-hidden="false"
aria-label="verified icon">
check_circle_outline</mat-icon>
<ng-container *ngIf="phone?.phone && !phone?.isPhoneVerified">
<ng-container *ngIf="user?.phone && !user?.isPhoneVerified">
<mat-icon color="warn" aria-hidden="false" aria-label="not verified icon">highlight_off
</mat-icon>
@@ -125,7 +128,7 @@
<button (click)="phoneEditState = true" mat-icon-button>
<mat-icon>edit</mat-icon>
</button>
<button *ngIf="phone?.phone" (click)="deletePhone()" mat-icon-button>
<button *ngIf="user?.phone" (click)="deletePhone()" mat-icon-button>
<mat-icon>delete_outline</mat-icon>
</button>
</div>
@@ -134,19 +137,19 @@
<ng-template #phoneEdit>
<mat-form-field class="name">
<mat-label>{{ 'USER.PHONE' | translate }}</mat-label>
<input matInput [(ngModel)]="phone.phone" />
<input matInput [(ngModel)]="user.phone" />
</mat-form-field>
<button (click)="phoneEditState = false" mat-icon-button>
<mat-icon>close</mat-icon>
</button>
<button [disabled]="!phone.phone" type="button" color="primary" (click)="savePhone()"
<button [disabled]="!user.phone" type="button" color="primary" (click)="savePhone()"
mat-raised-button>{{ 'ACTIONS.SAVE' | translate }}</button>
</ng-template>
</div>
</div>
</app-card>
<app-auth-user-mfa *ngIf="profile" [profile]="profile"></app-auth-user-mfa>
<app-auth-user-mfa *ngIf="user" [profile]="user"></app-auth-user-mfa>
<app-card title="{{ 'USER.ADDRESS.TITLE' | translate }}">
<form [formGroup]="addressForm" (ngSubmit)="saveAddress()">
@@ -178,14 +181,14 @@
</form>
</app-card>
<app-card *ngIf="profile?.id" title="{{ 'USER.GRANTS.TITLE' | translate }}"
<app-card *ngIf="user?.id" title="{{ 'USER.GRANTS.TITLE' | translate }}"
description="{{'USER.GRANTS.DESCRIPTION' | translate }}">
<app-user-grants [userId]="profile?.id"></app-user-grants>
<app-user-grants [userId]="user?.id"></app-user-grants>
</app-card>
</div>
<metainfo *ngIf="profile" class="side">
<metainfo *ngIf="user" class="side">
<p class="side-section">{{ 'CHANGES.USER.TITLE' | translate }}</p>
<app-changes [changeType]="ChangeType.USER" [id]="profile.id"></app-changes>
<app-changes [changeType]="ChangeType.USER" [id]="user.id"></app-changes>
</metainfo>
</app-meta-layout>
@@ -10,10 +10,12 @@ import {
Gender,
NotificationType,
PasswordComplexityPolicy,
User,
UserAddress,
UserEmail,
UserPhone,
UserProfile,
UserState,
} from 'src/app/proto/generated/management_pb';
import { AuthUserService } from 'src/app/services/auth-user.service';
import { MgmtUserService } from 'src/app/services/mgmt-user.service';
@@ -43,9 +45,9 @@ function passwordConfirmValidator(c: AbstractControl): any {
styleUrls: ['./user-detail.component.scss'],
})
export class UserDetailComponent implements OnInit, OnDestroy {
public profile!: UserProfile.AsObject;
public email: UserEmail.AsObject = { email: '' } as any;
public phone: UserPhone.AsObject = { phone: '' } as any;
public user!: User.AsObject;
// public email: UserEmail.AsObject = { email: '' } as any;
// public phone: UserPhone.AsObject = { phone: '' } as any;
public address: UserAddress.AsObject = { id: '' } as any;
public genders: Gender[] = [Gender.GENDER_MALE, Gender.GENDER_FEMALE, Gender.GENDER_DIVERSE];
public languages: string[] = ['de', 'en'];
@@ -61,10 +63,8 @@ export class UserDetailComponent implements OnInit, OnDestroy {
public ChangeType: any = ChangeType;
public loading: boolean = false;
public minLengthPassword: any = {
value: 0,
};
public UserState: any = UserState;
public policy!: PasswordComplexityPolicy.AsObject;
constructor(
public translate: TranslateService,
private route: ActivatedRoute,
@@ -77,22 +77,22 @@ export class UserDetailComponent implements OnInit, OnDestroy {
public authUserService: AuthUserService,
) {
const validators: Validators[] = [Validators.required];
this.orgService.GetPasswordComplexityPolicy().then(data => {
const policy: PasswordComplexityPolicy.AsObject = data.toObject();
this.minLengthPassword.value = data.toObject().minLength;
if (policy.minLength) {
validators.push(Validators.minLength(policy.minLength));
this.policy = data.toObject();
if (this.policy.minLength) {
validators.push(Validators.minLength(this.policy.minLength));
}
if (policy.hasLowercase) {
if (this.policy.hasLowercase) {
validators.push(Validators.pattern(/[a-z]/g));
}
if (policy.hasUppercase) {
if (this.policy.hasUppercase) {
validators.push(Validators.pattern(/[A-Z]/g));
}
if (policy.hasNumber) {
if (this.policy.hasNumber) {
validators.push(Validators.pattern(/[0-9]/g));
}
if (policy.hasSymbol) {
if (this.policy.hasSymbol) {
// All characters that are not a digit or an English letter \W or a whitespace \S
validators.push(Validators.pattern(/[\W\S]/));
}
@@ -101,7 +101,6 @@ export class UserDetailComponent implements OnInit, OnDestroy {
password: ['', validators],
confirmPassword: ['', [...validators, passwordConfirmValidator]],
});
// TODO custom validator for pattern
}).catch(error => {
console.log('no password complexity policy defined!');
this.passwordForm = this.fb.group({
@@ -135,14 +134,14 @@ export class UserDetailComponent implements OnInit, OnDestroy {
}
public deletePhone(): void {
this.phone.phone = '';
this.user.phone = '';
this.savePhone();
}
public enterCode(): void {
const dialogRef = this.dialog.open(CodeDialogComponent, {
data: {
number: this.phone.phone,
number: this.user.phone,
},
});
@@ -154,17 +153,18 @@ export class UserDetailComponent implements OnInit, OnDestroy {
}
public saveProfile(profileData: UserProfile.AsObject): void {
this.profile.firstName = profileData.firstName;
this.profile.lastName = profileData.lastName;
this.profile.nickName = profileData.nickName;
this.profile.displayName = profileData.displayName;
this.profile.gender = profileData.gender;
this.profile.preferredLanguage = profileData.preferredLanguage;
this.user.firstName = profileData.firstName;
this.user.lastName = profileData.lastName;
this.user.nickName = profileData.nickName;
this.user.displayName = profileData.displayName;
this.user.gender = profileData.gender;
this.user.preferredLanguage = profileData.preferredLanguage;
console.log(this.user);
this.mgmtUserService
.SaveUserProfile(this.profile)
.SaveUserProfile(this.user)
.then((data: UserProfile) => {
this.toast.showInfo('Saved Profile');
this.profile = data.toObject();
this.user = Object.assign(this.user, data.toObject());
})
.catch(data => {
this.toast.showError(data.message);
@@ -173,7 +173,7 @@ export class UserDetailComponent implements OnInit, OnDestroy {
public resendVerification(): void {
console.log('resendverification');
this.mgmtUserService.ResendEmailVerification(this.profile.id).then(() => {
this.mgmtUserService.ResendEmailVerification(this.user.id).then(() => {
this.toast.showInfo('Email was successfully sent!');
}).catch(data => {
this.toast.showError(data.message);
@@ -181,7 +181,7 @@ export class UserDetailComponent implements OnInit, OnDestroy {
}
public resendPhoneVerification(): void {
this.mgmtUserService.ResendPhoneVerification(this.profile.id).then(() => {
this.mgmtUserService.ResendPhoneVerification(this.user.id).then(() => {
this.toast.showInfo('Phoneverification was successfully sent!');
}).catch(data => {
this.toast.showError(data.message);
@@ -190,9 +190,9 @@ export class UserDetailComponent implements OnInit, OnDestroy {
public setInitialPassword(): void {
if (this.passwordForm.valid && this.password && this.password.value) {
this.mgmtUserService.SetInitialPassword(this.profile.id, this.password.value).then((data: any) => {
this.mgmtUserService.SetInitialPassword(this.user.id, this.password.value).then((data: any) => {
this.toast.showInfo('Set initial Password');
this.email = data.toObject();
this.user.email = data.toObject();
}).catch(data => {
this.toast.showError(data.message);
});
@@ -200,10 +200,10 @@ export class UserDetailComponent implements OnInit, OnDestroy {
}
public sendSetPasswordNotification(): void {
this.mgmtUserService.SendSetPasswordNotification(this.profile.id, NotificationType.NOTIFICATIONTYPE_EMAIL)
this.mgmtUserService.SendSetPasswordNotification(this.user.id, NotificationType.NOTIFICATIONTYPE_EMAIL)
.then((data: any) => {
this.toast.showInfo('Set initial Password');
this.email = data.toObject();
this.user.email = data.toObject();
}).catch(data => {
this.toast.showError(data.message);
});
@@ -212,9 +212,9 @@ export class UserDetailComponent implements OnInit, OnDestroy {
public saveEmail(): void {
this.emailEditState = false;
this.mgmtUserService
.SaveUserEmail(this.email).then((data: UserEmail) => {
.SaveUserEmail(this.user.id, this.user.email).then((data: UserEmail) => {
this.toast.showInfo('Saved Email');
this.email = data.toObject();
this.user.email = data.toObject().email;
}).catch(data => {
this.toast.showError(data.message);
});
@@ -222,13 +222,10 @@ export class UserDetailComponent implements OnInit, OnDestroy {
public savePhone(): void {
this.phoneEditState = false;
if (!this.phone.id) {
this.phone.id = this.profile.id;
}
this.mgmtUserService
.SaveUserPhone(this.phone).then((data: UserPhone) => {
.SaveUserPhone(this.user.id, this.user.phone).then((data: UserPhone) => {
this.toast.showInfo('Saved Phone');
this.phone = data.toObject();
this.user.phone = data.toObject().phone;
}).catch(data => {
this.toast.showError(data.message);
});
@@ -236,7 +233,7 @@ export class UserDetailComponent implements OnInit, OnDestroy {
public saveAddress(): void {
if (!this.address.id) {
this.address.id = this.profile.id;
this.address.id = this.user.id;
}
this.address.streetAddress = this.streetAddress?.value;
@@ -283,9 +280,15 @@ export class UserDetailComponent implements OnInit, OnDestroy {
private async getData({ id }: Params): Promise<void> {
this.isMgmt = true;
this.profile = (await this.mgmtUserService.GetUserProfile(id)).toObject();
this.email = (await this.mgmtUserService.GetUserEmail(id)).toObject();
this.phone = (await this.mgmtUserService.GetUserPhone(id)).toObject();
this.mgmtUserService.GetUserByID(id).then(user => {
console.log(user.toObject());
this.user = user.toObject();
}).catch(err => {
console.error(err);
});
// this.profile = (await this.mgmtUserService.GetUserProfile(id)).toObject();
// this.email = (await this.mgmtUserService.GetUserEmail(id)).toObject();
// this.phone = (await this.mgmtUserService.GetUserPhone(id)).toObject();
this.address = (await this.mgmtUserService.GetUserAddress(id)).toObject();
this.addressForm.patchValue(this.address);
}