Piped/src/components/RegisterPage.vue

73 lines
2.2 KiB
Vue
Raw Normal View History

<template>
2022-07-20 20:20:10 +00:00
<h1 v-t="'titles.register'" class="font-bold text-center my-4" />
<hr />
2022-01-12 12:13:04 +00:00
<div class="text-center">
<form class="children:pb-3">
<div>
<input
v-model="username"
2022-01-12 12:13:04 +00:00
class="input"
type="text"
autocomplete="username"
:placeholder="$t('login.username')"
:aria-label="$t('login.username')"
2022-08-18 11:47:10 +00:00
v-on:keyup.enter="register"
/>
</div>
2022-01-12 12:13:04 +00:00
<div>
<input
v-model="password"
2022-01-12 12:13:04 +00:00
class="input"
type="password"
autocomplete="password"
:placeholder="$t('login.password')"
:aria-label="$t('login.password')"
2022-08-18 11:47:10 +00:00
v-on:keyup.enter="register"
/>
</div>
2022-01-12 12:13:04 +00:00
<div>
<a class="btn w-auto" @click="register" v-t="'titles.register'" />
</div>
</form>
</div>
</template>
<script>
export default {
data() {
return {
username: null,
password: null,
};
},
mounted() {
//TODO: Add Server Side check
if (this.getAuthToken()) {
this.$router.push("/");
}
},
activated() {
document.title = "Register - Piped";
},
methods: {
register() {
2022-08-18 11:47:10 +00:00
if (!this.username || !this.password) return;
if (this.username.includes("@") && !confirm(this.$t("info.register_no_email_note"))) return;
this.fetchJson(this.authApiUrl() + "/register", null, {
method: "POST",
body: JSON.stringify({
username: this.username,
password: this.password,
}),
}).then(resp => {
if (resp.token) {
this.setPreference("authToken" + this.hashCode(this.authApiUrl()), resp.token);
window.location = "/"; // done to bypass cache
} else alert(resp.error);
});
},
},
};
</script>