pleroma-fe/src/components/login_form/login_form.js

61 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-10-26 15:20:39 +02:00
import oauthApi from '../../services/new_api/oauth.js'
2016-10-27 18:02:41 +02:00
const LoginForm = {
data: () => ({
user: {},
authError: false
2016-10-27 18:02:41 +02:00
}),
computed: {
2018-11-07 16:56:12 +01:00
loginMethod () { return this.$store.state.instance.loginMethod },
loggingIn () { return this.$store.state.users.loggingIn },
2018-09-09 20:21:23 +02:00
registrationOpen () { return this.$store.state.instance.registrationOpen }
2016-10-27 18:02:41 +02:00
},
methods: {
2018-10-26 15:16:23 +02:00
oAuthLogin () {
const data = {
...this.$store.state.oauth,
2018-10-26 15:16:23 +02:00
instance: this.$store.state.instance.server,
commit: this.$store.commit
}
oauthApi.getOrCreateApp(data)
.then((app) => { oauthApi.login({ ...app, ...data }) })
2018-10-26 15:16:23 +02:00
},
2016-10-27 18:02:41 +02:00
submit () {
2018-11-07 16:56:12 +01:00
const data = {
...this.$store.state.oauth,
instance: this.$store.state.instance.server,
commit: this.$store.commit
2018-11-07 16:56:12 +01:00
}
this.clearError()
2018-11-07 16:56:12 +01:00
oauthApi.getOrCreateApp(data).then((app) => {
oauthApi.getTokenWithCredentials(
{
...app,
2018-11-07 16:56:12 +01:00
instance: data.instance,
username: this.user.username,
2019-01-28 16:48:00 +01:00
password: this.user.password
}
).then(async (result) => {
2019-01-28 16:48:00 +01:00
if (result.error) {
this.authError = result.error
this.user.password = ''
return
}
this.$store.commit('setToken', result.access_token)
try {
await this.$store.dispatch('loginUser', result.access_token)
2019-04-09 18:19:48 +02:00
this.$router.push({name: 'friends'})
} catch (e) {
console.log(e)
}
2019-01-28 16:48:00 +01:00
})
2018-11-07 16:56:12 +01:00
})
},
clearError () {
this.authError = false
2016-10-27 18:02:41 +02:00
}
}
}
export default LoginForm