2018-02-10 07:22:14 +00:00
|
|
|
<template>
|
2018-02-11 03:42:02 +00:00
|
|
|
<form class="mk-signin" :class="{ signing }" @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-02-25 11:08:56 +00:00
|
|
|
<ui-input v-model="username" type="text" pattern="^[a-zA-Z0-9_]+$" spellcheck="false" autofocus required @input="onUsernameChange">
|
2018-11-08 18:44:35 +00:00
|
|
|
<span>{{ $t('username') }}</span>
|
2019-02-18 02:13:56 +00:00
|
|
|
<template #prefix>@</template>
|
|
|
|
<template #suffix>@{{ host }}</template>
|
2018-06-15 10:56:18 +00:00
|
|
|
</ui-input>
|
2019-02-25 11:08:56 +00:00
|
|
|
<ui-input v-model="password" type="password" :with-password-toggle="true" required>
|
2018-11-08 18:44:35 +00:00
|
|
|
<span>{{ $t('password') }}</span>
|
2019-02-18 02:13:56 +00:00
|
|
|
<template #prefix><fa icon="lock"/></template>
|
2018-06-15 10:56:18 +00:00
|
|
|
</ui-input>
|
2019-05-06 23:45:29 +00:00
|
|
|
<ui-input v-if="user && user.twoFactorEnabled" v-model="token" type="text" pattern="^[0-9]{6}$" autocomplete="off" spellcheck="false" required>
|
2019-01-18 04:20:32 +00:00
|
|
|
<span>{{ $t('@.2fa') }}</span>
|
2019-02-18 02:13:56 +00:00
|
|
|
<template #prefix><fa icon="gavel"/></template>
|
2019-01-18 04:20:32 +00:00
|
|
|
</ui-input>
|
2019-02-26 05:13:02 +00:00
|
|
|
<ui-button type="submit" :disabled="signing">{{ signing ? $t('signing-in') : $t('@.signin') }}</ui-button>
|
2019-05-05 00:28:24 +00:00
|
|
|
<p v-if="meta && meta.enableTwitterIntegration" style="margin: 8px 0;"><a :href="`${apiUrl}/signin/twitter`"><fa :icon="['fab', 'twitter']"/> {{ $t('signin-with-twitter') }}</a></p>
|
|
|
|
<p v-if="meta && meta.enableGithubIntegration" style="margin: 8px 0;"><a :href="`${apiUrl}/signin/github`"><fa :icon="['fab', 'github']"/> {{ $t('signin-with-github') }}</a></p>
|
|
|
|
<p v-if="meta && meta.enableDiscordIntegration" style="margin: 8px 0;"><a :href="`${apiUrl}/signin/discord`"><fa :icon="['fab', 'discord']"/> {{ $t('signin-with-discord') /* TODO: Make these layouts better */ }}</a></p>
|
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-08 18:44:35 +00:00
|
|
|
import i18n from '../../../i18n';
|
2018-08-19 13:32:25 +00:00
|
|
|
import { apiUrl, host } from '../../../config';
|
2018-11-11 03:35:30 +00:00
|
|
|
import { toUnicode } from 'punycode';
|
2018-02-10 07:22:14 +00:00
|
|
|
|
|
|
|
export default Vue.extend({
|
2018-11-08 18:44:35 +00:00
|
|
|
i18n: i18n('common/views/components/signin.vue'),
|
2018-12-18 15:40:29 +00:00
|
|
|
|
2018-06-15 22:40:07 +00:00
|
|
|
props: {
|
|
|
|
withAvatar: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: true
|
|
|
|
}
|
|
|
|
},
|
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),
|
|
|
|
meta: null
|
2018-02-10 07:22:14 +00:00
|
|
|
};
|
|
|
|
},
|
2018-12-18 15:40:29 +00:00
|
|
|
|
2018-11-16 17:13:01 +00:00
|
|
|
created() {
|
|
|
|
this.$root.getMeta().then(meta => {
|
|
|
|
this.meta = meta;
|
|
|
|
});
|
|
|
|
},
|
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
|
|
|
|
2018-02-10 07:22:14 +00:00
|
|
|
onSubmit() {
|
|
|
|
this.signing = true;
|
|
|
|
|
2018-11-08 23:13:34 +00:00
|
|
|
this.$root.api('signin', {
|
2018-08-20 16:23:39 +00:00
|
|
|
username: this.username,
|
|
|
|
password: this.password,
|
2018-04-07 18:58:11 +00:00
|
|
|
token: this.user && this.user.twoFactorEnabled ? this.token : undefined
|
2019-01-18 07:46:56 +00:00
|
|
|
}).then(res => {
|
2018-11-28 07:19:02 +00:00
|
|
|
localStorage.setItem('i', res.i);
|
2018-02-10 07:22:14 +00:00
|
|
|
location.reload();
|
|
|
|
}).catch(() => {
|
2019-04-16 04:05:10 +00:00
|
|
|
this.$root.dialog({
|
|
|
|
type: 'error',
|
|
|
|
text: this.$t('login-failed')
|
|
|
|
});
|
2018-02-10 07:22:14 +00:00
|
|
|
this.signing = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
2018-02-11 03:42:02 +00:00
|
|
|
.mk-signin
|
2018-06-15 22:31:35 +00:00
|
|
|
color #555
|
|
|
|
|
2018-02-10 07:22:14 +00:00
|
|
|
&.signing
|
|
|
|
&, *
|
|
|
|
cursor wait !important
|
|
|
|
|
2018-06-15 22:31:35 +00:00
|
|
|
> .avatar
|
2018-09-03 14:23:50 +00:00
|
|
|
margin 0 auto 0 auto
|
2018-06-15 22:31:35 +00:00
|
|
|
width 64px
|
|
|
|
height 64px
|
|
|
|
background #ddd
|
|
|
|
background-position center
|
|
|
|
background-size cover
|
|
|
|
border-radius 100%
|
2018-02-10 07:22:14 +00:00
|
|
|
|
|
|
|
</style>
|