User.email UI
This commit is contained in:
parent
af43204063
commit
43208bf37d
@ -9,6 +9,7 @@ export class UserPrivate extends UserPublic {
|
|||||||
readonly created: Date,
|
readonly created: Date,
|
||||||
name: string,
|
name: string,
|
||||||
readonly password: boolean,
|
readonly password: boolean,
|
||||||
|
readonly email: string,
|
||||||
admin: boolean,
|
admin: boolean,
|
||||||
) {
|
) {
|
||||||
super(publicUuid, name, admin);
|
super(publicUuid, name, admin);
|
||||||
@ -21,6 +22,7 @@ export class UserPrivate extends UserPublic {
|
|||||||
validateDate(json['created']),
|
validateDate(json['created']),
|
||||||
validateString(json['name']),
|
validateString(json['name']),
|
||||||
validateBoolean(json['password']),
|
validateBoolean(json['password']),
|
||||||
|
validateString(json['email']),
|
||||||
validateBoolean(json['admin']),
|
validateBoolean(json['admin']),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -89,6 +89,10 @@ export class UserService {
|
|||||||
this.api.postSingle(['User', 'changePassword'], password, UserPrivate.fromJson, next);
|
this.api.postSingle(['User', 'changePassword'], password, UserPrivate.fromJson, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
changeEmail(email: string, next?: Next<UserPrivate>) {
|
||||||
|
this.api.postSingle(['User', 'changeEmail'], email, UserPrivate.fromJson, next);
|
||||||
|
}
|
||||||
|
|
||||||
goto(user: UserPublic) {
|
goto(user: UserPublic) {
|
||||||
this.router.navigate(['User', user.publicUuid]);
|
this.router.navigate(['User', user.publicUuid]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="tile">
|
||||||
|
<div class="tileInner">
|
||||||
|
<div class="tileTitle">
|
||||||
|
E-Mail
|
||||||
|
</div>
|
||||||
|
<div class="tileContent">
|
||||||
|
<app-text initial="" [placeholder]="userService.user.email" [editable]="true" (onChange)="userService.changeEmail($event)" [validator]="emailValidator"></app-text>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|||||||
@ -38,6 +38,8 @@ export class ProfileComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
protected password1: string = "";
|
protected password1: string = "";
|
||||||
|
|
||||||
|
protected email: string = "";
|
||||||
|
|
||||||
protected groups: Group[] = [];
|
protected groups: Group[] = [];
|
||||||
|
|
||||||
@ViewChild('p1')
|
@ViewChild('p1')
|
||||||
@ -74,6 +76,10 @@ export class ProfileComponent implements OnInit, OnDestroy {
|
|||||||
return password.length >= USER_PASSWORD_MIN_LENGTH && !/^[a-zA-Z]+$|^[0-9]+$/.test(password);
|
return password.length >= USER_PASSWORD_MIN_LENGTH && !/^[a-zA-Z]+$|^[0-9]+$/.test(password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected emailValidator(email: string) {
|
||||||
|
return /^\w+([-.]\w+)*@\w+([-.]\w+)*\.\w{2,}$/.test(email);
|
||||||
|
}
|
||||||
|
|
||||||
protected p0Invalid(): boolean {
|
protected p0Invalid(): boolean {
|
||||||
return this.password0 !== '' && !this.passwordValidator(this.password0);
|
return this.password0 !== '' && !this.passwordValidator(this.password0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
<input
|
<input
|
||||||
*ngIf="editable"
|
*ngIf="editable"
|
||||||
[(ngModel)]="model"
|
[(ngModel)]="model"
|
||||||
|
[placeholder]="_placeholder"
|
||||||
(focus)="begin()"
|
(focus)="begin()"
|
||||||
(blur)="apply()"
|
(blur)="apply()"
|
||||||
(keydown.enter)="apply()"
|
(keydown.enter)="apply()"
|
||||||
(keydown.escape)="abort()"
|
(keydown.escape)="abort()"
|
||||||
[class.invalid]="validator !== null && !validator(model)"
|
[class.invalid]="model !== _initial && validator !== null && !validator(model)"
|
||||||
[class.unsaved]="model !== _initial"
|
[class.unsaved]="model !== _initial"
|
||||||
>
|
>
|
||||||
|
|
||||||
|
|||||||
@ -26,6 +26,18 @@ export class TextComponent implements OnInit {
|
|||||||
@Input()
|
@Input()
|
||||||
set initial(value: string) {
|
set initial(value: string) {
|
||||||
this._initial = value;
|
this._initial = value;
|
||||||
|
this.updateFromOutside();
|
||||||
|
}
|
||||||
|
|
||||||
|
_placeholder: string = '';
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
set placeholder(value: string) {
|
||||||
|
this._placeholder = value;
|
||||||
|
this.updateFromOutside();
|
||||||
|
}
|
||||||
|
|
||||||
|
private updateFromOutside() {
|
||||||
if (!this.editing) {
|
if (!this.editing) {
|
||||||
this.model = this._initial;
|
this.model = this._initial;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
public class EmailHelper {
|
public class EmailHelper {
|
||||||
|
|
||||||
private static final Pattern REGEX = Pattern.compile("(?<username>(?<usernameFirst>[^@])[^@]*)@(?<domain>(?<domainFirst>[^.]).*(?<tld>\\.[^.]+))");
|
private static final Pattern REGEX = Pattern.compile("(?<username>\\w+(?:[-.]\\w+)*)@(?<domain>\\w+(?:[-.]\\w+)*)\\.(?<tld>\\w{2,})");
|
||||||
|
|
||||||
public static boolean isEmailValid(@NonNull final String email) {
|
public static boolean isEmailValid(@NonNull final String email) {
|
||||||
return REGEX.matcher(email).matches();
|
return REGEX.matcher(email).matches();
|
||||||
@ -19,10 +19,10 @@ public class EmailHelper {
|
|||||||
if (!matcher.find()) {
|
if (!matcher.find()) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
final String usernameFirst = matcher.group("usernameFirst");
|
final String usernameFirst = matcher.group("username");
|
||||||
final String domainFirst = matcher.group("domainFirst");
|
final String domainFirst = matcher.group("domain");
|
||||||
final String tld = matcher.group("tld");
|
final String tld = matcher.group("tld");
|
||||||
return "%s...@%s...%s".formatted(usernameFirst, domainFirst, tld);
|
return "%s...@%s...%s".formatted(usernameFirst.charAt(0), domainFirst.charAt(0), tld);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user