2018-02-10 07:22:14 +00:00
|
|
|
<template>
|
2020-01-29 19:37:25 +00:00
|
|
|
<form class="eppvobhk" :class="{ signing, totpLogin }" @submit.prevent="onSubmit">
|
2018-06-15 22:40:07 +00:00
|
|
|
<div class="avatar" :style="{ backgroundImage: user ? `url('${ user.avatarUrl }')` : null }" v-show="withAvatar"></div>
|
2019-07-03 11:18:07 +00:00
|
|
|
<div class="normal-signin" v-if="!totpLogin">
|
2020-01-29 19:37:25 +00:00
|
|
|
<mk-input v-model="username" type="text" pattern="^[a-zA-Z0-9_]+$" spellcheck="false" autofocus required @input="onUsernameChange">
|
2019-07-03 11:18:07 +00:00
|
|
|
<span>{{ $t('username') }}</span>
|
|
|
|
<template #prefix>@</template>
|
|
|
|
<template #suffix>@{{ host }}</template>
|
2020-01-29 19:37:25 +00:00
|
|
|
</mk-input>
|
|
|
|
<mk-input v-model="password" type="password" :with-password-toggle="true" v-if="!user || user && !user.usePasswordLessLogin" required>
|
2019-07-03 11:18:07 +00:00
|
|
|
<span>{{ $t('password') }}</span>
|
2020-01-29 19:37:25 +00:00
|
|
|
<template #prefix><fa :icon="faLock"/></template>
|
|
|
|
</mk-input>
|
|
|
|
<mk-button type="submit" primary :disabled="signing" style="margin: 0 auto;">{{ signing ? $t('loggingIn') : $t('login') }}</mk-button>
|
2020-03-28 13:25:52 +00:00
|
|
|
<a class="_panel _button" style="margin: 8px auto;" v-if="meta && meta.enableTwitterIntegration" :href="`${apiUrl}/signin/twitter`"><fa :icon="faTwitter" style="margin-right: 4px;"/>{{ $t('signinWith', { x: 'Twitter' }) }}</a>
|
|
|
|
<a class="_panel _button" style="margin: 8px auto;" v-if="meta && meta.enableGithubIntegration" :href="`${apiUrl}/signin/github`"><fa :icon="faGithub" style="margin-right: 4px;"/>{{ $t('signinWith', { x: 'GitHub' }) }}</a>
|
|
|
|
<a class="_panel _button" style="margin: 8px auto;" v-if="meta && meta.enableDiscordIntegration" :href="`${apiUrl}/signin/discord`"><fa :icon="faDiscord" style="margin-right: 4px;"/>{{ $t('signinWith', { x: 'Discord' }) }}</a>
|
2019-07-03 11:18:07 +00: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-02-11 21:27:11 +00:00
|
|
|
<p>{{ $t('tapSecurityKey') }}</p>
|
2020-01-29 19:37:25 +00:00
|
|
|
<mk-button @click="queryKey" v-if="!queryingKey">
|
2020-02-11 21:27:11 +00:00
|
|
|
{{ $t('retry') }}
|
2020-01-29 19:37:25 +00:00
|
|
|
</mk-button>
|
2019-07-03 11:18:07 +00:00
|
|
|
</div>
|
|
|
|
<div class="or-hr" v-if="user && user.securityKeys">
|
|
|
|
<p class="or-msg">{{ $t('or') }}</p>
|
|
|
|
</div>
|
|
|
|
<div class="twofa-group totp-group">
|
2020-01-29 19:37:25 +00:00
|
|
|
<p style="margin-bottom:0;">{{ $t('twoStepAuthentication') }}</p>
|
|
|
|
<mk-input v-model="password" type="password" :with-password-toggle="true" v-if="user && user.usePasswordLessLogin" required>
|
2019-07-06 16:38:36 +00:00
|
|
|
<span>{{ $t('password') }}</span>
|
2020-01-29 19:37:25 +00:00
|
|
|
<template #prefix><fa :icon="faLock"/></template>
|
|
|
|
</mk-input>
|
2020-01-29 20:45:15 +00:00
|
|
|
<mk-input v-model="token" type="text" pattern="^[0-9]{6}$" autocomplete="off" spellcheck="false" required>
|
2020-01-29 19:37:25 +00:00
|
|
|
<span>{{ $t('token') }}</span>
|
|
|
|
<template #prefix><fa :icon="faGavel"/></template>
|
|
|
|
</mk-input>
|
|
|
|
<mk-button type="submit" :disabled="signing" primary style="margin: 0 auto;">{{ signing ? $t('loggingIn') : $t('login') }}</mk-button>
|
2019-07-03 11:18:07 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2018-02-10 07:22:14 +00:00
|
|
|
</form>
|
|
|
|
</template>
|
|
|
|
|
2018-02-11 03:08:43 +00:00
|
|
|
<script lang="ts">
|
2018-02-10 07:22:14 +00:00
|
|
|
import Vue from 'vue';
|
2018-11-11 03:35:30 +00:00
|
|
|
import { toUnicode } from 'punycode';
|
2020-01-29 19:37:25 +00:00
|
|
|
import { faLock, faGavel } from '@fortawesome/free-solid-svg-icons';
|
2020-02-11 21:27:11 +00:00
|
|
|
import { faTwitter, faDiscord, faGithub } from '@fortawesome/free-brands-svg-icons';
|
2020-01-29 19:37:25 +00:00
|
|
|
import MkButton from './ui/button.vue';
|
|
|
|
import MkInput from './ui/input.vue';
|
|
|
|
import { apiUrl, host } from '../config';
|
2020-05-08 23:20:22 +00:00
|
|
|
import { byteify, hexify } from '../scripts/2fa';
|
2018-02-10 07:22:14 +00:00
|
|
|
|
|
|
|
export default Vue.extend({
|
2020-01-29 19:37:25 +00:00
|
|
|
components: {
|
|
|
|
MkButton,
|
|
|
|
MkInput,
|
|
|
|
},
|
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
|
|
|
|
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,
|
2020-02-11 21:27:11 +00:00
|
|
|
faLock, faGavel, faTwitter, faDiscord, faGithub
|
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() {
|
|
|
|
return this.$store.state.instance.meta;
|
|
|
|
},
|
|
|
|
},
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2020-02-10 14:17:42 +00:00
|
|
|
created() {
|
2020-01-29 19:37:25 +00:00
|
|
|
if (this.autoSet) {
|
|
|
|
this.$once('login', res => {
|
|
|
|
localStorage.setItem('i', res.i);
|
|
|
|
location.reload();
|
|
|
|
});
|
|
|
|
}
|
2018-11-16 17:13:01 +00:00
|
|
|
},
|
2018-12-18 15:40:29 +00:00
|
|
|
|
2018-02-10 07:22:14 +00:00
|
|
|
methods: {
|
|
|
|
onUsernameChange() {
|
2018-11-08 23:13:34 +00:00
|
|
|
this.$root.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
|
|
|
|
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;
|
|
|
|
return this.$root.api('signin', {
|
|
|
|
username: this.username,
|
|
|
|
password: this.password,
|
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,
|
|
|
|
challengeId: this.challengeData.challengeId
|
|
|
|
});
|
2019-01-18 07:46:56 +00:00
|
|
|
}).then(res => {
|
2020-01-29 19:37:25 +00:00
|
|
|
this.$emit('login', res);
|
2019-07-03 11:18:07 +00:00
|
|
|
}).catch(err => {
|
2019-07-04 22:48:12 +00:00
|
|
|
if (err === null) return;
|
2019-04-16 04:05:10 +00:00
|
|
|
this.$root.dialog({
|
|
|
|
type: 'error',
|
2020-03-22 01:51:40 +00:00
|
|
|
text: this.$t('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) {
|
2019-07-04 22:48:12 +00:00
|
|
|
this.$root.api('signin', {
|
2019-07-03 11:18:07 +00:00
|
|
|
username: this.username,
|
|
|
|
password: this.password
|
|
|
|
}).then(res => {
|
|
|
|
this.totpLogin = true;
|
|
|
|
this.signing = false;
|
|
|
|
this.challengeData = res;
|
|
|
|
return this.queryKey();
|
2019-07-04 22:48:12 +00:00
|
|
|
}).catch(() => {
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'error',
|
2020-03-22 01:51:40 +00:00
|
|
|
text: this.$t('signinFailed')
|
2019-07-04 22:48:12 +00:00
|
|
|
});
|
|
|
|
this.challengeData = null;
|
|
|
|
this.totpLogin = false;
|
|
|
|
this.signing = false;
|
2019-07-03 11:18:07 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.totpLogin = true;
|
|
|
|
this.signing = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.$root.api('signin', {
|
|
|
|
username: this.username,
|
|
|
|
password: this.password,
|
|
|
|
token: this.user && this.user.twoFactorEnabled ? this.token : undefined
|
|
|
|
}).then(res => {
|
2020-01-29 19:37:25 +00:00
|
|
|
this.$emit('login', res);
|
2019-07-03 11:18:07 +00:00
|
|
|
}).catch(() => {
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'error',
|
2020-01-29 19:37:25 +00:00
|
|
|
text: this.$t('loginFailed')
|
2019-07-03 11:18:07 +00:00
|
|
|
});
|
|
|
|
this.signing = false;
|
|
|
|
});
|
|
|
|
}
|
2018-02-10 07:22:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.eppvobhk {
|
|
|
|
> .avatar {
|
|
|
|
margin: 0 auto 0 auto;
|
|
|
|
width: 64px;
|
|
|
|
height: 64px;
|
|
|
|
background: #ddd;
|
|
|
|
background-position: center;
|
|
|
|
background-size: cover;
|
|
|
|
border-radius: 100%;
|
|
|
|
}
|
|
|
|
}
|
2018-02-10 07:22:14 +00:00
|
|
|
</style>
|