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