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