register/login: display if there are no remote sources

Show if no remote sources are defined or if no remote sources are register/login
enabled.
This commit is contained in:
Simone Gotti 2020-02-14 11:19:17 +01:00
parent 2878905257
commit 6eba09aa5a
2 changed files with 97 additions and 27 deletions

View File

@ -9,24 +9,40 @@
</div> </div>
<div> <div>
<div <div
class="my-6 flex justify-center items-center" v-if="!hasRemoteSources"
v-for="rs in remotesources" class="mb-10 bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative"
v-bind:key="rs.id"
> >
<div v-if="rs.login_enabled"> No remote sources defined
<LoginForm </div>
action="Login" <div
:name="rs.name" v-else-if="!hasLoginRemoteSources"
v-if="rs.auth_type == 'password'" class="mb-10 bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative"
v-on:login="doLogin($event.username, $event.password, rs.name)" >
/> No remote sources enabled for login
<div v-else class="w-full max-w-xs"> </div>
<div class="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4"> <div v-else>
<div class="flex justify-center"> <div
<button class="my-6 flex justify-center items-center"
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline" v-for="rs in remotesources"
@click="doLogin(null, null, rs.name)" v-bind:key="rs.id"
>Login with {{rs.name}}</button> >
<div v-if="rs.login_enabled">
<LoginForm
action="Login"
:name="rs.name"
v-if="rs.auth_type == 'password'"
v-on:login="doLogin($event.username, $event.password, rs.name)"
/>
<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>
</div> </div>
</div> </div>
@ -58,6 +74,22 @@ export default {
remotesources: null remotesources: null
}; };
}, },
computed: {
hasRemoteSources() {
if (this.remotesources) {
return this.remotesources.length > 0;
}
return false;
},
hasLoginRemoteSources() {
for (let rs of this.remotesources) {
if (rs.login_enabled) {
return true;
}
}
return false;
}
},
methods: { methods: {
async fetchRemoteSources() { async fetchRemoteSources() {
let { data, error } = await fetchRemoteSources(); let { data, error } = await fetchRemoteSources();

View File

@ -12,10 +12,29 @@
<RegisterForm <RegisterForm
:remote-username="registeruser.remote_user_info.LoginName" :remote-username="registeruser.remote_user_info.LoginName"
: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)" v-on:login="
doRegister(
registeruser.remote_source_name,
$event.username,
registeruser.remote_source_login_name,
registeruser.remote_source_login_password
)
"
/> />
</div> </div>
</div> </div>
<div
v-else-if="!hasRemoteSources"
class="mb-10 bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative"
>
No remote sources defined
</div>
<div
v-else-if="!hasRegisterRemoteSources"
class="mb-10 bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative"
>
No remote sources enabled for registration
</div>
<div v-else> <div v-else>
<div <div
class="my-6 flex justify-center items-center" class="my-6 flex justify-center items-center"
@ -35,7 +54,9 @@
<button <button
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline" 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)" @click="doAuthorize(rs.name)"
>Register with {{rs.name}}</button> >
Register with {{ rs.name }}
</button>
</div> </div>
</div> </div>
</div> </div>
@ -68,7 +89,22 @@ export default {
}; };
}, },
computed: { computed: {
...mapGetters(["registeruser"]) ...mapGetters(["registeruser"]),
hasRemoteSources() {
if (this.remotesources) {
return this.remotesources.length > 0;
}
return false;
},
hasRegisterRemoteSources() {
for (let rs of this.remotesources) {
if (rs.registration_enabled) {
return true;
}
}
return false;
}
}, },
methods: { methods: {
async fetchRemoteSources() { async fetchRemoteSources() {
@ -81,14 +117,16 @@ export default {
}, },
async doAuthorize(remotesourcename, username, password) { async doAuthorize(remotesourcename, username, password) {
let u = authorizeurl(); let u = authorizeurl();
let res = await (await fetch(u, { let res = await (
method: "POST", await fetch(u, {
body: JSON.stringify({ method: "POST",
remote_source_name: remotesourcename, body: JSON.stringify({
login_name: username, remote_source_name: remotesourcename,
password: password login_name: username,
password: password
})
}) })
})).json(); ).json();
if (res.oauth2_redirect) { if (res.oauth2_redirect) {
window.location = res.oauth2_redirect; window.location = res.oauth2_redirect;