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 />
|
2023-09-14 15:24:00 +00:00
|
|
|
<div class="flex flex-col items-center justify-center text-center">
|
|
|
|
<form class="w-max items-center px-3 children:pb-3">
|
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="username"
|
2023-08-14 08:21:22 +00:00
|
|
|
class="input w-full"
|
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>
|
2023-08-14 08:21:22 +00:00
|
|
|
<div class="flex justify-center">
|
2021-07-16 22:56:41 +00:00
|
|
|
<input
|
2021-10-08 18:52:51 +00:00
|
|
|
v-model="password"
|
2023-08-14 08:21:22 +00:00
|
|
|
class="input w-full"
|
|
|
|
:type="showPassword ? 'text' : 'password'"
|
2021-07-16 22:56:41 +00:00
|
|
|
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
|
|
|
/>
|
2023-08-14 08:21:22 +00:00
|
|
|
<button type="button" class="btn ml-2" @click="showPassword = !showPassword">
|
|
|
|
<div class="i-fa6-solid:eye" />
|
|
|
|
</button>
|
2021-07-16 22:56:41 +00:00
|
|
|
</div>
|
2023-08-14 08:21:22 +00:00
|
|
|
<div class="flex justify-center">
|
2023-08-14 08:03:26 +00:00
|
|
|
<input
|
|
|
|
v-model="passwordConfirm"
|
2023-08-14 08:21:22 +00:00
|
|
|
class="input w-full"
|
|
|
|
:type="showConfirmPassword ? 'text' : 'password'"
|
2023-08-14 08:03:26 +00:00
|
|
|
autocomplete="password"
|
|
|
|
:placeholder="$t('login.password_confirm')"
|
|
|
|
:aria-label="$t('login.password_confirm')"
|
|
|
|
@keyup.enter="register"
|
|
|
|
/>
|
2023-08-14 08:21:22 +00:00
|
|
|
<button type="button" class="btn ml-2" @click="showConfirmPassword = !showConfirmPassword">
|
|
|
|
<div class="i-fa6-solid:eye" />
|
|
|
|
</button>
|
2023-08-14 08:03:26 +00:00
|
|
|
</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>
|
2023-09-14 15:24:00 +00:00
|
|
|
<TooltipIcon icon="i-fa6-solid:circle-info" :tooltip="$t('info.register_note')" />
|
2021-07-16 22:56:41 +00:00
|
|
|
</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";
|
2023-09-14 15:24:00 +00:00
|
|
|
import TooltipIcon from "./TooltipIcon.vue";
|
2022-11-28 15:06:02 +00:00
|
|
|
|
2021-07-16 22:56:41 +00:00
|
|
|
export default {
|
2023-09-14 15:24:00 +00:00
|
|
|
components: { ConfirmModal, TooltipIcon },
|
2021-07-16 22:56:41 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
username: null,
|
|
|
|
password: null,
|
2023-08-14 08:21:22 +00:00
|
|
|
passwordConfirm: null,
|
|
|
|
showPassword: false,
|
|
|
|
showConfirmPassword: false,
|
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>
|