2018-03-10 14:44:15 +01:00
|
|
|
<template>
|
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-04-28 19:09:45 +02:00
|
|
|
<el-form-item label="First, let's log in to a Mastodon instance. Please enter an instance domain name.">
|
2018-03-23 17:23:13 +01:00
|
|
|
<el-input v-model="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-04-04 15:34:42 +02:00
|
|
|
<el-button
|
|
|
|
type="primary"
|
|
|
|
@click="confirm"
|
|
|
|
v-if="selectedInstance === null"
|
|
|
|
v-loading="searching"
|
|
|
|
element-loading-background="rgba(0, 0, 0, 0.8)">
|
|
|
|
Search
|
|
|
|
</el-button>
|
2018-03-10 14:44:15 +01:00
|
|
|
<el-form-item class="submit">
|
2018-04-04 15:34:42 +02: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>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { mapState } from 'vuex'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'login-form',
|
|
|
|
computed: {
|
|
|
|
...mapState({
|
2018-04-04 15:34:42 +02:00
|
|
|
selectedInstance: state => state.Login.selectedInstance,
|
|
|
|
searching: state => state.Login.searching
|
2018-03-23 17:23:13 +01:00
|
|
|
}),
|
|
|
|
domainName: {
|
|
|
|
get () {
|
|
|
|
return this.$store.state.Login.domainName
|
|
|
|
},
|
|
|
|
set (value) {
|
|
|
|
this.$store.dispatch('Login/updateDomainName', value)
|
|
|
|
}
|
|
|
|
}
|
2018-03-10 14:44:15 +01:00
|
|
|
},
|
|
|
|
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 () {
|
2018-03-23 17:23:13 +01:00
|
|
|
this.$store.dispatch('Login/confirmInstance', this.domainName)
|
2018-03-20 14:58:50 +01:00
|
|
|
.then(() => {
|
|
|
|
this.$message({
|
2018-03-23 17:23:13 +01:00
|
|
|
message: `${this.domainName} is confirmed, please login`,
|
2018-03-20 14:58:50 +01:00
|
|
|
type: 'success'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.$message({
|
2018-03-23 17:23:13 +01:00
|
|
|
message: `${this.domainName} does not exist`,
|
2018-03-20 14:58:50 +01:00
|
|
|
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>
|