Skip to content

Commit

Permalink
fixed auto login on adm creation + persistent session
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Feb 25, 2020
1 parent 1e7bf3b commit 63f7ac2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/components/webServer/ctxUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ sqrl.defineFilter("isSelected", (x)=>{
sqrl.defineFilter("isDisabled", (x)=>{
return (x==='true')? 'disabled' : '';
});
sqrl.defineFilter("n2br", (x)=>{
return x.replace(/(\r|\n)+/m, '<br>');
});


//================================================================
Expand Down
8 changes: 6 additions & 2 deletions src/webroutes/authentication/addMaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ async function handlePin(ctx) {
return ctx.utils.render('login', {template: 'noMaster', message});
}

//Make sure the session is initialized
ctx.session.startedSocialLogin = Date.now();

//Generate URL
try {
let callback = ctx.protocol + '://' + ctx.get('host') + `/auth/addMaster/callback`;
Expand Down Expand Up @@ -89,8 +92,8 @@ async function handleCallback(ctx) {
let currentURL = ctx.protocol + '://' + ctx.get('host') + `/auth/addMaster/callback`;
tokenSet = await globals.authenticator.providers.citizenfx.processCallback(ctx, currentURL, ctx.session._sessCtx.externalKey);
} catch (error) {
let message = `Code Exchange error: ${error.message}`;
logError(message);
logWarn(`Code Exchange error: ${error.message}`);
let message = `Failed to exchange code for token. Try again.\n\n\n\r\nIf this problem persists, check terminal for more info.`;
return ctx.utils.render('login', {template: 'justMessage', message});
}

Expand Down Expand Up @@ -180,6 +183,7 @@ async function handleSave(ctx) {
ctx.session.tmpAddMasterTokenSet,
ctx.session.tmpAddMasterUserInfo
);
ctx.session.auth.username = ctx.session.tmpAddMasterUserInfo.name
delete ctx.session.tmpAddMasterTokenSet;
delete ctx.session.tmpAddMasterUserInfo;
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion web/basic/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
<div class="card-body text-center p-4">
<!-- TODO: see if squirrelly already supports elseif -->
{{if(options.template == 'justMessage')}}
<h5 class="text-danger mb-3">{{message}}</h5>
<h5 class="text-danger mb-3">{{message|n2br}}</h5>
<a href="/auth" class="btn btn-primary px-4" role="submit">Back</a>
{{/if}}
{{if(options.template == 'noMaster')}}
Expand Down

0 comments on commit 63f7ac2

Please sign in to comment.