2018-02-10 09:22:14 +02:00
|
|
|
<template>
|
2021-04-13 06:43:19 +03:00
|
|
|
<form class="eppvobhk _monolithic_" :class="{ signing, totpLogin }" @submit.prevent="onSubmit">
|
2021-09-29 18:50:45 +03:00
|
|
|
<div class="auth _section _formRoot">
|
2022-05-19 14:28:08 +03:00
|
|
|
<div v-show="withAvatar" class="avatar" :style="{ backgroundImage: user ? `url('${ user.avatarUrl }')` : null, marginBottom: message ? '1.5em' : null }"></div>
|
|
|
|
<MkInfo v-if="message">
|
|
|
|
{{ message }}
|
|
|
|
</MkInfo>
|
2021-11-19 12:36:12 +02:00
|
|
|
<div v-if="!totpLogin" class="normal-signin">
|
2022-12-22 09:51:48 +02:00
|
|
|
<MkInput v-model="username" class="_formBlock" :placeholder="i18n.ts.username" type="text" pattern="^[a-zA-Z0-9_]+$" :spellcheck="false" autofocus required data-cy-signin-username @update:model-value="onUsernameChange">
|
2020-10-31 02:39:22 +02:00
|
|
|
<template #prefix>@</template>
|
|
|
|
<template #suffix>@{{ host }}</template>
|
|
|
|
</MkInput>
|
2022-05-19 14:28:08 +03:00
|
|
|
<MkInput v-if="!user || user && !user.usePasswordLessLogin" v-model="password" class="_formBlock" :placeholder="i18n.ts.password" type="password" :with-password-toggle="true" required data-cy-signin-password>
|
2022-12-19 12:01:30 +02:00
|
|
|
<template #prefix><i class="ti ti-lock"></i></template>
|
2022-05-19 14:28:08 +03:00
|
|
|
<template #caption><button class="_textButton" type="button" @click="resetPassword">{{ i18n.ts.forgotPassword }}</button></template>
|
2020-10-17 14:12:00 +03:00
|
|
|
</MkInput>
|
2022-05-19 14:28:08 +03:00
|
|
|
<MkButton class="_formBlock" type="submit" primary :disabled="signing" style="margin: 0 auto;">{{ signing ? i18n.ts.loggingIn : i18n.ts.login }}</MkButton>
|
2020-10-31 02:39:22 +02:00
|
|
|
</div>
|
2021-11-19 12:36:12 +02:00
|
|
|
<div v-if="totpLogin" class="2fa-signin" :class="{ securityKeys: user && user.securityKeys }">
|
2020-10-31 02:39:22 +02:00
|
|
|
<div v-if="user && user.securityKeys" class="twofa-group tap-group">
|
2022-05-19 14:28:08 +03:00
|
|
|
<p>{{ i18n.ts.tapSecurityKey }}</p>
|
2021-11-19 12:36:12 +02:00
|
|
|
<MkButton v-if="!queryingKey" @click="queryKey">
|
2022-05-19 14:28:08 +03:00
|
|
|
{{ i18n.ts.retry }}
|
2020-10-31 02:39:22 +02:00
|
|
|
</MkButton>
|
|
|
|
</div>
|
2021-11-19 12:36:12 +02:00
|
|
|
<div v-if="user && user.securityKeys" class="or-hr">
|
2022-05-19 14:28:08 +03:00
|
|
|
<p class="or-msg">{{ i18n.ts.or }}</p>
|
2020-10-31 02:39:22 +02:00
|
|
|
</div>
|
|
|
|
<div class="twofa-group totp-group">
|
2022-05-19 14:28:08 +03:00
|
|
|
<p style="margin-bottom:0;">{{ i18n.ts.twoStepAuthentication }}</p>
|
2021-11-19 12:36:12 +02:00
|
|
|
<MkInput v-if="user && user.usePasswordLessLogin" v-model="password" type="password" :with-password-toggle="true" required>
|
2022-05-19 14:28:08 +03:00
|
|
|
<template #label>{{ i18n.ts.password }}</template>
|
2022-12-19 12:01:30 +02:00
|
|
|
<template #prefix><i class="ti ti-lock"></i></template>
|
2020-10-31 02:39:22 +02:00
|
|
|
</MkInput>
|
2022-07-04 11:35:27 +03:00
|
|
|
<MkInput v-model="token" type="text" pattern="^[0-9]{6}$" autocomplete="off" :spellcheck="false" required>
|
2022-05-19 14:28:08 +03:00
|
|
|
<template #label>{{ i18n.ts.token }}</template>
|
2021-04-20 17:22:59 +03:00
|
|
|
<template #prefix><i class="fas fa-gavel"></i></template>
|
2020-10-31 02:39:22 +02:00
|
|
|
</MkInput>
|
2022-05-19 14:28:08 +03:00
|
|
|
<MkButton type="submit" :disabled="signing" primary style="margin: 0 auto;">{{ signing ? i18n.ts.loggingIn : i18n.ts.login }}</MkButton>
|
2020-10-31 02:39:22 +02:00
|
|
|
</div>
|
2019-07-03 14:18:07 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-04-13 06:43:19 +03:00
|
|
|
<div class="social _section">
|
2022-12-20 08:15:34 +02:00
|
|
|
<a v-if="meta && meta.enableTwitterIntegration" class="_borderButton _gap" :href="`${apiUrl}/signin/twitter`"><i class="ti ti-brand-twitter" style="margin-right: 4px;"></i>{{ $t('signinWith', { x: 'Twitter' }) }}</a>
|
|
|
|
<a v-if="meta && meta.enableGithubIntegration" class="_borderButton _gap" :href="`${apiUrl}/signin/github`"><i class="ti ti-brand-github" style="margin-right: 4px;"></i>{{ $t('signinWith', { x: 'GitHub' }) }}</a>
|
|
|
|
<a v-if="meta && meta.enableDiscordIntegration" class="_borderButton _gap" :href="`${apiUrl}/signin/discord`"><i class="ti ti-brand-discord" style="margin-right: 4px;"></i>{{ $t('signinWith', { x: 'Discord' }) }}</a>
|
2020-10-31 02:39:22 +02:00
|
|
|
</div>
|
2018-02-10 09:22:14 +02:00
|
|
|
</form>
|
|
|
|
</template>
|
|
|
|
|
2022-05-19 14:28:08 +03:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { defineAsyncComponent } from 'vue';
|
2021-04-04 07:00:39 +03:00
|
|
|
import { toUnicode } from 'punycode/';
|
2022-12-20 08:15:34 +02:00
|
|
|
import { showSuspendedDialog } from '../scripts/show-suspended-dialog';
|
2022-09-06 12:21:49 +03:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2021-11-11 19:02:25 +02:00
|
|
|
import MkInput from '@/components/form/input.vue';
|
2022-09-06 12:21:49 +03:00
|
|
|
import MkInfo from '@/components/MkInfo.vue';
|
2022-05-19 14:28:08 +03:00
|
|
|
import { apiUrl, host as configHost } from '@/config';
|
2021-11-11 19:02:25 +02:00
|
|
|
import { byteify, hexify } from '@/scripts/2fa';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import { login } from '@/account';
|
2022-05-19 14:28:08 +03:00
|
|
|
import { instance } from '@/instance';
|
|
|
|
import { i18n } from '@/i18n';
|
2018-02-10 09:22:14 +02:00
|
|
|
|
2022-05-19 14:28:08 +03:00
|
|
|
let signing = $ref(false);
|
|
|
|
let user = $ref(null);
|
|
|
|
let username = $ref('');
|
|
|
|
let password = $ref('');
|
|
|
|
let token = $ref('');
|
|
|
|
let host = $ref(toUnicode(configHost));
|
|
|
|
let totpLogin = $ref(false);
|
|
|
|
let credential = $ref(null);
|
|
|
|
let challengeData = $ref(null);
|
|
|
|
let queryingKey = $ref(false);
|
|
|
|
let hCaptchaResponse = $ref(null);
|
|
|
|
let reCaptchaResponse = $ref(null);
|
2018-12-18 17:40:29 +02:00
|
|
|
|
2022-05-19 14:28:08 +03:00
|
|
|
const meta = $computed(() => instance);
|
2020-10-17 14:12:00 +03:00
|
|
|
|
2022-05-19 14:28:08 +03:00
|
|
|
const emit = defineEmits<{
|
|
|
|
(ev: 'login', v: any): void;
|
|
|
|
}>();
|
2018-12-18 17:40:29 +02:00
|
|
|
|
2022-05-19 14:28:08 +03:00
|
|
|
const props = defineProps({
|
|
|
|
withAvatar: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
2022-12-20 08:15:34 +02:00
|
|
|
default: true,
|
2020-02-10 16:17:42 +02:00
|
|
|
},
|
2022-05-19 14:28:08 +03:00
|
|
|
autoSet: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
message: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
2022-12-20 08:15:34 +02:00
|
|
|
default: '',
|
|
|
|
},
|
2022-05-19 14:28:08 +03:00
|
|
|
});
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-05-19 14:28:08 +03:00
|
|
|
function onUsernameChange() {
|
|
|
|
os.api('users/show', {
|
2022-12-20 08:15:34 +02:00
|
|
|
username: username,
|
2022-05-23 23:43:13 +03:00
|
|
|
}).then(userResponse => {
|
|
|
|
user = userResponse;
|
2022-05-19 14:28:08 +03:00
|
|
|
}, () => {
|
|
|
|
user = null;
|
|
|
|
});
|
|
|
|
}
|
2019-07-03 14:18:07 +03:00
|
|
|
|
2022-05-19 14:28:08 +03:00
|
|
|
function onLogin(res) {
|
|
|
|
if (props.autoSet) {
|
|
|
|
return login(res.i);
|
|
|
|
}
|
|
|
|
}
|
2021-09-18 20:23:12 +03:00
|
|
|
|
2022-05-19 14:28:08 +03:00
|
|
|
function queryKey() {
|
|
|
|
queryingKey = true;
|
|
|
|
return navigator.credentials.get({
|
|
|
|
publicKey: {
|
|
|
|
challenge: byteify(challengeData.challenge, 'base64'),
|
|
|
|
allowCredentials: challengeData.securityKeys.map(key => ({
|
|
|
|
id: byteify(key.id, 'hex'),
|
|
|
|
type: 'public-key',
|
2022-12-20 08:15:34 +02:00
|
|
|
transports: ['usb', 'nfc', 'ble', 'internal'],
|
2022-05-19 14:28:08 +03:00
|
|
|
})),
|
2022-12-20 08:15:34 +02:00
|
|
|
timeout: 60 * 1000,
|
|
|
|
},
|
2022-05-19 14:28:08 +03:00
|
|
|
}).catch(() => {
|
|
|
|
queryingKey = false;
|
|
|
|
return Promise.reject(null);
|
|
|
|
}).then(credential => {
|
|
|
|
queryingKey = false;
|
|
|
|
signing = true;
|
|
|
|
return os.api('signin', {
|
|
|
|
username,
|
|
|
|
password,
|
|
|
|
signature: hexify(credential.response.signature),
|
|
|
|
authenticatorData: hexify(credential.response.authenticatorData),
|
|
|
|
clientDataJSON: hexify(credential.response.clientDataJSON),
|
|
|
|
credentialId: credential.id,
|
|
|
|
challengeId: challengeData.challengeId,
|
2022-12-20 08:15:34 +02:00
|
|
|
'hcaptcha-response': hCaptchaResponse,
|
2022-05-19 14:28:08 +03:00
|
|
|
'g-recaptcha-response': reCaptchaResponse,
|
|
|
|
});
|
|
|
|
}).then(res => {
|
|
|
|
emit('login', res);
|
|
|
|
return onLogin(res);
|
|
|
|
}).catch(err => {
|
|
|
|
if (err === null) return;
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
2022-12-20 08:15:34 +02:00
|
|
|
text: i18n.ts.signinFailed,
|
2022-05-19 14:28:08 +03:00
|
|
|
});
|
|
|
|
signing = false;
|
|
|
|
});
|
|
|
|
}
|
2021-09-18 20:23:12 +03:00
|
|
|
|
2022-05-19 14:28:08 +03:00
|
|
|
function onSubmit() {
|
|
|
|
signing = true;
|
2022-06-10 08:36:55 +03:00
|
|
|
console.log('submit');
|
2022-05-19 14:28:08 +03:00
|
|
|
if (!totpLogin && user && user.twoFactorEnabled) {
|
|
|
|
if (window.PublicKeyCredential && user.securityKeys) {
|
|
|
|
os.api('signin', {
|
|
|
|
username,
|
|
|
|
password,
|
2022-12-20 08:15:34 +02:00
|
|
|
'hcaptcha-response': hCaptchaResponse,
|
|
|
|
'g-recaptcha-response': reCaptchaResponse,
|
2022-05-19 14:28:08 +03:00
|
|
|
}).then(res => {
|
|
|
|
totpLogin = true;
|
|
|
|
signing = false;
|
|
|
|
challengeData = res;
|
|
|
|
return queryKey();
|
|
|
|
}).catch(loginFailed);
|
|
|
|
} else {
|
|
|
|
totpLogin = true;
|
|
|
|
signing = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
os.api('signin', {
|
|
|
|
username,
|
|
|
|
password,
|
2022-12-20 08:15:34 +02:00
|
|
|
'hcaptcha-response': hCaptchaResponse,
|
2022-05-19 14:28:08 +03:00
|
|
|
'g-recaptcha-response': reCaptchaResponse,
|
2022-12-20 08:15:34 +02:00
|
|
|
token: user && user.twoFactorEnabled ? token : undefined,
|
2022-05-19 14:28:08 +03:00
|
|
|
}).then(res => {
|
|
|
|
emit('login', res);
|
|
|
|
onLogin(res);
|
|
|
|
}).catch(loginFailed);
|
|
|
|
}
|
|
|
|
}
|
2021-05-04 09:05:34 +03:00
|
|
|
|
2022-05-19 14:28:08 +03:00
|
|
|
function loginFailed(err) {
|
|
|
|
switch (err.id) {
|
|
|
|
case '6cc579cc-885d-43d8-95c2-b8c7fc963280': {
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
|
|
|
title: i18n.ts.loginFailed,
|
2022-12-20 08:15:34 +02:00
|
|
|
text: i18n.ts.noSuchUser,
|
2022-05-19 14:28:08 +03:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '932c904e-9460-45b7-9ce6-7ed33be7eb2c': {
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
|
|
|
title: i18n.ts.loginFailed,
|
|
|
|
text: i18n.ts.incorrectPassword,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'e03a5f46-d309-4865-9b69-56282d94e1eb': {
|
|
|
|
showSuspendedDialog();
|
|
|
|
break;
|
|
|
|
}
|
2022-05-28 06:06:47 +03:00
|
|
|
case '22d05606-fbcf-421a-a2db-b32610dcfd1b': {
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
|
|
|
title: i18n.ts.loginFailed,
|
|
|
|
text: i18n.ts.rateLimitExceeded,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
2022-05-19 14:28:08 +03:00
|
|
|
default: {
|
2022-06-10 08:36:55 +03:00
|
|
|
console.log(err);
|
2022-05-19 14:28:08 +03:00
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
|
|
|
title: i18n.ts.loginFailed,
|
2022-12-20 08:15:34 +02:00
|
|
|
text: JSON.stringify(err),
|
2022-05-19 14:28:08 +03:00
|
|
|
});
|
2018-02-10 09:22:14 +02:00
|
|
|
}
|
|
|
|
}
|
2022-05-19 14:28:08 +03:00
|
|
|
|
|
|
|
challengeData = null;
|
|
|
|
totpLogin = false;
|
|
|
|
signing = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetPassword() {
|
2022-08-30 18:24:33 +03:00
|
|
|
os.popup(defineAsyncComponent(() => import('@/components/MkForgotPassword.vue')), {}, {
|
2022-05-19 14:28:08 +03:00
|
|
|
}, 'closed');
|
|
|
|
}
|
2018-02-10 09:22:14 +02:00
|
|
|
</script>
|
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.eppvobhk {
|
2020-10-31 02:39:22 +02:00
|
|
|
> .auth {
|
|
|
|
> .avatar {
|
|
|
|
margin: 0 auto 0 auto;
|
|
|
|
width: 64px;
|
|
|
|
height: 64px;
|
|
|
|
background: #ddd;
|
|
|
|
background-position: center;
|
|
|
|
background-size: cover;
|
|
|
|
border-radius: 100%;
|
|
|
|
}
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
|
|
|
}
|
2018-02-10 09:22:14 +02:00
|
|
|
</style>
|