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>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'"
|
2019-05-13 14:29:47 +00:00
|
|
|
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"
|
2019-05-13 14:29:47 +00:00
|
|
|
@click="doLogin(null, null, rs.name)"
|
2018-12-09 13:21:20 +00:00
|
|
|
>Login with {{rs.name}}</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2019-05-13 14:29:47 +00:00
|
|
|
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 {
|
2019-05-13 14:29:47 +00:00
|
|
|
error: null,
|
2018-12-09 13:21:20 +00:00
|
|
|
remotesources: null
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
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;
|
2018-12-09 13:21:20 +00:00
|
|
|
},
|
2019-05-13 14:29:47 +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;
|
|
|
|
|
}
|
2019-05-13 14:29:47 +00:00
|
|
|
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() {
|
2019-05-13 14:29:47 +00:00
|
|
|
doLogout();
|
|
|
|
|
this.fetchRemoteSources();
|
2018-12-09 13:21:20 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|