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