2018-02-10 00:22:14 -07:00
|
|
|
<template>
|
2021-04-11 09:14:27 -06:00
|
|
|
<form class="eppvobhk" :class="{ signing, totpLogin }" @submit.prevent="onSubmit">
|
|
|
|
<div class="auth _root">
|
2020-10-30 18:39:22 -06:00
|
|
|
<div class="avatar" :style="{ backgroundImage: user ? `url('${ user.avatarUrl }')` : null }" v-show="withAvatar"></div>
|
|
|
|
<div class="normal-signin" v-if="!totpLogin">
|
|
|
|
<MkInput v-model:value="username" type="text" pattern="^[a-zA-Z0-9_]+$" spellcheck="false" autofocus required @update:value="onUsernameChange">
|
2020-12-25 18:47:36 -07:00
|
|
|
<span>{{ $ts.username }}</span>
|
2020-10-30 18:39:22 -06:00
|
|
|
<template #prefix>@</template>
|
|
|
|
<template #suffix>@{{ host }}</template>
|
|
|
|
</MkInput>
|
|
|
|
<MkInput v-model:value="password" type="password" :with-password-toggle="true" v-if="!user || user && !user.usePasswordLessLogin" required>
|
2020-12-25 18:47:36 -07:00
|
|
|
<span>{{ $ts.password }}</span>
|
2020-10-17 05:12:00 -06:00
|
|
|
<template #prefix><Fa :icon="faLock"/></template>
|
|
|
|
</MkInput>
|
2020-12-25 18:47:36 -07:00
|
|
|
<MkButton type="submit" primary :disabled="signing" style="margin: 0 auto;">{{ signing ? $ts.loggingIn : $ts.login }}</MkButton>
|
2020-10-30 18:39:22 -06: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-25 18:47:36 -07:00
|
|
|
<p>{{ $ts.tapSecurityKey }}</p>
|
2020-10-30 18:39:22 -06:00
|
|
|
<MkButton @click="queryKey" v-if="!queryingKey">
|
2020-12-25 18:47:36 -07:00
|
|
|
{{ $ts.retry }}
|
2020-10-30 18:39:22 -06:00
|
|
|
</MkButton>
|
|
|
|
</div>
|
|
|
|
<div class="or-hr" v-if="user && user.securityKeys">
|
2020-12-25 18:47:36 -07:00
|
|
|
<p class="or-msg">{{ $ts.or }}</p>
|
2020-10-30 18:39:22 -06:00
|
|
|
</div>
|
|
|
|
<div class="twofa-group totp-group">
|
2020-12-25 18:47:36 -07:00
|
|
|
<p style="margin-bottom:0;">{{ $ts.twoStepAuthentication }}</p>
|
2020-10-30 18:39:22 -06:00
|
|
|
<MkInput v-model:value="password" type="password" :with-password-toggle="true" v-if="user && user.usePasswordLessLogin" required>
|
2020-12-25 18:47:36 -07:00
|
|
|
<span>{{ $ts.password }}</span>
|
2020-10-30 18:39:22 -06:00
|
|
|
<template #prefix><Fa :icon="faLock"/></template>
|
|
|
|
</MkInput>
|
|
|
|
<MkInput v-model:value="token" type="text" pattern="^[0-9]{6}$" autocomplete="off" spellcheck="false" required>
|
2020-12-25 18:47:36 -07:00
|
|
|
<span>{{ $ts.token }}</span>
|
2020-10-30 18:39:22 -06:00
|
|
|
<template #prefix><Fa :icon="faGavel"/></template>
|
|
|
|
</MkInput>
|
2020-12-25 18:47:36 -07:00
|
|
|
<MkButton type="submit" :disabled="signing" primary style="margin: 0 auto;">{{ signing ? $ts.loggingIn : $ts.login }}</MkButton>
|
2020-10-30 18:39:22 -06:00
|
|
|
</div>
|
2019-07-03 05:18:07 -06:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-04-11 09:14:27 -06:00
|
|
|
<div class="social _root">
|
2021-04-10 03:17:42 -06:00
|
|
|
<a class="_borderButton _gap" v-if="meta && meta.enableTwitterIntegration" :href="`${apiUrl}/signin/twitter`"><Fa :icon="faTwitter" style="margin-right: 4px;"/>{{ $t('signinWith', { x: 'Twitter' }) }}</a>
|
|
|
|
<a class="_borderButton _gap" v-if="meta && meta.enableGithubIntegration" :href="`${apiUrl}/signin/github`"><Fa :icon="faGithub" style="margin-right: 4px;"/>{{ $t('signinWith', { x: 'GitHub' }) }}</a>
|
|
|
|
<a class="_borderButton _gap" v-if="meta && meta.enableDiscordIntegration" :href="`${apiUrl}/signin/discord`"><Fa :icon="faDiscord" style="margin-right: 4px;"/>{{ $t('signinWith', { x: 'Discord' }) }}</a>
|
2020-10-30 18:39:22 -06:00
|
|
|
</div>
|
2018-02-10 00:22:14 -07:00
|
|
|
</form>
|
|
|
|
</template>
|
|
|
|
|
2018-02-10 20:08:43 -07:00
|
|
|
<script lang="ts">
|
2020-10-17 05:12:00 -06:00
|
|
|
import { defineComponent } from 'vue';
|
2021-04-03 22:00:39 -06:00
|
|
|
import { toUnicode } from 'punycode/';
|
2020-01-29 12:37:25 -07:00
|
|
|
import { faLock, faGavel } from '@fortawesome/free-solid-svg-icons';
|
2020-02-11 14:27:11 -07:00
|
|
|
import { faTwitter, faDiscord, faGithub } from '@fortawesome/free-brands-svg-icons';
|
2020-01-29 12:37:25 -07:00
|
|
|
import MkButton from './ui/button.vue';
|
|
|
|
import MkInput from './ui/input.vue';
|
2021-03-23 02:30:14 -06: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';
|
2018-02-10 00:22:14 -07:00
|
|
|
|
2020-10-17 05:12:00 -06:00
|
|
|
export default defineComponent({
|
2020-01-29 12:37:25 -07:00
|
|
|
components: {
|
|
|
|
MkButton,
|
|
|
|
MkInput,
|
|
|
|
},
|
2018-12-18 08:40:29 -07:00
|
|
|
|
2018-06-15 16:40:07 -06:00
|
|
|
props: {
|
|
|
|
withAvatar: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: true
|
2020-01-29 12:37:25 -07:00
|
|
|
},
|
|
|
|
autoSet: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
2018-06-15 16:40:07 -06:00
|
|
|
}
|
|
|
|
},
|
2018-12-18 08:40:29 -07:00
|
|
|
|
2020-10-17 05:12:00 -06:00
|
|
|
emits: ['login'],
|
|
|
|
|
2018-02-10 00:22:14 -07:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
signing: false,
|
2018-02-10 20:08:43 -07:00
|
|
|
user: null,
|
|
|
|
username: '',
|
|
|
|
password: '',
|
2018-03-26 01:18:40 -06:00
|
|
|
token: '',
|
|
|
|
apiUrl,
|
2018-11-16 10:13:01 -07:00
|
|
|
host: toUnicode(host),
|
2019-07-03 05:18:07 -06:00
|
|
|
totpLogin: false,
|
|
|
|
credential: null,
|
|
|
|
challengeData: null,
|
|
|
|
queryingKey: false,
|
2020-02-11 14:27:11 -07:00
|
|
|
faLock, faGavel, faTwitter, faDiscord, faGithub
|
2018-02-10 00:22:14 -07:00
|
|
|
};
|
|
|
|
},
|
2018-12-18 08:40:29 -07:00
|
|
|
|
2020-02-10 07:17:42 -07:00
|
|
|
computed: {
|
|
|
|
meta() {
|
2020-12-18 18:55:52 -07:00
|
|
|
return this.$instance;
|
2020-02-10 07:17:42 -07:00
|
|
|
},
|
|
|
|
},
|
2020-01-29 12:37:25 -07:00
|
|
|
|
2018-02-10 00:22:14 -07:00
|
|
|
methods: {
|
|
|
|
onUsernameChange() {
|
2020-10-17 05:12:00 -06:00
|
|
|
os.api('users/show', {
|
2018-02-10 00:22:14 -07:00
|
|
|
username: this.username
|
|
|
|
}).then(user => {
|
|
|
|
this.user = user;
|
2018-06-15 16:31:35 -06:00
|
|
|
}, () => {
|
|
|
|
this.user = null;
|
2018-02-10 00:22:14 -07:00
|
|
|
});
|
|
|
|
},
|
2018-12-18 08:40:29 -07:00
|
|
|
|
2020-10-17 05:12:00 -06:00
|
|
|
onLogin(res) {
|
|
|
|
if (this.autoSet) {
|
2020-12-18 18:55:52 -07:00
|
|
|
login(res.i);
|
2020-10-17 05:12:00 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-07-03 05:18:07 -06:00
|
|
|
queryKey() {
|
|
|
|
this.queryingKey = true;
|
|
|
|
return navigator.credentials.get({
|
|
|
|
publicKey: {
|
2020-05-08 17:20:22 -06:00
|
|
|
challenge: byteify(this.challengeData.challenge, 'base64'),
|
2019-07-03 05:18:07 -06:00
|
|
|
allowCredentials: this.challengeData.securityKeys.map(key => ({
|
2020-05-08 17:20:22 -06:00
|
|
|
id: byteify(key.id, 'hex'),
|
2019-07-03 05:18:07 -06:00
|
|
|
type: 'public-key',
|
2020-01-26 13:38:40 -07:00
|
|
|
transports: ['usb', 'nfc', 'ble', 'internal']
|
2019-07-03 05:18:07 -06:00
|
|
|
})),
|
|
|
|
timeout: 60 * 1000
|
|
|
|
}
|
2019-07-04 16:48:12 -06:00
|
|
|
}).catch(() => {
|
2019-07-03 05:18:07 -06:00
|
|
|
this.queryingKey = false;
|
|
|
|
return Promise.reject(null);
|
|
|
|
}).then(credential => {
|
|
|
|
this.queryingKey = false;
|
|
|
|
this.signing = true;
|
2020-10-17 05:12:00 -06:00
|
|
|
return os.api('signin', {
|
2019-07-03 05:18:07 -06:00
|
|
|
username: this.username,
|
|
|
|
password: this.password,
|
2020-05-08 17:20:22 -06:00
|
|
|
signature: hexify(credential.response.signature),
|
|
|
|
authenticatorData: hexify(credential.response.authenticatorData),
|
|
|
|
clientDataJSON: hexify(credential.response.clientDataJSON),
|
2019-07-03 05:18:07 -06:00
|
|
|
credentialId: credential.id,
|
|
|
|
challengeId: this.challengeData.challengeId
|
|
|
|
});
|
2019-01-18 00:46:56 -07:00
|
|
|
}).then(res => {
|
2020-01-29 12:37:25 -07:00
|
|
|
this.$emit('login', res);
|
2020-10-17 05:12:00 -06:00
|
|
|
this.onLogin(res);
|
2019-07-03 05:18:07 -06:00
|
|
|
}).catch(err => {
|
2019-07-04 16:48:12 -06:00
|
|
|
if (err === null) return;
|
2020-10-17 05:12:00 -06:00
|
|
|
os.dialog({
|
2019-04-15 22:05:10 -06:00
|
|
|
type: 'error',
|
2020-12-25 18:47:36 -07:00
|
|
|
text: this.$ts.signinFailed
|
2019-04-15 22:05:10 -06:00
|
|
|
});
|
2018-02-10 00:22:14 -07:00
|
|
|
this.signing = false;
|
|
|
|
});
|
2019-07-03 05:18:07 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
onSubmit() {
|
|
|
|
this.signing = true;
|
|
|
|
if (!this.totpLogin && this.user && this.user.twoFactorEnabled) {
|
|
|
|
if (window.PublicKeyCredential && this.user.securityKeys) {
|
2020-10-17 05:12:00 -06:00
|
|
|
os.api('signin', {
|
2019-07-03 05:18:07 -06:00
|
|
|
username: this.username,
|
|
|
|
password: this.password
|
|
|
|
}).then(res => {
|
|
|
|
this.totpLogin = true;
|
|
|
|
this.signing = false;
|
|
|
|
this.challengeData = res;
|
|
|
|
return this.queryKey();
|
2019-07-04 16:48:12 -06:00
|
|
|
}).catch(() => {
|
2020-10-17 05:12:00 -06:00
|
|
|
os.dialog({
|
2019-07-04 16:48:12 -06:00
|
|
|
type: 'error',
|
2020-12-25 18:47:36 -07:00
|
|
|
text: this.$ts.signinFailed
|
2019-07-04 16:48:12 -06:00
|
|
|
});
|
|
|
|
this.challengeData = null;
|
|
|
|
this.totpLogin = false;
|
|
|
|
this.signing = false;
|
2019-07-03 05:18:07 -06:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.totpLogin = true;
|
|
|
|
this.signing = false;
|
|
|
|
}
|
|
|
|
} else {
|
2020-10-17 05:12:00 -06:00
|
|
|
os.api('signin', {
|
2019-07-03 05:18:07 -06:00
|
|
|
username: this.username,
|
|
|
|
password: this.password,
|
|
|
|
token: this.user && this.user.twoFactorEnabled ? this.token : undefined
|
|
|
|
}).then(res => {
|
2020-01-29 12:37:25 -07:00
|
|
|
this.$emit('login', res);
|
2020-10-17 05:12:00 -06:00
|
|
|
this.onLogin(res);
|
2019-07-03 05:18:07 -06:00
|
|
|
}).catch(() => {
|
2020-10-17 05:12:00 -06:00
|
|
|
os.dialog({
|
2019-07-03 05:18:07 -06:00
|
|
|
type: 'error',
|
2020-12-25 18:47:36 -07:00
|
|
|
text: this.$ts.loginFailed
|
2019-07-03 05:18:07 -06:00
|
|
|
});
|
|
|
|
this.signing = false;
|
|
|
|
});
|
|
|
|
}
|
2018-02-10 00:22:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-01-29 12:37:25 -07:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.eppvobhk {
|
2020-10-30 18:39:22 -06: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 12:37:25 -07:00
|
|
|
}
|
|
|
|
}
|
2018-02-10 00:22:14 -07:00
|
|
|
</style>
|