Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<template>
<v-container>
<v-dialog width="500" :value="opened" persistent>
<v-card>
<v-card-title>Registrieren</v-card-title>
<v-card-text>
<v-form ref="form">
<v-text-field
label="Accountname"
v-model="accountname"
:rules="accountnameRules"
autofocus
></v-text-field>
<v-text-field
label="Passwort"
v-model="password"
type="password"
:rules="passwordRules"
></v-text-field>
<v-text-field
label="Passwort wiederholen"
v-model="passwordconfirm"
type="password"
:rules="[passwordconfirmRule]"
></v-text-field>
<v-text-field
label="Nickname"
v-model="nickname"
:rules="nicknameRules"
@keyup.enter="register()"
></v-text-field>
<v-text-field
label="E-Mail (optional)"
v-model="email"
:rules="emailRules"
@keyup.enter="register()"
></v-text-field>
</v-form>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn outlined @click="abort()">Abbrechen</v-btn>
<v-btn outlined @click="register()">Registrieren</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-snackbar
v-model="snackbar.opened"
:timeout="snackbar.timeout"
:color="snackbarColor"
>{{ snackbar.text }}</v-snackbar
>
</v-container>
</template>
<script>
import client from "../../services/Client";
export default {
/* eslint-disable no-debugger, no-console */
name: "Register",
data: () => ({
opened: false,
accountname: "",
accountnameRules: [
v => !!v || "Accountname benötigt",
v => (!!v && /^[0-9a-zA-Z_-]+$/.test(v)) || "Dateiname ungültig"
passwordRules: [v => !!v || "Passwort benötigt"],
nicknameRules: [
v => !!v || "Nickname benötigt",
v => (!!v && /^[0-9a-zA-Z_- ]+$/.test(v)) || "Dateiname ungültig"
v => !v || /.+@.+/.test(v) || "Eingabe ist keine gültige E-Mail Adresse"
],
status: "",
snackbar: {
opened: false,
timeout: 3000,
success: false,
}),
computed: {
snackbarColor: function() {
return this.snackbar.success ? "success" : "error";
},
methods: {
showDialog() {
this.opened = true;
},
passwordconfirmRule: function(v) {
return v === this.password || "Passwort stimmt nicht überein";
},
abort: function() {
this.$refs.form.reset();
this.opened = false;
},
register: function() {
if (this.$refs.form.validate()) {
let payload = new FormData();
payload.append("accountname", this.accountname);
payload.append("password", this.password);
payload.append("nickname", this.nickname);
payload.append("email", this.email);
payload.append("status", this.status);
client.post(client.URLs.register, payload).then(result => {
this.snackbar.success = result.success;
this.snackbar.text = result.message;
this.snackbar.opened = true;
if (result.success) {
this.abort();
}
});
}