2021-07-16 22:56:41 +00:00
|
|
|
<template>
|
2023-08-13 17:31:57 +00:00
|
|
|
<h1 v-t="'titles.register'" class="my-4 text-center font-bold" />
|
2022-07-20 20:20:10 +00:00
|
|
|
<hr />
|
2022-01-12 12:13:04 +00:00
|
|
|
<div class="text-center">
|
|
|
|
<form class="children:pb-3">
|
|
|
|
<div>
|
2021-07-16 22:56:41 +00:00
|
|
|
<input
|
2021-10-08 18:52:51 +00:00
|
|
|
v-model="username"
|
2022-01-12 12:13:04 +00:00
|
|
|
class="input"
|
2021-07-16 22:56:41 +00:00
|
|
|
type="text"
|
|
|
|
autocomplete="username"
|
2021-09-21 21:58:25 +00:00
|
|
|
:placeholder="$t('login.username')"
|
|
|
|
:aria-label="$t('login.username')"
|
2023-07-27 11:46:05 +00:00
|
|
|
@keyup.enter="register"
|
2021-07-16 22:56:41 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2022-01-12 12:13:04 +00:00
|
|
|
<div>
|
2021-07-16 22:56:41 +00:00
|
|
|
<input
|
2021-10-08 18:52:51 +00:00
|
|
|
v-model="password"
|
2022-01-12 12:13:04 +00:00
|
|
|
class="input"
|
2021-07-16 22:56:41 +00:00
|
|
|
type="password"
|
|
|
|
autocomplete="password"
|
2021-09-21 21:58:25 +00:00
|
|
|
:placeholder="$t('login.password')"
|
|
|
|
:aria-label="$t('login.password')"
|
2023-07-27 11:46:05 +00:00
|
|
|
@keyup.enter="register"
|
2021-07-16 22:56:41 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2023-08-14 08:03:26 +00:00
|
|
|
<div>
|
|
|
|
<input
|
|
|
|
v-model="passwordConfirm"
|
|
|
|
class="input"
|
|
|
|
type="password"
|
|
|
|
autocomplete="password"
|
|
|
|
:placeholder="$t('login.password_confirm')"
|
|
|
|
:aria-label="$t('login.password_confirm')"
|
|
|
|
@keyup.enter="register"
|
|
|
|
/>
|
|
|
|
</div>
|
2022-01-12 12:13:04 +00:00
|
|
|
<div>
|
2023-07-27 11:46:05 +00:00
|
|
|
<a v-t="'titles.register'" class="btn w-auto" @click="register" />
|
2021-07-16 22:56:41 +00:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
2023-05-30 13:02:20 +00:00
|
|
|
<ConfirmModal
|
|
|
|
v-if="showUnsecureRegisterDialog"
|
2023-07-27 11:46:05 +00:00
|
|
|
:message="$t('info.register_no_email_note')"
|
2023-05-30 13:02:20 +00:00
|
|
|
@close="showUnsecureRegisterDialog = false"
|
|
|
|
@confirm="
|
|
|
|
forceUnsecureRegister = true;
|
|
|
|
showUnsecureRegisterDialog = false;
|
|
|
|
register();
|
|
|
|
"
|
|
|
|
/>
|
2021-07-16 22:56:41 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-11-28 15:06:02 +00:00
|
|
|
import { isEmail } from "../utils/Misc.js";
|
2023-05-30 13:02:20 +00:00
|
|
|
import ConfirmModal from "./ConfirmModal.vue";
|
2022-11-28 15:06:02 +00:00
|
|
|
|
2021-07-16 22:56:41 +00:00
|
|
|
export default {
|
2023-07-27 11:46:05 +00:00
|
|
|
components: { ConfirmModal },
|
2021-07-16 22:56:41 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
username: null,
|
|
|
|
password: null,
|
2023-05-30 13:02:20 +00:00
|
|
|
showUnsecureRegisterDialog: false,
|
|
|
|
forceUnsecureRegister: false,
|
2021-07-16 22:56:41 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
//TODO: Add Server Side check
|
|
|
|
if (this.getAuthToken()) {
|
|
|
|
this.$router.push("/");
|
|
|
|
}
|
|
|
|
},
|
2021-07-21 10:59:53 +00:00
|
|
|
activated() {
|
|
|
|
document.title = "Register - Piped";
|
|
|
|
},
|
2021-07-16 22:56:41 +00:00
|
|
|
methods: {
|
|
|
|
register() {
|
2022-08-18 11:47:10 +00:00
|
|
|
if (!this.username || !this.password) return;
|
2023-08-14 08:03:26 +00:00
|
|
|
if (this.password != this.passwordConfirm) {
|
|
|
|
alert(this.$t("login.passwords_incorrect"));
|
|
|
|
return;
|
|
|
|
}
|
2023-05-30 13:02:20 +00:00
|
|
|
if (isEmail(this.username) && !this.forceUnsecureRegister) {
|
|
|
|
this.showUnsecureRegisterDialog = true;
|
|
|
|
return;
|
|
|
|
}
|
2022-07-21 04:04:57 +00:00
|
|
|
this.fetchJson(this.authApiUrl() + "/register", null, {
|
2021-07-16 22:56:41 +00:00
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
username: this.username,
|
|
|
|
password: this.password,
|
|
|
|
}),
|
|
|
|
}).then(resp => {
|
|
|
|
if (resp.token) {
|
2022-07-21 04:04:57 +00:00
|
|
|
this.setPreference("authToken" + this.hashCode(this.authApiUrl()), resp.token);
|
2021-07-16 22:56:41 +00:00
|
|
|
window.location = "/"; // done to bypass cache
|
|
|
|
} else alert(resp.error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|