2018-03-10 14:44:15 +01:00
|
|
|
<template>
|
|
|
|
<div id="login_form">
|
2018-03-22 07:17:31 +01:00
|
|
|
<el-form ref="loginForm" label-width="120px" label-position="top" v-on:submit.prevent="confirm" class="login-form">
|
2018-03-23 01:31:08 +01:00
|
|
|
<el-form-item label="At first, let's login a mastodon instance. Please write host name which you want to login.">
|
|
|
|
<el-input v-model="loginForm.domainName" placeholder="mastodon.social"></el-input>
|
2018-03-10 14:44:15 +01:00
|
|
|
</el-form-item>
|
2018-03-22 07:17:31 +01:00
|
|
|
<!-- Dummy form to guard submitting with enter -->
|
|
|
|
<el-form-item class="hidden">
|
|
|
|
<el-input></el-input>
|
|
|
|
</el-form-item>
|
2018-03-22 02:46:17 +01:00
|
|
|
<el-button type="primary" @click="confirm" v-if="selectedInstance === null">Search</el-button>
|
2018-03-10 14:44:15 +01:00
|
|
|
<el-form-item class="submit">
|
2018-03-22 07:17:31 +01:00
|
|
|
<el-button type="primary" class="login" @click="login" v-if="selectedInstance !== null">Login</el-button>
|
2018-03-10 14:44:15 +01:00
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { mapState } from 'vuex'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'login-form',
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
loginForm: {
|
2018-03-20 14:58:50 +01:00
|
|
|
domainName: ''
|
2018-03-10 14:44:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapState({
|
|
|
|
selectedInstance: state => state.Login.selectedInstance
|
|
|
|
})
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
login () {
|
2018-03-10 15:28:55 +01:00
|
|
|
const loading = this.$loading({
|
|
|
|
lock: true,
|
|
|
|
text: 'Loading',
|
|
|
|
spinner: 'el-icon-loading',
|
|
|
|
background: 'rgba(0, 0, 0, 0.7)'
|
|
|
|
})
|
2018-03-10 14:44:15 +01:00
|
|
|
this.$store.dispatch('Login/fetchLogin', this.selectedInstance)
|
|
|
|
.then((url) => {
|
2018-03-10 15:28:55 +01:00
|
|
|
loading.close()
|
2018-03-21 14:32:32 +01:00
|
|
|
this.$store.dispatch('Login/pageBack')
|
2018-03-10 14:44:15 +01:00
|
|
|
this.$router.push({ path: '/authorize' })
|
|
|
|
})
|
2018-03-10 15:28:55 +01:00
|
|
|
.catch(() => {
|
|
|
|
loading.close()
|
|
|
|
this.$message({
|
|
|
|
message: 'Could not get authorize url',
|
|
|
|
type: 'error'
|
|
|
|
})
|
|
|
|
})
|
2018-03-10 14:44:15 +01:00
|
|
|
},
|
2018-03-20 14:58:50 +01:00
|
|
|
confirm () {
|
|
|
|
this.$store.dispatch('Login/confirmInstance', this.loginForm.domainName)
|
|
|
|
.then(() => {
|
|
|
|
this.$message({
|
|
|
|
message: `${this.loginForm.domainName} is confirmed, please login`,
|
|
|
|
type: 'success'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.$message({
|
|
|
|
message: `${this.loginForm.domainName} does not exist`,
|
|
|
|
type: 'error'
|
|
|
|
})
|
|
|
|
})
|
2018-03-10 14:44:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2018-03-20 14:58:50 +01:00
|
|
|
.login-form {
|
2018-03-10 14:44:15 +01:00
|
|
|
margin: 0 auto;
|
|
|
|
width: 300px;
|
|
|
|
|
2018-03-20 14:58:50 +01:00
|
|
|
.instance-group {
|
|
|
|
text-align: left;
|
|
|
|
margin: 0 auto;
|
|
|
|
}
|
2018-03-14 08:12:44 +01:00
|
|
|
|
2018-03-20 14:58:50 +01:00
|
|
|
.instance-list {
|
|
|
|
display: block;
|
|
|
|
margin-left: 0 !important;
|
|
|
|
border-color: #606266;
|
|
|
|
color: #dcdfe6;
|
|
|
|
margin-bottom: 10px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.submit {
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.back {
|
|
|
|
margin-right: 20px;
|
|
|
|
}
|
2018-03-22 07:17:31 +01:00
|
|
|
|
|
|
|
.hidden {
|
|
|
|
display: none;
|
|
|
|
}
|
2018-03-10 14:44:15 +01:00
|
|
|
}
|
|
|
|
</style>
|