summaryrefslogtreecommitdiff
path: root/src/server/web/app/common/views/components/signin.vue
blob: 17154e6b311e787d7d33401fdab05f8eac56bb72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<template>
<form class="mk-signin" :class="{ signing }" @submit.prevent="onSubmit">
	<label class="user-name">
		<input v-model="username" type="text" pattern="^[a-zA-Z0-9_]+$" placeholder="%i18n:common.tags.mk-signin.username%" autofocus required @change="onUsernameChange"/>%fa:at%
	</label>
	<label class="password">
		<input v-model="password" type="password" placeholder="%i18n:common.tags.mk-signin.password%" required/>%fa:lock%
	</label>
	<label class="token" v-if="user && user.account.twoFactorEnabled">
		<input v-model="token" type="number" placeholder="%i18n:common.tags.mk-signin.token%" required/>%fa:lock%
	</label>
	<button type="submit" :disabled="signing">{{ signing ? '%i18n:common.tags.mk-signin.signing-in%' : '%i18n:common.tags.mk-signin.signin%' }}</button>
	もしくは <a :href="`${apiUrl}/signin/twitter`">Twitterでログイン</a>
</form>
</template>

<script lang="ts">
import Vue from 'vue';
import { apiUrl } from '../../../config';

export default Vue.extend({
	data() {
		return {
			signing: false,
			user: null,
			username: '',
			password: '',
			token: '',
			apiUrl,
		};
	},
	methods: {
		onUsernameChange() {
			(this as any).api('users/show', {
				username: this.username
			}).then(user => {
				this.user = user;
			});
		},
		onSubmit() {
			this.signing = true;

			(this as any).api('signin', {
				username: this.username,
				password: this.password,
				token: this.user && this.user.account.twoFactorEnabled ? this.token : undefined
			}).then(() => {
				location.reload();
			}).catch(() => {
				alert('something happened');
				this.signing = false;
			});
		}
	}
});
</script>

<style lang="stylus" scoped>
@import '~const.styl'

.mk-signin
	&.signing
		&, *
			cursor wait !important

	label
		display block
		margin 12px 0

		[data-fa]
			display block
			pointer-events none
			position absolute
			bottom 0
			top 0
			left 0
			z-index 1
			margin auto
			padding 0 16px
			height 1em
			color #898786

		input[type=text]
		input[type=password]
		input[type=number]
			user-select text
			display inline-block
			cursor auto
			padding 0 0 0 38px
			margin 0
			width 100%
			line-height 44px
			font-size 1em
			color rgba(0, 0, 0, 0.7)
			background #fff
			outline none
			border solid 1px #eee
			border-radius 4px

			&:hover
				background rgba(255, 255, 255, 0.7)
				border-color #ddd

				& + i
					color #797776

			&:focus
				background #fff
				border-color #ccc

				& + i
					color #797776

	[type=submit]
		cursor pointer
		padding 16px
		margin -6px 0 0 0
		width 100%
		font-size 1.2em
		color rgba(0, 0, 0, 0.5)
		outline none
		border none
		border-radius 0
		background transparent
		transition all .5s ease

		&:hover
			color $theme-color
			transition all .2s ease

		&:focus
			color $theme-color
			transition all .2s ease

		&:active
			color darken($theme-color, 30%)
			transition all .2s ease

		&:disabled
			opacity 0.7

</style>