Whalebird-desktop-client-ma.../src/renderer/components/Login/LoginForm.vue

121 lines
2.8 KiB
Vue
Raw Normal View History

2018-03-10 14:44:15 +01:00
<template>
<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="domainName" placeholder="mastodon.social"></el-input>
2018-03-10 14:44:15 +01:00
</el-form-item>
<!-- Dummy form to guard submitting with enter -->
<el-form-item class="hidden">
<el-input></el-input>
</el-form-item>
<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">
<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({
selectedInstance: state => state.Login.selectedInstance,
searching: state => state.Login.searching
}),
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()
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
},
confirm () {
this.$store.dispatch('Login/confirmInstance', this.domainName)
.then(() => {
this.$message({
message: `${this.domainName} is confirmed, please login`,
type: 'success'
})
})
.catch(() => {
this.$message({
message: `${this.domainName} does not exist`,
type: 'error'
})
})
2018-03-10 14:44:15 +01:00
}
}
}
</script>
<style lang="scss" scoped>
.login-form {
2018-03-10 14:44:15 +01:00
margin: 0 auto;
width: 300px;
.instance-group {
text-align: left;
margin: 0 auto;
}
2018-03-14 08:12:44 +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;
}
.hidden {
display: none;
}
2018-03-10 14:44:15 +01:00
}
</style>