User.email UI
This commit is contained in:
parent
af43204063
commit
43208bf37d
@ -9,6 +9,7 @@ export class UserPrivate extends UserPublic {
|
||||
readonly created: Date,
|
||||
name: string,
|
||||
readonly password: boolean,
|
||||
readonly email: string,
|
||||
admin: boolean,
|
||||
) {
|
||||
super(publicUuid, name, admin);
|
||||
@ -21,6 +22,7 @@ export class UserPrivate extends UserPublic {
|
||||
validateDate(json['created']),
|
||||
validateString(json['name']),
|
||||
validateBoolean(json['password']),
|
||||
validateString(json['email']),
|
||||
validateBoolean(json['admin']),
|
||||
);
|
||||
}
|
||||
|
||||
@ -89,6 +89,10 @@ export class UserService {
|
||||
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) {
|
||||
this.router.navigate(['User', user.publicUuid]);
|
||||
}
|
||||
|
||||
@ -32,6 +32,17 @@
|
||||
</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>
|
||||
|
||||
</ng-container>
|
||||
|
||||
@ -38,6 +38,8 @@ export class ProfileComponent implements OnInit, OnDestroy {
|
||||
|
||||
protected password1: string = "";
|
||||
|
||||
protected email: string = "";
|
||||
|
||||
protected groups: Group[] = [];
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
protected emailValidator(email: string) {
|
||||
return /^\w+([-.]\w+)*@\w+([-.]\w+)*\.\w{2,}$/.test(email);
|
||||
}
|
||||
|
||||
protected p0Invalid(): boolean {
|
||||
return this.password0 !== '' && !this.passwordValidator(this.password0);
|
||||
}
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
<input
|
||||
*ngIf="editable"
|
||||
[(ngModel)]="model"
|
||||
[placeholder]="_placeholder"
|
||||
(focus)="begin()"
|
||||
(blur)="apply()"
|
||||
(keydown.enter)="apply()"
|
||||
(keydown.escape)="abort()"
|
||||
[class.invalid]="validator !== null && !validator(model)"
|
||||
[class.invalid]="model !== _initial && validator !== null && !validator(model)"
|
||||
[class.unsaved]="model !== _initial"
|
||||
>
|
||||
|
||||
|
||||
@ -26,6 +26,18 @@ export class TextComponent implements OnInit {
|
||||
@Input()
|
||||
set initial(value: string) {
|
||||
this._initial = value;
|
||||
this.updateFromOutside();
|
||||
}
|
||||
|
||||
_placeholder: string = '';
|
||||
|
||||
@Input()
|
||||
set placeholder(value: string) {
|
||||
this._placeholder = value;
|
||||
this.updateFromOutside();
|
||||
}
|
||||
|
||||
private updateFromOutside() {
|
||||
if (!this.editing) {
|
||||
this.model = this._initial;
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
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) {
|
||||
return REGEX.matcher(email).matches();
|
||||
@ -19,10 +19,10 @@ public class EmailHelper {
|
||||
if (!matcher.find()) {
|
||||
return "";
|
||||
}
|
||||
final String usernameFirst = matcher.group("usernameFirst");
|
||||
final String domainFirst = matcher.group("domainFirst");
|
||||
final String usernameFirst = matcher.group("username");
|
||||
final String domainFirst = matcher.group("domain");
|
||||
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