fix registration

This commit is contained in:
_Bastler 2022-11-24 12:41:04 +01:00
parent 88bd69cbc6
commit 7391ff1147

View File

@ -19,7 +19,7 @@ var openpgp = require('openpgp');
@Component({ @Component({
selector: 'app-register', selector: 'app-register',
templateUrl: './register.component.html', templateUrl: './register.component.html',
styleUrls: [ './register.component.scss' ] styleUrls: ['./register.component.scss']
}) })
export class RegisterComponent implements OnInit { export class RegisterComponent implements OnInit {
@ -51,11 +51,11 @@ export class RegisterComponent implements OnInit {
async ngOnInit() { async ngOnInit() {
this.form = this.formBuilder.group({ this.form = this.formBuilder.group({
username: [ '', Validators.required ], username: ['', Validators.required],
email: [ '', Validators.email ], email: ['', Validators.email],
primaryEmail: [ false, Validators.nullValidator ], primaryEmail: [false, Validators.nullValidator],
password: [ '', Validators.nullValidator ], password: ['', Validators.nullValidator],
password2: [ '', Validators.required ] password2: ['', Validators.required]
}, { }, {
validator: MatchingValidator('password', 'password2') validator: MatchingValidator('password', 'password2')
}); });
@ -84,7 +84,7 @@ export class RegisterComponent implements OnInit {
mailControl.clearAsyncValidators(); mailControl.clearAsyncValidators();
mailControl.clearValidators(); mailControl.clearValidators();
if (this.model.primaryEmail) { if (this.model.primaryEmail) {
mailControl.setValidators([ Validators.email, Validators.required ]); mailControl.setValidators([Validators.email, Validators.required]);
} }
mailControl.updateValueAndValidity(); mailControl.updateValueAndValidity();
} }
@ -92,7 +92,7 @@ export class RegisterComponent implements OnInit {
genUsername() { genUsername() {
const config: Config = { const config: Config = {
dictionaries: [ adjectives, colors, animals ], dictionaries: [adjectives, colors, animals],
separator: "", separator: "",
style: "capital", style: "capital",
length: 3 length: 3
@ -107,14 +107,14 @@ export class RegisterComponent implements OnInit {
if (this.form.valid && !this.working) { if (this.form.valid && !this.working) {
this.working = true; this.working = true;
let pgpOption = { let pgpOption = {
userIds: [ { name: this.model.username, email: this.model.username + "@we.bstly.de" } ], userIDs: [{ name: this.model.username, email: this.model.username + "@we.bstly.de" }],
curve: "ed25519", curve: "ed25519",
} }
var pubKey, privKey var pubKey, privKey
openpgp.generateKey(pgpOption).then((key) => { openpgp.generateKey(pgpOption).then((key) => {
privKey = key.privateKeyArmored; privKey = key.privateKey;
pubKey = key.publicKeyArmored; pubKey = key.publicKey;
this.model.profileFields = [ this.model.profileFields = [
{ "name": "publicKey", "type": "BLOB", "visibility": "PROTECTED", "blob": pubKey } { "name": "publicKey", "type": "BLOB", "visibility": "PROTECTED", "blob": pubKey }
@ -154,12 +154,13 @@ export class RegisterComponent implements OnInit {
} else if (error.status == 409) { } else if (error.status == 409) {
let errors = {}; let errors = {};
for (let code of error.error) { for (let code of error.error) {
errors[ code.field ] = errors[ code.field ] || {}; errors[code.field] = errors[code.field] || {};
errors[ code.field ][ code.code ] = true; errors[code.field][code.code] = true;
} }
for (let code in errors) { for (let code in errors) {
this.form.get(code).setErrors(errors[ code ]); console.warn(code, errors[code]);
this.form.get(code).setErrors(errors[code]);
} }
} }
} }
@ -174,7 +175,7 @@ export class RegisterComponent implements OnInit {
@Component({ @Component({
selector: 'app-register-dialog', selector: 'app-register-dialog',
templateUrl: 'register.dialog.html', templateUrl: 'register.dialog.html',
styleUrls: [ './register.dialog.scss' ] styleUrls: ['./register.dialog.scss']
}) })
export class RegisterDialog { export class RegisterDialog {