await this._sessionCookieSet(res, undefined, 0, path);
}
+ /**
+ * @typedef {(pagePathLevel: Number, ctx: Object, htmlOptions: Object) => void} AppTemplateCallback
+ */
+
/**
* GET request for establishing admin session.
* @param {http.ServerResponse} res
* @param {Object} ctx
+ * @param {AppTemplateCallback} appCb
*/
- async getAdminLogin(res, ctx) {
+ async getAdminLogin(res, ctx, appCb) {
const _scope = _fileScope('getAdminLogin');
this.logger.debug(_scope, 'called', { ctx });
res.setHeader(Enum.Header.Location, redirect);
res.end();
} else {
- res.end(Template.LoginHTML(ctx, this.options));
+ res.end(Template.LoginHTML(ctx, this.options, appCb));
}
this.logger.info(_scope, 'finished', { ctx });
* POST request for taking form data to establish admin session.
* @param {http.ServerResponse} res
* @param {Object} ctx
+ * @param {AppTemplateCallback} appCb
*/
- async postAdminLogin(res, ctx) {
+ async postAdminLogin(res, ctx, appCb) {
const _scope = _fileScope('postAdminLogin');
this.logger.debug(_scope, 'called', { ctx });
ctx.errors = [];
// Check if this was an OTP entry attempt.
- if (await this._otpSubmission(res, ctx)) {
+ if (await this._otpSubmission(res, ctx, appCb)) {
// OTP path was taken, either successful entry and session creation, or re-prompting for otp.
return;
}
- if (await this._localUserAuth(res, ctx)) {
+ if (await this._localUserAuth(res, ctx, appCb)) {
// Local auth path was taken.
return;
}
}
if (ctx.errors.length) {
- res.end(Template.LoginHTML(ctx, this.options));
+ res.end(Template.LoginHTML(ctx, this.options, appCb));
return;
}
}
if (ctx.errors.length) {
- res.end(Template.LoginHTML(ctx, this.options));
+ res.end(Template.LoginHTML(ctx, this.options, appCb));
return;
}
* @param {String} ctx.parsedBody.otp
* @returns {Promise<Boolean>} true if otp was handled, otherwise false indicates further login processing needed
*/
- async _otpSubmission(res, ctx) {
+ async _otpSubmission(res, ctx, appCb) {
const _scope = _fileScope('_otpSubmission');
const {
if (!otp) {
// Nothing submitted, but valid state, just present otp form again, do not count as attempt.
ctx.otpState = stateBox;
- res.end(Template.OTPHTML(ctx, this.options));
+ res.end(Template.OTPHTML(ctx, this.options, appCb));
this.logger.info(_scope, 'finished otp, nothing entered, request again', { ctx });
return true;
}
...state,
attempt: state.attempt + 1,
});
- res.end(Template.OTPHTML(ctx, this.options));
+ res.end(Template.OTPHTML(ctx, this.options, appCb));
this.logger.info(_scope, 'finished otp, invalid, request again', { ctx });
return true;
* @param {Object} ctx
* @returns {Promise<Boolean>} true if handled, false if flow should continue
*/
- async _localUserAuth(res, ctx) {
+ async _localUserAuth(res, ctx, appCb) {
const _scope = _fileScope('_localUserAuth');
// If Indiauth enabled and profile was submitted, defer to that.
}
if (ctx.errors.length) {
- res.end(Template.LoginHTML(ctx, this.options));
+ res.end(Template.LoginHTML(ctx, this.options, appCb));
return true;
}
attempt: 0,
redirect,
});
- res.end(Template.OTPHTML(ctx, this.options));
+ res.end(Template.OTPHTML(ctx, this.options, appCb));
this.logger.info(_scope, 'finished local, otp required', { ctx });
return true;
}
* This currently only redeems a scope-less profile.
* @param {http.ServerResponse} res
* @param {Object} ctx
+ * @param {AppTemplateCallback} appCb
*/
- async getAdminIA(res, ctx) {
+ async getAdminIA(res, ctx, appCb) {
const _scope = _fileScope('getAdminIA');
this.logger.debug(_scope, 'called', { ctx });
if (ctx.errors.length) {
await this._sessionCookieClear(res);
- res.end(Template.IAHTML(ctx, this.options));
+ res.end(Template.IAHTML(ctx, this.options, appCb));
return;
}
* Page for modifying credentials and OTP.
* @param {http.ServerResponse} res
* @param {Object} ctx
+ * @param {AppTemplateCallback} appCb
*/
- async getAdminSettings(res, ctx) {
+ async getAdminSettings(res, ctx, appCb) {
const _scope = _fileScope('getAdminSettings');
this.logger.debug(_scope, 'called', { ctx });
ctx.errors.push('An error was encountered. Sorry that is not very helpful.');
}
- res.end(Template.SettingsHTML(ctx, this.options));
+ res.end(Template.SettingsHTML(ctx, this.options, appCb));
this.logger.info(_scope, 'finished', { ctx });
}
* Page for modifying credentials and OTP.
* @param {http.ServerResponse} res
* @param {Object} ctx
+ * @param {Object[]=} appNavLinks
+ * @param {AppTemplateCallback} appCb
*/
- async postAdminSettings(res, ctx) {
+ async postAdminSettings(res, ctx, appCb) {
const _scope = _fileScope('postAdminSettings');
this.logger.debug(_scope, 'called', { ctx });
ctx.errors.push('An error was encountered. Sorry that is not very helpful.');
}
- res.end(Template.SettingsHTML(ctx, this.options));
+ res.end(Template.SettingsHTML(ctx, this.options, appCb));
this.logger.info(_scope, 'finished', { ctx });
}
}
}
-
}
module.exports = SessionManager;