agola-web/src/views/Login.vue

88 lines
2.2 KiB
Vue
Raw Normal View History

2018-12-09 13:21:20 +00:00
<template>
<div>
<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>
</div>
<div>
<div
class="my-6 flex justify-center items-center"
v-for="rs in remotesources"
v-bind:key="rs.id"
>
2019-03-29 17:08:54 +00:00
<LoginForm
action="Login"
2018-12-09 13:21:20 +00:00
:name="rs.name"
v-if="rs.auth_type == 'password'"
v-on:login="doLogin($event.username, $event.password, rs.name)"
2018-12-09 13:21:20 +00:00
/>
<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="doLogin(null, null, rs.name)"
>Login with {{rs.name}}</button>
</div>
</div>
</div>
2018-12-09 13:21:20 +00:00
</div>
</div>
</div>
</template>
<script>
import { fetchRemoteSources, login } from "@/util/data";
import { setLoggedUser, doLogout } from "@/util/auth";
2019-05-06 15:57:52 +00:00
2019-03-29 17:08:54 +00:00
import LoginForm from "@/components/loginform";
2018-12-09 13:21:20 +00:00
export default {
name: "Login",
components: {
2019-03-29 17:08:54 +00:00
LoginForm
2018-12-09 13:21:20 +00:00
},
data: function() {
return {
error: null,
2018-12-09 13:21:20 +00:00
remotesources: null
};
},
methods: {
async fetchRemoteSources() {
let { data, error } = await fetchRemoteSources();
if (error) {
this.$store.dispatch("setError", error);
return;
}
this.remotesources = data;
2018-12-09 13:21:20 +00:00
},
async doLogin(username, password, remotesourcename) {
this.error = null;
let { data, error } = await login(username, password, remotesourcename);
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;
}
setLoggedUser(data.token, data.user);
2019-03-29 17:08:54 +00:00
this.$router.push({ name: "home" });
2018-12-09 13:21:20 +00:00
}
},
created: function() {
doLogout();
this.fetchRemoteSources();
2018-12-09 13:21:20 +00:00
}
};
</script>