const { Controller } = require('libflitter') class MFAController extends Controller { static get services() { return [...super.services, 'Vue', 'configs', 'models'] } async setup(req, res, next) { if ( req.user.mfa_enabled ) { // Already set up! return this.Vue.auth_message(res, { message: 'It looks like your account is already set up for multi-factor authentication. Unable to continue with MFA setup.', next_destination: '/', // TODO update this button_text: 'Okay', }) } // Display the token setup page return res.page('auth:mfa:setup', { ...this.Vue.data() }) } async challenge(req, res, next) { if ( !req.user.mfa_enabled ) { return this.Vue.auth_message(res, { message: 'Your account is not configured to use multi-factor authentication. Would you like to configure it now?', next_destination: '/auth/mfa/setup', button_text: 'Setup MFA', }) } if ( !req.session.auth.in_dmz ) { return res.redirect(req.session.auth.flow) } // Display the MFA challenge page return res.page('auth:mfa:challenge', { ...this.Vue.data() }) } async get_disable(req, res, next) { return this.Vue.confirm(res, { message: `You are about to disable multi-factor authentication for your account. This process will require you to re-authenticate to continue.

Proceed?`, yes: '/auth/mfa/disable/process', no: '/dash/profile', }) } async do_disable(req, res, next) { return res.page('auth:mfa:disable', { ...this.Vue.data(), ...this.Vue.session(req), }) } } module.exports = exports = MFAController