2018-02-09 23:22:14 -08:00
|
|
|
<template>
|
2022-06-09 07:42:00 -07:00
|
|
|
<form class="qlvuhzng _formRoot" autocomplete="new-password" @submit.prevent="onSubmit">
|
2022-07-15 01:14:05 -07:00
|
|
|
<MkInput v-if="instance.disableRegistration" v-model="invitationCode" class="_formBlock" type="text" :spellcheck="false" required>
|
2022-07-20 06:24:26 -07:00
|
|
|
<template #label>{{ i18n.ts.invitationCode }}</template>
|
2022-12-19 02:01:30 -08:00
|
|
|
<template #prefix><i class="ti ti-key"></i></template>
|
2022-07-15 01:14:05 -07:00
|
|
|
</MkInput>
|
2022-12-21 23:51:48 -08:00
|
|
|
<MkInput v-model="username" class="_formBlock" type="text" pattern="^[a-zA-Z0-9_]{1,20}$" :spellcheck="false" required data-cy-signup-username @update:model-value="onChangeUsername">
|
2022-12-19 22:24:31 -08:00
|
|
|
<template #label>{{ i18n.ts.username }} <div v-tooltip:dialog="i18n.ts.usernameInfo" class="_button _help"><i class="ti ti-question-circle"></i></div></template>
|
2022-07-15 01:14:05 -07:00
|
|
|
<template #prefix>@</template>
|
|
|
|
<template #suffix>@{{ host }}</template>
|
|
|
|
<template #caption>
|
2022-12-19 18:00:05 -08:00
|
|
|
<span v-if="usernameState === 'wait'" style="color:#999"><MkLoading :em="true"/> {{ i18n.ts.checking }}</span>
|
2022-12-19 02:01:30 -08:00
|
|
|
<span v-else-if="usernameState === 'ok'" style="color: var(--success)"><i class="ti ti-check ti-fw"></i> {{ i18n.ts.available }}</span>
|
|
|
|
<span v-else-if="usernameState === 'unavailable'" style="color: var(--error)"><i class="ti ti-alert-triangle ti-fw"></i> {{ i18n.ts.unavailable }}</span>
|
|
|
|
<span v-else-if="usernameState === 'error'" style="color: var(--error)"><i class="ti ti-alert-triangle ti-fw"></i> {{ i18n.ts.error }}</span>
|
|
|
|
<span v-else-if="usernameState === 'invalid-format'" style="color: var(--error)"><i class="ti ti-alert-triangle ti-fw"></i> {{ i18n.ts.usernameInvalidFormat }}</span>
|
|
|
|
<span v-else-if="usernameState === 'min-range'" style="color: var(--error)"><i class="ti ti-alert-triangle ti-fw"></i> {{ i18n.ts.tooShort }}</span>
|
|
|
|
<span v-else-if="usernameState === 'max-range'" style="color: var(--error)"><i class="ti ti-alert-triangle ti-fw"></i> {{ i18n.ts.tooLong }}</span>
|
2022-07-15 01:14:05 -07:00
|
|
|
</template>
|
|
|
|
</MkInput>
|
2022-12-21 23:51:48 -08:00
|
|
|
<MkInput v-if="instance.emailRequiredForSignup" v-model="email" class="_formBlock" :debounce="true" type="email" :spellcheck="false" required data-cy-signup-email @update:model-value="onChangeEmail">
|
2022-12-19 22:24:31 -08:00
|
|
|
<template #label>{{ i18n.ts.emailAddress }} <div v-tooltip:dialog="i18n.ts._signup.emailAddressInfo" class="_button _help"><i class="ti ti-question-circle"></i></div></template>
|
2022-12-19 02:01:30 -08:00
|
|
|
<template #prefix><i class="ti ti-mail"></i></template>
|
2022-07-15 01:14:05 -07:00
|
|
|
<template #caption>
|
2022-12-19 18:00:05 -08:00
|
|
|
<span v-if="emailState === 'wait'" style="color:#999"><MkLoading :em="true"/> {{ i18n.ts.checking }}</span>
|
2022-12-19 02:01:30 -08:00
|
|
|
<span v-else-if="emailState === 'ok'" style="color: var(--success)"><i class="ti ti-check ti-fw"></i> {{ i18n.ts.available }}</span>
|
|
|
|
<span v-else-if="emailState === 'unavailable:used'" style="color: var(--error)"><i class="ti ti-alert-triangle ti-fw"></i> {{ i18n.ts._emailUnavailable.used }}</span>
|
|
|
|
<span v-else-if="emailState === 'unavailable:format'" style="color: var(--error)"><i class="ti ti-alert-triangle ti-fw"></i> {{ i18n.ts._emailUnavailable.format }}</span>
|
|
|
|
<span v-else-if="emailState === 'unavailable:disposable'" style="color: var(--error)"><i class="ti ti-alert-triangle ti-fw"></i> {{ i18n.ts._emailUnavailable.disposable }}</span>
|
|
|
|
<span v-else-if="emailState === 'unavailable:mx'" style="color: var(--error)"><i class="ti ti-alert-triangle ti-fw"></i> {{ i18n.ts._emailUnavailable.mx }}</span>
|
|
|
|
<span v-else-if="emailState === 'unavailable:smtp'" style="color: var(--error)"><i class="ti ti-alert-triangle ti-fw"></i> {{ i18n.ts._emailUnavailable.smtp }}</span>
|
|
|
|
<span v-else-if="emailState === 'unavailable'" style="color: var(--error)"><i class="ti ti-alert-triangle ti-fw"></i> {{ i18n.ts.unavailable }}</span>
|
|
|
|
<span v-else-if="emailState === 'error'" style="color: var(--error)"><i class="ti ti-alert-triangle ti-fw"></i> {{ i18n.ts.error }}</span>
|
2022-07-15 01:14:05 -07:00
|
|
|
</template>
|
|
|
|
</MkInput>
|
2022-12-21 23:51:48 -08:00
|
|
|
<MkInput v-model="password" class="_formBlock" type="password" autocomplete="new-password" required data-cy-signup-password @update:model-value="onChangePassword">
|
2022-07-20 06:24:26 -07:00
|
|
|
<template #label>{{ i18n.ts.password }}</template>
|
2022-12-19 02:01:30 -08:00
|
|
|
<template #prefix><i class="ti ti-lock"></i></template>
|
2022-07-15 01:14:05 -07:00
|
|
|
<template #caption>
|
2022-12-19 02:01:30 -08:00
|
|
|
<span v-if="passwordStrength == 'low'" style="color: var(--error)"><i class="ti ti-alert-triangle ti-fw"></i> {{ i18n.ts.weakPassword }}</span>
|
|
|
|
<span v-if="passwordStrength == 'medium'" style="color: var(--warn)"><i class="ti ti-check ti-fw"></i> {{ i18n.ts.normalPassword }}</span>
|
|
|
|
<span v-if="passwordStrength == 'high'" style="color: var(--success)"><i class="ti ti-check ti-fw"></i> {{ i18n.ts.strongPassword }}</span>
|
2022-07-15 01:14:05 -07:00
|
|
|
</template>
|
|
|
|
</MkInput>
|
2022-12-21 23:51:48 -08:00
|
|
|
<MkInput v-model="retypedPassword" class="_formBlock" type="password" autocomplete="new-password" required data-cy-signup-password-retype @update:model-value="onChangePasswordRetype">
|
2022-07-20 06:24:26 -07:00
|
|
|
<template #label>{{ i18n.ts.password }} ({{ i18n.ts.retype }})</template>
|
2022-12-19 02:01:30 -08:00
|
|
|
<template #prefix><i class="ti ti-lock"></i></template>
|
2022-07-15 01:14:05 -07:00
|
|
|
<template #caption>
|
2022-12-19 02:01:30 -08:00
|
|
|
<span v-if="passwordRetypeState == 'match'" style="color: var(--success)"><i class="ti ti-check ti-fw"></i> {{ i18n.ts.passwordMatched }}</span>
|
|
|
|
<span v-if="passwordRetypeState == 'not-match'" style="color: var(--error)"><i class="ti ti-alert-triangle ti-fw"></i> {{ i18n.ts.passwordNotMatched }}</span>
|
2022-07-15 01:14:05 -07:00
|
|
|
</template>
|
|
|
|
</MkInput>
|
|
|
|
<MkSwitch v-if="instance.tosUrl" v-model="ToSAgreement" class="_formBlock tou">
|
2022-07-20 06:24:26 -07:00
|
|
|
<I18n :src="i18n.ts.agreeTo">
|
2022-07-15 01:14:05 -07:00
|
|
|
<template #0>
|
2022-07-20 06:24:26 -07:00
|
|
|
<a :href="instance.tosUrl" class="_link" target="_blank">{{ i18n.ts.tos }}</a>
|
2021-10-07 21:37:02 -07:00
|
|
|
</template>
|
2022-07-15 01:14:05 -07:00
|
|
|
</I18n>
|
|
|
|
</MkSwitch>
|
|
|
|
<MkCaptcha v-if="instance.enableHcaptcha" ref="hcaptcha" v-model="hCaptchaResponse" class="_formBlock captcha" provider="hcaptcha" :sitekey="instance.hcaptchaSiteKey"/>
|
|
|
|
<MkCaptcha v-if="instance.enableRecaptcha" ref="recaptcha" v-model="reCaptchaResponse" class="_formBlock captcha" provider="recaptcha" :sitekey="instance.recaptchaSiteKey"/>
|
2022-10-12 17:19:57 -07:00
|
|
|
<MkCaptcha v-if="instance.enableTurnstile" ref="turnstile" v-model="turnstileResponse" class="_formBlock captcha" provider="turnstile" :sitekey="instance.turnstileSiteKey"/>
|
2022-07-20 06:24:26 -07:00
|
|
|
<MkButton class="_formBlock" type="submit" :disabled="shouldDisableSubmitting" gradate data-cy-signup-submit>{{ i18n.ts.start }}</MkButton>
|
2018-02-09 23:22:14 -08:00
|
|
|
</form>
|
|
|
|
</template>
|
|
|
|
|
2022-07-15 01:14:05 -07:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { } from 'vue';
|
2022-06-24 05:19:38 -07:00
|
|
|
import getPasswordStrength from 'syuilo-password-strength';
|
2021-04-03 21:00:39 -07:00
|
|
|
import { toUnicode } from 'punycode/';
|
2022-09-06 02:21:49 -07:00
|
|
|
import MkButton from './MkButton.vue';
|
2021-09-29 08:50:45 -07:00
|
|
|
import MkInput from './form/input.vue';
|
|
|
|
import MkSwitch from './form/switch.vue';
|
2022-08-30 08:24:33 -07:00
|
|
|
import MkCaptcha from '@/components/MkCaptcha.vue';
|
2022-07-15 01:14:05 -07:00
|
|
|
import * as config from '@/config';
|
2021-11-11 09:02:25 -08:00
|
|
|
import * as os from '@/os';
|
|
|
|
import { login } from '@/account';
|
2022-07-15 01:14:05 -07:00
|
|
|
import { instance } from '@/instance';
|
|
|
|
import { i18n } from '@/i18n';
|
2018-02-09 23:22:14 -08:00
|
|
|
|
2022-07-15 01:14:05 -07:00
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
autoSet?: boolean;
|
|
|
|
}>(), {
|
|
|
|
autoSet: false,
|
|
|
|
});
|
2020-10-17 04:12:00 -07:00
|
|
|
|
2022-07-15 01:14:05 -07:00
|
|
|
const emit = defineEmits<{
|
|
|
|
(ev: 'signup', user: Record<string, any>): void;
|
|
|
|
(ev: 'signupEmailPending'): void;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const host = toUnicode(config.host);
|
|
|
|
|
|
|
|
let hcaptcha = $ref();
|
|
|
|
let recaptcha = $ref();
|
2022-10-12 17:19:57 -07:00
|
|
|
let turnstile = $ref();
|
2022-07-15 01:14:05 -07:00
|
|
|
|
|
|
|
let username: string = $ref('');
|
|
|
|
let password: string = $ref('');
|
|
|
|
let retypedPassword: string = $ref('');
|
|
|
|
let invitationCode: string = $ref('');
|
|
|
|
let email = $ref('');
|
|
|
|
let usernameState: null | 'wait' | 'ok' | 'unavailable' | 'error' | 'invalid-format' | 'min-range' | 'max-range' = $ref(null);
|
|
|
|
let emailState: null | 'wait' | 'ok' | 'unavailable:used' | 'unavailable:format' | 'unavailable:disposable' | 'unavailable:mx' | 'unavailable:smtp' | 'unavailable' | 'error' = $ref(null);
|
|
|
|
let passwordStrength: '' | 'low' | 'medium' | 'high' = $ref('');
|
|
|
|
let passwordRetypeState: null | 'match' | 'not-match' = $ref(null);
|
|
|
|
let submitting: boolean = $ref(false);
|
|
|
|
let ToSAgreement: boolean = $ref(false);
|
|
|
|
let hCaptchaResponse = $ref(null);
|
|
|
|
let reCaptchaResponse = $ref(null);
|
2022-10-12 17:19:57 -07:00
|
|
|
let turnstileResponse = $ref(null);
|
2022-07-15 01:14:05 -07:00
|
|
|
|
|
|
|
const shouldDisableSubmitting = $computed((): boolean => {
|
|
|
|
return submitting ||
|
|
|
|
instance.tosUrl && !ToSAgreement ||
|
|
|
|
instance.enableHcaptcha && !hCaptchaResponse ||
|
|
|
|
instance.enableRecaptcha && !reCaptchaResponse ||
|
2022-10-12 17:19:57 -07:00
|
|
|
instance.enableTurnstile && !turnstileResponse ||
|
2022-07-15 01:14:05 -07:00
|
|
|
passwordRetypeState === 'not-match';
|
|
|
|
});
|
2018-12-18 07:39:28 -08:00
|
|
|
|
2022-07-15 01:14:05 -07:00
|
|
|
function onChangeUsername(): void {
|
|
|
|
if (username === '') {
|
|
|
|
usernameState = null;
|
|
|
|
return;
|
|
|
|
}
|
2020-04-27 22:29:33 -07:00
|
|
|
|
2022-07-15 01:14:05 -07:00
|
|
|
{
|
|
|
|
const err =
|
|
|
|
!username.match(/^[a-zA-Z0-9_]+$/) ? 'invalid-format' :
|
|
|
|
username.length < 1 ? 'min-range' :
|
|
|
|
username.length > 20 ? 'max-range' :
|
|
|
|
null;
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
usernameState = err;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-04-27 22:29:33 -07:00
|
|
|
|
2022-07-15 01:14:05 -07:00
|
|
|
usernameState = 'wait';
|
2018-12-18 07:39:28 -08:00
|
|
|
|
2022-07-15 01:14:05 -07:00
|
|
|
os.api('username/available', {
|
|
|
|
username,
|
|
|
|
}).then(result => {
|
|
|
|
usernameState = result.available ? 'ok' : 'unavailable';
|
|
|
|
}).catch(() => {
|
|
|
|
usernameState = 'error';
|
|
|
|
});
|
|
|
|
}
|
2018-02-09 23:22:14 -08:00
|
|
|
|
2022-07-15 01:14:05 -07:00
|
|
|
function onChangeEmail(): void {
|
|
|
|
if (email === '') {
|
|
|
|
emailState = null;
|
|
|
|
return;
|
|
|
|
}
|
2018-02-09 23:22:14 -08:00
|
|
|
|
2022-07-15 01:14:05 -07:00
|
|
|
emailState = 'wait';
|
|
|
|
|
|
|
|
os.api('email-address/available', {
|
|
|
|
emailAddress: email,
|
|
|
|
}).then(result => {
|
|
|
|
emailState = result.available ? 'ok' :
|
|
|
|
result.reason === 'used' ? 'unavailable:used' :
|
|
|
|
result.reason === 'format' ? 'unavailable:format' :
|
|
|
|
result.reason === 'disposable' ? 'unavailable:disposable' :
|
|
|
|
result.reason === 'mx' ? 'unavailable:mx' :
|
|
|
|
result.reason === 'smtp' ? 'unavailable:smtp' :
|
|
|
|
'unavailable';
|
|
|
|
}).catch(() => {
|
|
|
|
emailState = 'error';
|
|
|
|
});
|
|
|
|
}
|
2018-02-09 23:22:14 -08:00
|
|
|
|
2022-07-15 01:14:05 -07:00
|
|
|
function onChangePassword(): void {
|
|
|
|
if (password === '') {
|
|
|
|
passwordStrength = '';
|
|
|
|
return;
|
|
|
|
}
|
2018-02-09 23:22:14 -08:00
|
|
|
|
2022-07-15 01:14:05 -07:00
|
|
|
const strength = getPasswordStrength(password);
|
|
|
|
passwordStrength = strength > 0.7 ? 'high' : strength > 0.3 ? 'medium' : 'low';
|
|
|
|
}
|
2018-12-18 07:39:28 -08:00
|
|
|
|
2022-07-15 01:14:05 -07:00
|
|
|
function onChangePasswordRetype(): void {
|
|
|
|
if (retypedPassword === '') {
|
|
|
|
passwordRetypeState = null;
|
|
|
|
return;
|
|
|
|
}
|
2021-10-07 21:37:02 -07:00
|
|
|
|
2022-07-15 01:14:05 -07:00
|
|
|
passwordRetypeState = password === retypedPassword ? 'match' : 'not-match';
|
|
|
|
}
|
2021-10-07 21:37:02 -07:00
|
|
|
|
2022-07-15 01:14:05 -07:00
|
|
|
function onSubmit(): void {
|
|
|
|
if (submitting) return;
|
|
|
|
submitting = true;
|
|
|
|
|
|
|
|
os.api('signup', {
|
|
|
|
username,
|
|
|
|
password,
|
|
|
|
emailAddress: email,
|
|
|
|
invitationCode,
|
|
|
|
'hcaptcha-response': hCaptchaResponse,
|
|
|
|
'g-recaptcha-response': reCaptchaResponse,
|
2022-10-12 17:19:57 -07:00
|
|
|
'turnstile-response': turnstileResponse,
|
2022-07-15 01:14:05 -07:00
|
|
|
}).then(() => {
|
|
|
|
if (instance.emailRequiredForSignup) {
|
|
|
|
os.alert({
|
|
|
|
type: 'success',
|
|
|
|
title: i18n.ts._signup.almostThere,
|
|
|
|
text: i18n.t('_signup.emailSent', { email }),
|
2021-10-07 21:37:02 -07:00
|
|
|
});
|
2022-07-15 01:14:05 -07:00
|
|
|
emit('signupEmailPending');
|
|
|
|
} else {
|
|
|
|
os.api('signin', {
|
|
|
|
username,
|
|
|
|
password,
|
|
|
|
}).then(res => {
|
|
|
|
emit('signup', res);
|
|
|
|
|
|
|
|
if (props.autoSet) {
|
|
|
|
login(res.i);
|
2021-10-07 21:37:02 -07:00
|
|
|
}
|
2018-02-10 00:01:32 -08:00
|
|
|
});
|
2022-07-15 01:14:05 -07:00
|
|
|
}
|
|
|
|
}).catch(() => {
|
|
|
|
submitting = false;
|
|
|
|
hcaptcha.reset?.();
|
|
|
|
recaptcha.reset?.();
|
2022-10-12 17:19:57 -07:00
|
|
|
turnstile.reset?.();
|
2022-07-15 01:14:05 -07:00
|
|
|
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
|
|
|
text: i18n.ts.somethingHappened,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2018-02-10 00:01:32 -08:00
|
|
|
</script>
|
2020-04-28 17:15:18 -07:00
|
|
|
|
2022-12-27 01:29:39 -08:00
|
|
|
<style lang="scss" scoped>
|
2021-08-22 00:15:40 -07:00
|
|
|
.qlvuhzng {
|
2020-04-28 17:15:18 -07:00
|
|
|
.captcha {
|
|
|
|
margin: 16px 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|