diff --git a/src/includes/entrepreneur/login.pug b/src/includes/entrepreneur/login.pug index 1323da754b0402569ece635b021eb608cf49f4e2..ffdcef9ef86a2210f2c6b7ec7cf0314c61a745bf 100644 --- a/src/includes/entrepreneur/login.pug +++ b/src/includes/entrepreneur/login.pug @@ -1,6 +1,7 @@ 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 diff --git a/src/includes/head.pug b/src/includes/head.pug index 63f8363375db850cde1e8f475c6dddb3f23dd210..4c5a6703b5338d2442f971ed7b909cfa4dc24560 100644 --- a/src/includes/head.pug +++ b/src/includes/head.pug @@ -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") diff --git a/src/includes/mentor/components/header.pug b/src/includes/mentor/components/header.pug index c9f0553b643681bcd5166412589f8139b44b633a..6b207de81fa158837cafa904dc44e2c6aaf1ce55 100644 --- a/src/includes/mentor/components/header.pug +++ b/src/includes/mentor/components/header.pug @@ -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 ) diff --git a/src/includes/mentor/components/menu.pug b/src/includes/mentor/components/menu.pug index c9fef295b70a512d80b17a74542c80d27bd942b7..8488aab9fdd8684e7fc4affbaaa7dbaef619afa7 100644 --- a/src/includes/mentor/components/menu.pug +++ b/src/includes/mentor/components/menu.pug @@ -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) diff --git a/src/includes/mentor/login.pug b/src/includes/mentor/login.pug index c907c43536a382283a1d3b4abb3c87e05a5b0cf3..77f827a3560c568a5c1af1e7942beb977824ca43 100644 --- a/src/includes/mentor/login.pug +++ b/src/includes/mentor/login.pug @@ -1,6 +1,7 @@ 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 diff --git a/src/includes/splash.pug b/src/includes/splash.pug index caa93d28e8756c11e84d49679b53c4f40e0431d5..8c90634d8d2cb384ecf318818d762d712c089e5c 100644 --- a/src/includes/splash.pug +++ b/src/includes/splash.pug @@ -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 diff --git a/src/index.pug b/src/index.pug index e58fa109624dacc17379e443c803e4c54b38a405..0258bf29bf8b0c2b5e6443cc6a250251c222e4d8 100644 --- a/src/index.pug +++ b/src/index.pug @@ -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);