Piped/src/components/LoginPage.vue

67 lines
1.9 KiB
Vue
Raw Normal View History

<template>
2022-01-12 12:13:04 +00:00
<div class="text-center">
<h1 v-t="'titles.login'" />
2022-01-12 12:13:04 +00:00
<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')"
/>
</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')"
/>
</div>
2022-01-12 12:13:04 +00:00
<div>
<a class="btn w-auto" @click="login" v-text="$t('titles.login')" />
</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 = this.$t("titles.login") + " - Piped";
},
methods: {
login() {
this.fetchJson(this.apiUrl() + "/login", null, {
method: "POST",
body: JSON.stringify({
username: this.username,
password: this.password,
}),
}).then(resp => {
if (resp.token) {
this.setPreference("authToken" + this.hashCode(this.apiUrl()), resp.token);
window.location = "/"; // done to bypass cache
} else alert(resp.error);
});
},
},
};
</script>