2019-03-29 17:08:54 +00:00
|
|
|
<template>
|
|
|
|
|
<div>
|
2019-05-21 10:13:21 +00:00
|
|
|
<div
|
|
|
|
|
v-if="error"
|
|
|
|
|
class="mb-10 bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative"
|
|
|
|
|
role="alert"
|
|
|
|
|
>
|
|
|
|
|
<span class="block sm:inline">{{ error }}</span>
|
2019-03-29 17:08:54 +00:00
|
|
|
</div>
|
2019-05-21 10:13:21 +00:00
|
|
|
<div v-if="registeruser" class="my-6 flex justify-center items-center">
|
|
|
|
|
<div>
|
|
|
|
|
<RegisterForm
|
|
|
|
|
:remote-username="registeruser.remote_user_info.LoginName"
|
|
|
|
|
:username="registeruser.remote_user_info.LoginName"
|
|
|
|
|
v-on:login="doRegister(registeruser.remote_source_name, $event.username, registeruser.remote_source_login_name, registeruser.remote_source_login_password)"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div v-else>
|
|
|
|
|
<div
|
|
|
|
|
class="my-6 flex justify-center items-center"
|
|
|
|
|
v-for="rs in remotesources"
|
|
|
|
|
v-bind:key="rs.id"
|
|
|
|
|
>
|
2019-07-05 11:49:16 +00:00
|
|
|
<div v-if="rs.registration_enabled">
|
|
|
|
|
<LoginForm
|
|
|
|
|
action="Register"
|
|
|
|
|
:name="rs.name"
|
|
|
|
|
v-if="rs.auth_type == 'password'"
|
|
|
|
|
v-on:login="doAuthorize(rs.name, $event.username, $event.password)"
|
|
|
|
|
/>
|
|
|
|
|
<div v-else class="w-full max-w-xs">
|
|
|
|
|
<div class="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4">
|
|
|
|
|
<div class="flex justify-center">
|
|
|
|
|
<button
|
|
|
|
|
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline"
|
|
|
|
|
@click="doAuthorize(rs.name)"
|
|
|
|
|
>Register with {{rs.name}}</button>
|
|
|
|
|
</div>
|
2019-05-21 10:13:21 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2019-03-29 17:08:54 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import { mapGetters } from "vuex";
|
|
|
|
|
|
|
|
|
|
import LoginForm from "@/components/loginform";
|
|
|
|
|
import RegisterForm from "@/components/registerform";
|
|
|
|
|
|
2019-05-21 09:06:38 +00:00
|
|
|
import { fetchRemoteSources, register } from "@/util/data";
|
2019-05-13 14:29:47 +00:00
|
|
|
|
2019-05-21 10:13:21 +00:00
|
|
|
import { authorizeurl, fetch, doLogout } from "@/util/auth";
|
2019-03-29 17:08:54 +00:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: "Register",
|
|
|
|
|
components: {
|
|
|
|
|
LoginForm,
|
|
|
|
|
RegisterForm
|
|
|
|
|
},
|
|
|
|
|
data: function() {
|
|
|
|
|
return {
|
2019-05-21 09:06:38 +00:00
|
|
|
error: null,
|
2019-03-29 17:08:54 +00:00
|
|
|
remotesources: null
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
...mapGetters(["registeruser"])
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
2019-05-13 14:29:47 +00:00
|
|
|
async fetchRemoteSources() {
|
|
|
|
|
let { data, error } = await fetchRemoteSources();
|
|
|
|
|
if (error) {
|
|
|
|
|
this.$store.dispatch("setError", error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.remotesources = data;
|
2019-03-29 17:08:54 +00:00
|
|
|
},
|
2019-05-21 09:06:38 +00:00
|
|
|
async doAuthorize(remotesourcename, username, password) {
|
2019-03-29 17:08:54 +00:00
|
|
|
let u = authorizeurl();
|
|
|
|
|
let res = await (await fetch(u, {
|
|
|
|
|
method: "POST",
|
|
|
|
|
body: JSON.stringify({
|
2019-05-21 09:06:38 +00:00
|
|
|
remote_source_name: remotesourcename,
|
2019-03-29 17:08:54 +00:00
|
|
|
login_name: username,
|
|
|
|
|
password: password
|
|
|
|
|
})
|
|
|
|
|
})).json();
|
|
|
|
|
|
|
|
|
|
if (res.oauth2_redirect) {
|
|
|
|
|
window.location = res.oauth2_redirect;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.$store.dispatch("setRegisterUser", {
|
|
|
|
|
remote_user_info: res.remote_user_info,
|
|
|
|
|
remote_source_name: res.remote_source_name,
|
|
|
|
|
remote_source_login_name: username,
|
|
|
|
|
remote_source_login_password: password
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
async doRegister(
|
2019-05-21 09:06:38 +00:00
|
|
|
remotesourcename,
|
2019-03-29 17:08:54 +00:00
|
|
|
username,
|
|
|
|
|
remote_login_name,
|
|
|
|
|
remote_login_password
|
|
|
|
|
) {
|
2019-05-21 09:06:38 +00:00
|
|
|
this.error = null;
|
2019-03-29 17:08:54 +00:00
|
|
|
|
2019-05-21 09:06:38 +00:00
|
|
|
let { data, error } = await register(
|
|
|
|
|
username,
|
|
|
|
|
remotesourcename,
|
|
|
|
|
remote_login_name,
|
|
|
|
|
remote_login_password
|
|
|
|
|
);
|
|
|
|
|
if (error) {
|
|
|
|
|
// set local login error on failed login.
|
|
|
|
|
this.error = error;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (data.oauth2_redirect) {
|
|
|
|
|
window.location = data.oauth2_redirect;
|
2019-03-29 17:08:54 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.$router.push({ name: "home" });
|
|
|
|
|
}
|
|
|
|
|
},
|
2019-07-05 11:41:43 +00:00
|
|
|
mounted: function() {
|
|
|
|
|
this.$store.dispatch("setError", null);
|
|
|
|
|
},
|
2019-03-29 17:08:54 +00:00
|
|
|
created: function() {
|
2019-05-13 14:29:47 +00:00
|
|
|
doLogout();
|
|
|
|
|
this.fetchRemoteSources();
|
2019-03-29 17:08:54 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|