agola-web/src/views/Login.vue

66 lines
1.5 KiB
Vue
Raw Normal View History

2018-12-09 13:21:20 +00:00
<template>
<div>
<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(rs.name, $event.username, $event.password)"
/>
<button
v-else
class="button is-info is-fullwidth"
@click="doLogin(rs.name)"
>Login with {{rs.name}}</button>
</div>
</div>
</div>
</template>
<script>
2019-03-29 17:08:54 +00:00
import LoginForm from "@/components/loginform";
2018-12-09 13:21:20 +00:00
import { apiurl, loginurl, fetch, login, logout } from "@/util/auth";
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 {
remotesources: null
};
},
methods: {
2019-03-29 17:08:54 +00:00
async getRemoteSources() {
let res = await (await fetch(apiurl("/remotesources"))).json();
this.remotesources = res;
2018-12-09 13:21:20 +00:00
},
2019-03-29 17:08:54 +00:00
async doLogin(rsName, username, password) {
2018-12-09 13:21:20 +00:00
let u = loginurl();
2019-03-29 17:08:54 +00:00
let res = await (await fetch(u, {
2018-12-09 13:21:20 +00:00
method: "POST",
body: JSON.stringify({
remote_source_name: rsName,
login_name: username,
password: password
})
2019-03-29 17:08:54 +00:00
})).json();
if (res.oauth2_redirect) {
window.location = res.oauth2_redirect;
return;
}
login(res.token, res.user);
this.$router.push({ name: "home" });
2018-12-09 13:21:20 +00:00
}
},
created: function() {
logout();
this.getRemoteSources();
}
};
</script>