2018-12-09 13:21:20 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<div>{{code}}</div>
|
2019-03-29 17:08:54 +00:00
|
|
|
<div>{{username}}</div>
|
2018-12-09 13:21:20 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-03-29 17:08:54 +00:00
|
|
|
import { apiurl, oauth2callbackurl, login, fetch } from "@/util/auth";
|
2018-12-09 13:21:20 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {},
|
|
|
|
name: "Oauth2",
|
|
|
|
props: {},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
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-03-29 17:08:54 +00:00
|
|
|
let res = await (await fetch(u)).json();
|
|
|
|
console.log("oauth2 result", res);
|
|
|
|
if (res.request_type === "loginuser") {
|
|
|
|
login(res.response.token, res.response.user);
|
|
|
|
this.$router.push("/");
|
|
|
|
} else if (res.request_type === "authorize") {
|
|
|
|
this.$store.dispatch("setRegisterUser", res.response);
|
|
|
|
this.$router.push("/register");
|
|
|
|
}
|
2018-12-09 13:21:20 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
created: function() {
|
|
|
|
this.doOauth2();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|