Skip to content
Snippets Groups Projects
Commit 41f310f4 authored by Benoit Alessandroni's avatar Benoit Alessandroni
Browse files

Fixing the login and switch between entrepreneurs and mentors

parent bbe54087
No related branches found
No related tags found
1 merge request!4Feature/editing a resource
h2 I am an entrepreneur
button(role='log in' onclick="document.querySelector('sib-auth').login();") Login as entrepreneur
cs-login(bind-user)
button(id='entrepreneur_login') Login as entrepreneur
sib-link(next='entrepreneur-new-account')
div Create an account
\ No newline at end of file
......@@ -2,9 +2,9 @@ head
title CoopStarter
meta(charset="utf-8")
script(src="https://unpkg.com/@webcomponents/webcomponentsjs@1.2.7/webcomponents-loader.js")
script(type="module" src="https://unpkg.com/@startinblox/core@0.8")
script(type="module" src="https://unpkg.com/@startinblox/router@0.7")
script(type="module" src="https://unpkg.com/@startinblox/oidc@0.7")
script(type="module" src="https://unpkg.com/@startinblox/core")
script(type="module" src="https://unpkg.com/@startinblox/router")
script(type="module" src="https://unpkg.com/@startinblox/oidc")
script(src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous")
script(src="/scripts/coopstarter.js")
link(rel="stylesheet" href="/styles/coopstarter.css")
......@@ -14,7 +14,7 @@ sib-widget(name='account-user-name')
sib-display#user-controls__profile(
fields='first_name, account.picture',
widget-user.first_name='account-user-name',
widget-first_name='account-user-name',
widget-account.picture='account-user-avatar',
bind-user
)
......
......@@ -5,7 +5,7 @@ sib-router(default-route='mentor-resource-list')
div.divider
sib-ac-checker(permission="acl:Write")
sib-route(name='mentor-resource-create')
div.menu-label Create a resource
div.menu-label Post a new resource +
div.menu-icon.icon-people
div.divider
sib-ac-checker(permission="acl:Write" bind-resources)
......
h2 I am a mentor
button(role='log in' onclick="document.querySelector('sib-auth').login();") Login as mentor
cs-login(bind-user)
button(id='mentor_login') Login as mentor
sib-link(next='mentor-new-account')
div Create an account
\ No newline at end of file
div Create an account
......@@ -2,7 +2,7 @@ sib-router
sib-route(name='mentor-login')
sib-route(name='entrepreneur-login')
h2 Welcome to our international index of resources for cooperative mentors and entrepreneurs
h2 Welcome to your international index of resources for cooperative mentors and entrepreneurs
sib-link(next='mentor-login')
div I am a mentor
......
......@@ -24,16 +24,53 @@ html
#entrepreneur-new-account(hidden).no-sidebar
include includes/entrepreneur/create.pug
sib-auth
sib-auth-provider(
sib-auth
sib-auth-provider(
class="sib-auth-provider"
data-authority=`${sdn}`
data-client_id=`${client_id}`,
data-id="coopstarter"
data-response_type='id_token token',
data-scope='openid profile email',
data-automaticSilentRenew='true',
data-loadUserInfo='true'
)
)
script(type='module').
import { store } from 'https://unpkg.com/@startinblox/core@0.8';
const sibAuth = document.querySelector('sib-auth');
class CoopStarterLoginComponent extends HTMLElement {
async connectedCallback() {
mentor_login.onclick = () => this.triggerLogin();
entrepreneur_login.onclick = () => this.triggerLogin();
this.update();
}
async triggerLogin() {
await sibAuth.login();
}
async update() {
let user = await sibAuth.getUser();
let idToken = await sibAuth.getUserIdToken();
if ( !user ) {
console.log("You're not logged in");
return;
}
user = await store.get(user);
console.log('Retrieved user', user);
if (user && user.mentor_profile) {
window.dispatchEvent(
new CustomEvent('requestNavigation', { detail: { route: 'mentor-dashboard' } })
);
} else if (user && user.entrepreneur_profile) {
window.dispatchEvent(
new CustomEvent('requestNavigation', { detail: { route: 'entrepreneur-dashboard' } })
);
}
}
empty(){}
populate(){}
}
customElements.define('cs-login', CoopStarterLoginComponent);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment