agola-web/src/views/Login.vue

78 lines
1.8 KiB
Vue
Raw Normal View History

2018-12-09 13:21:20 +00:00
<template>
<div>
<div v-if="error" class="message is-danger">
<div class="message-header">
<p>Login error</p>
</div>
<div class="message-body">{{ error }}</div>
</div>
2018-12-09 13:21:20 +00:00
<div class="column is-4 is-offset-4">
<div class="box" 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
/>
<button
v-else
class="button is-info is-fullwidth"
@click="doLogin(null, null, rs.name)"
2018-12-09 13:21:20 +00:00
>Login with {{rs.name}}</button>
</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>