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