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