2018-12-09 13:21:20 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
2019-05-13 14:29:47 +00:00
|
|
|
<div v-if="error" class="message is-danger">
|
|
|
|
<div class="message-header">
|
|
|
|
<p>Error</p>
|
|
|
|
</div>
|
|
|
|
<div class="message-body">{{ error }}</div>
|
|
|
|
</div>
|
2018-12-09 13:21:20 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-05-13 14:29:47 +00:00
|
|
|
import { fetch } from "@/util/data";
|
|
|
|
|
|
|
|
import { oauth2callbackurl, setLoggedUser } from "@/util/auth";
|
2018-12-09 13:21:20 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {},
|
|
|
|
name: "Oauth2",
|
|
|
|
props: {},
|
|
|
|
data() {
|
|
|
|
return {
|
2019-05-13 14:29:47 +00:00
|
|
|
error: null,
|
2018-12-09 13:21:20 +00:00
|
|
|
run: null,
|
|
|
|
code: this.$route.query.code,
|
2019-03-29 17:08:54 +00:00
|
|
|
polling: null,
|
|
|
|
username: null
|
2018-12-09 13:21:20 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
2019-03-29 17:08:54 +00:00
|
|
|
async doOauth2() {
|
2018-12-09 13:21:20 +00:00
|
|
|
let u = oauth2callbackurl();
|
|
|
|
u.searchParams.append("code", this.$route.query.code);
|
|
|
|
u.searchParams.append("state", this.$route.query.state);
|
2019-05-13 14:29:47 +00:00
|
|
|
let { data, error } = await fetch(u);
|
|
|
|
if (error) {
|
|
|
|
// set local login error on failed oauth2.
|
|
|
|
this.error = error;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.request_type === "loginuser") {
|
|
|
|
setLoggedUser(data.response.token, data.response.user);
|
2019-03-29 17:08:54 +00:00
|
|
|
this.$router.push("/");
|
2019-05-13 14:29:47 +00:00
|
|
|
} else if (data.request_type === "authorize") {
|
|
|
|
this.$store.dispatch("setRegisterUser", data.response);
|
2019-03-29 17:08:54 +00:00
|
|
|
this.$router.push("/register");
|
2019-05-17 21:45:20 +00:00
|
|
|
} else if (data.request_type === "createuserla") {
|
|
|
|
this.$router.push({
|
|
|
|
name: "user settings",
|
|
|
|
params: { username: this.username }
|
|
|
|
});
|
2019-03-29 17:08:54 +00:00
|
|
|
}
|
2018-12-09 13:21:20 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
created: function() {
|
|
|
|
this.doOauth2();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|