2018-02-10 07:22:14 +00:00
|
|
|
<template>
|
2021-04-13 03:43:19 +00:00
|
|
|
<form class="eppvobhk _monolithic_" :class="{ signing, totpLogin }" @submit.prevent="onSubmit">
|
2021-09-29 15:50:45 +00:00
|
|
|
<div class="auth _section _formRoot">
|
2021-11-19 10:36:12 +00:00
|
|
|
<div v-show="withAvatar" class="avatar" :style="{ backgroundImage: user ? `url('${ user.avatarUrl }')` : null }"></div>
|
|
|
|
<div v-if="!totpLogin" class="normal-signin">
|
|
|
|
<MkInput v-model="username" class="_formBlock" :placeholder="$ts.username" type="text" pattern="^[a-zA-Z0-9_]+$" spellcheck="false" autofocus required data-cy-signin-username @update:modelValue="onUsernameChange">
|
2020-10-31 00:39:22 +00:00
|
|
|
<template #prefix>@</template>
|
|
|
|
<template #suffix>@{{ host }}</template>
|
|
|
|
</MkInput>
|
2021-11-19 10:36:12 +00:00
|
|
|
<MkInput v-if="!user || user && !user.usePasswordLessLogin" v-model="password" class="_formBlock" :placeholder="$ts.password" type="password" :with-password-toggle="true" required data-cy-signin-password>
|
2021-04-20 14:22:59 +00:00
|
|
|
<template #prefix><i class="fas fa-lock"></i></template>
|
2021-11-19 10:36:12 +00:00
|
|
|
<template #caption><button class="_textButton" type="button" @click="resetPassword">{{ $ts.forgotPassword }}</button></template>
|
2020-10-17 11:12:00 +00:00
|
|
|
</MkInput>
|
2021-09-29 15:50:45 +00:00
|
|
|
<MkButton class="_formBlock" type="submit" primary :disabled="signing" style="margin: 0 auto;">{{ signing ? $ts.loggingIn : $ts.login }}</MkButton>
|
2020-10-31 00:39:22 +00:00
|
|
|
</div>
|
2021-11-19 10:36:12 +00:00
|
|
|
<div v-if="totpLogin" class="2fa-signin" :class="{ securityKeys: user && user.securityKeys }">
|
2020-10-31 00:39:22 +00:00
|
|
|
<div v-if="user && user.securityKeys" class="twofa-group tap-group">
|
2020-12-26 01:47:36 +00:00
|
|
|
<p>{{ $ts.tapSecurityKey }}</p>
|
2021-11-19 10:36:12 +00:00
|
|
|
<MkButton v-if="!queryingKey" @click="queryKey">
|
2020-12-26 01:47:36 +00:00
|
|
|
{{ $ts.retry }}
|
2020-10-31 00:39:22 +00:00
|
|
|
</MkButton>
|
|
|
|
</div>
|
2021-11-19 10:36:12 +00:00
|
|
|
<div v-if="user && user.securityKeys" class="or-hr">
|
2020-12-26 01:47:36 +00:00
|
|
|
<p class="or-msg">{{ $ts.or }}</p>
|
2020-10-31 00:39:22 +00:00
|
|
|
</div>
|
|
|
|
<div class="twofa-group totp-group">
|
2020-12-26 01:47:36 +00:00
|
|
|
<p style="margin-bottom:0;">{{ $ts.twoStepAuthentication }}</p>
|
2021-11-19 10:36:12 +00:00
|
|
|
<MkInput v-if="user && user.usePasswordLessLogin" v-model="password" type="password" :with-password-toggle="true" required>
|
2021-08-06 13:29:19 +00:00
|
|
|
<template #label>{{ $ts.password }}</template>
|
2021-04-20 14:22:59 +00:00
|
|
|
<template #prefix><i class="fas fa-lock"></i></template>
|
2020-10-31 00:39:22 +00:00
|
|
|
</MkInput>
|
2021-08-06 13:29:19 +00:00
|
|
|
<MkInput v-model="token" type="text" pattern="^[0-9]{6}$" autocomplete="off" spellcheck="false" required>
|
|
|
|
<template #label>{{ $ts.token }}</template>
|
2021-04-20 14:22:59 +00:00
|
|
|
<template #prefix><i class="fas fa-gavel"></i></template>
|
2020-10-31 00:39:22 +00:00
|
|
|
</MkInput>
|
2022-05-15 03:18:46 +00:00
|
|
|
<MkCaptcha v-if="meta.enableHcaptcha" ref="hcaptcha" v-model="hCaptchaResponse" class="_formBlock captcha" provider="hcaptcha" :sitekey="meta.hcaptchaSiteKey"/>
|
|
|
|
<MkCaptcha v-if="meta.enableRecaptcha" ref="recaptcha" v-model="reCaptchaResponse" class="_formBlock captcha" provider="recaptcha" :sitekey="meta.recaptchaSiteKey"/>
|
2020-12-26 01:47:36 +00:00
|
|
|
<MkButton type="submit" :disabled="signing" primary style="margin: 0 auto;">{{ signing ? $ts.loggingIn : $ts.login }}</MkButton>
|
2020-10-31 00:39:22 +00:00
|
|
|
</div>
|
2019-07-03 11:18:07 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-04-13 03:43:19 +00:00
|
|
|
<div class="social _section">
|
2021-11-19 10:36:12 +00:00
|
|
|
<a v-if="meta && meta.enableTwitterIntegration" class="_borderButton _gap" :href="`${apiUrl}/signin/twitter`"><i class="fab fa-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="fab fa-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="fab fa-discord" style="margin-right: 4px;"></i>{{ $t('signinWith', { x: 'Discord' }) }}</a>
|
2020-10-31 00:39:22 +00:00
|
|
|
</div>
|
2018-02-10 07:22:14 +00:00
|
|
|
</form>
|
|
|
|
</template>
|
|
|
|
|
2018-02-11 03:08:43 +00:00
|
|
|
<script lang="ts">
|
2022-05-01 13:51:07 +00:00
|
|
|
import { defineAsyncComponent, defineComponent } from 'vue';
|
2021-04-04 04:00:39 +00:00
|
|
|
import { toUnicode } from 'punycode/';
|
2021-11-11 17:02:25 +00:00
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import MkInput from '@/components/form/input.vue';
|
|
|
|
import { apiUrl, host } from '@/config';
|
|
|
|
import { byteify, hexify } from '@/scripts/2fa';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import { login } from '@/account';
|
2021-09-18 17:23:12 +00:00
|
|
|
import { showSuspendedDialog } from '../scripts/show-suspended-dialog';
|
2018-02-10 07:22:14 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
export default defineComponent({
|
2020-01-29 19:37:25 +00:00
|
|
|
components: {
|
|
|
|
MkButton,
|
|
|
|
MkInput,
|
2022-05-15 03:18:46 +00:00
|
|
|
MkCaptcha: defineAsyncComponent(() => import('./captcha.vue')),
|
2020-01-29 19:37:25 +00:00
|
|
|
},
|
2018-12-18 15:40:29 +00:00
|
|
|
|
2018-06-15 22:40:07 +00:00
|
|
|
props: {
|
|
|
|
withAvatar: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: true
|
2020-01-29 19:37:25 +00:00
|
|
|
},
|
|
|
|
autoSet: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
2018-06-15 22:40:07 +00:00
|
|
|
}
|
|
|
|
},
|
2018-12-18 15:40:29 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
emits: ['login'],
|
|
|
|
|
2018-02-10 07:22:14 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
signing: false,
|
2018-02-11 03:08:43 +00:00
|
|
|
user: null,
|
|
|
|
username: '',
|
|
|
|
password: '',
|
2018-03-26 07:18:40 +00:00
|
|
|
token: '',
|
|
|
|
apiUrl,
|
2018-11-16 17:13:01 +00:00
|
|
|
host: toUnicode(host),
|
2019-07-03 11:18:07 +00:00
|
|
|
totpLogin: false,
|
|
|
|
credential: null,
|
|
|
|
challengeData: null,
|
|
|
|
queryingKey: false,
|
2022-05-15 03:18:46 +00:00
|
|
|
hCaptchaResponse: null,
|
|
|
|
reCaptchaResponse: null,
|
2018-02-10 07:22:14 +00:00
|
|
|
};
|
|
|
|
},
|
2018-12-18 15:40:29 +00:00
|
|
|
|
2020-02-10 14:17:42 +00:00
|
|
|
computed: {
|
|
|
|
meta() {
|
2020-12-19 01:55:52 +00:00
|
|
|
return this.$instance;
|
2020-02-10 14:17:42 +00:00
|
|
|
},
|
|
|
|
},
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2018-02-10 07:22:14 +00:00
|
|
|
methods: {
|
|
|
|
onUsernameChange() {
|
2020-10-17 11:12:00 +00:00
|
|
|
os.api('users/show', {
|
2018-02-10 07:22:14 +00:00
|
|
|
username: this.username
|
|
|
|
}).then(user => {
|
|
|
|
this.user = user;
|
2018-06-15 22:31:35 +00:00
|
|
|
}, () => {
|
|
|
|
this.user = null;
|
2018-02-10 07:22:14 +00:00
|
|
|
});
|
|
|
|
},
|
2018-12-18 15:40:29 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
onLogin(res) {
|
|
|
|
if (this.autoSet) {
|
2021-09-04 09:09:53 +00:00
|
|
|
return login(res.i);
|
|
|
|
} else {
|
|
|
|
return;
|
2020-10-17 11:12:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-07-03 11:18:07 +00:00
|
|
|
queryKey() {
|
|
|
|
this.queryingKey = true;
|
|
|
|
return navigator.credentials.get({
|
|
|
|
publicKey: {
|
2020-05-08 23:20:22 +00:00
|
|
|
challenge: byteify(this.challengeData.challenge, 'base64'),
|
2019-07-03 11:18:07 +00:00
|
|
|
allowCredentials: this.challengeData.securityKeys.map(key => ({
|
2020-05-08 23:20:22 +00:00
|
|
|
id: byteify(key.id, 'hex'),
|
2019-07-03 11:18:07 +00:00
|
|
|
type: 'public-key',
|
2020-01-26 20:38:40 +00:00
|
|
|
transports: ['usb', 'nfc', 'ble', 'internal']
|
2019-07-03 11:18:07 +00:00
|
|
|
})),
|
|
|
|
timeout: 60 * 1000
|
|
|
|
}
|
2019-07-04 22:48:12 +00:00
|
|
|
}).catch(() => {
|
2019-07-03 11:18:07 +00:00
|
|
|
this.queryingKey = false;
|
|
|
|
return Promise.reject(null);
|
|
|
|
}).then(credential => {
|
|
|
|
this.queryingKey = false;
|
|
|
|
this.signing = true;
|
2020-10-17 11:12:00 +00:00
|
|
|
return os.api('signin', {
|
2019-07-03 11:18:07 +00:00
|
|
|
username: this.username,
|
|
|
|
password: this.password,
|
2022-05-15 03:18:46 +00:00
|
|
|
'hcaptcha-response': this.hCaptchaResponse,
|
|
|
|
'g-recaptcha-response': this.reCaptchaResponse,
|
2020-05-08 23:20:22 +00:00
|
|
|
signature: hexify(credential.response.signature),
|
|
|
|
authenticatorData: hexify(credential.response.authenticatorData),
|
|
|
|
clientDataJSON: hexify(credential.response.clientDataJSON),
|
2019-07-03 11:18:07 +00:00
|
|
|
credentialId: credential.id,
|
2022-05-15 03:18:46 +00:00
|
|
|
challengeId: this.challengeData.challengeId,
|
2019-07-03 11:18:07 +00:00
|
|
|
});
|
2019-01-18 07:46:56 +00:00
|
|
|
}).then(res => {
|
2020-01-29 19:37:25 +00:00
|
|
|
this.$emit('login', res);
|
2021-09-04 09:09:53 +00:00
|
|
|
return this.onLogin(res);
|
2019-07-03 11:18:07 +00:00
|
|
|
}).catch(err => {
|
2019-07-04 22:48:12 +00:00
|
|
|
if (err === null) return;
|
2021-11-18 09:45:58 +00:00
|
|
|
os.alert({
|
2019-04-16 04:05:10 +00:00
|
|
|
type: 'error',
|
2020-12-26 01:47:36 +00:00
|
|
|
text: this.$ts.signinFailed
|
2019-04-16 04:05:10 +00:00
|
|
|
});
|
2018-02-10 07:22:14 +00:00
|
|
|
this.signing = false;
|
|
|
|
});
|
2019-07-03 11:18:07 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onSubmit() {
|
|
|
|
this.signing = true;
|
|
|
|
if (!this.totpLogin && this.user && this.user.twoFactorEnabled) {
|
|
|
|
if (window.PublicKeyCredential && this.user.securityKeys) {
|
2020-10-17 11:12:00 +00:00
|
|
|
os.api('signin', {
|
2019-07-03 11:18:07 +00:00
|
|
|
username: this.username,
|
2022-05-15 03:18:46 +00:00
|
|
|
password: this.password,
|
|
|
|
'hcaptcha-response': this.hCaptchaResponse,
|
|
|
|
'g-recaptcha-response': this.reCaptchaResponse,
|
2019-07-03 11:18:07 +00:00
|
|
|
}).then(res => {
|
|
|
|
this.totpLogin = true;
|
|
|
|
this.signing = false;
|
|
|
|
this.challengeData = res;
|
|
|
|
return this.queryKey();
|
2021-09-18 17:23:12 +00:00
|
|
|
}).catch(this.loginFailed);
|
2019-07-03 11:18:07 +00:00
|
|
|
} else {
|
|
|
|
this.totpLogin = true;
|
|
|
|
this.signing = false;
|
|
|
|
}
|
|
|
|
} else {
|
2020-10-17 11:12:00 +00:00
|
|
|
os.api('signin', {
|
2019-07-03 11:18:07 +00:00
|
|
|
username: this.username,
|
|
|
|
password: this.password,
|
2022-05-15 03:18:46 +00:00
|
|
|
'hcaptcha-response': this.hCaptchaResponse,
|
|
|
|
'g-recaptcha-response': this.reCaptchaResponse,
|
|
|
|
token: this.user && this.user.twoFactorEnabled ? this.token : undefined,
|
2019-07-03 11:18:07 +00:00
|
|
|
}).then(res => {
|
2020-01-29 19:37:25 +00:00
|
|
|
this.$emit('login', res);
|
2020-10-17 11:12:00 +00:00
|
|
|
this.onLogin(res);
|
2021-09-18 17:23:12 +00:00
|
|
|
}).catch(this.loginFailed);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
loginFailed(err) {
|
|
|
|
switch (err.id) {
|
|
|
|
case '6cc579cc-885d-43d8-95c2-b8c7fc963280': {
|
2021-11-18 09:45:58 +00:00
|
|
|
os.alert({
|
2019-07-03 11:18:07 +00:00
|
|
|
type: 'error',
|
2021-09-18 17:23:12 +00:00
|
|
|
title: this.$ts.loginFailed,
|
|
|
|
text: this.$ts.noSuchUser
|
2019-07-03 11:18:07 +00:00
|
|
|
});
|
2021-09-18 17:23:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-11-21 05:01:53 +00:00
|
|
|
case '932c904e-9460-45b7-9ce6-7ed33be7eb2c': {
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
|
|
|
title: this.$ts.loginFailed,
|
|
|
|
text: this.$ts.incorrectPassword,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
2021-09-18 17:23:12 +00:00
|
|
|
case 'e03a5f46-d309-4865-9b69-56282d94e1eb': {
|
|
|
|
showSuspendedDialog();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2021-11-18 09:45:58 +00:00
|
|
|
os.alert({
|
2021-09-18 17:23:12 +00:00
|
|
|
type: 'error',
|
|
|
|
title: this.$ts.loginFailed,
|
|
|
|
text: JSON.stringify(err)
|
|
|
|
});
|
|
|
|
}
|
2019-07-03 11:18:07 +00:00
|
|
|
}
|
2021-09-18 17:23:12 +00:00
|
|
|
|
|
|
|
this.challengeData = null;
|
|
|
|
this.totpLogin = false;
|
|
|
|
this.signing = false;
|
2021-05-04 06:05:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
resetPassword() {
|
2022-05-01 13:51:07 +00:00
|
|
|
os.popup(defineAsyncComponent(() => import('@/components/forgot-password.vue')), {}, {
|
2021-05-04 06:05:34 +00:00
|
|
|
}, 'closed');
|
2018-02-10 07:22:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.eppvobhk {
|
2020-10-31 00:39:22 +00: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 19:37:25 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-10 07:22:14 +00:00
|
|
|
</style>
|