2020-04-22 21:56:39 +00:00
const { Controller } = require ( 'libflitter' )
class MFAController extends Controller {
static get services ( ) {
2020-05-04 01:16:54 +00:00
return [ ... super . services , 'Vue' , 'configs' , 'models' ]
2020-04-22 21:56:39 +00:00
}
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 ( )
} )
}
2020-05-04 01:16:54 +00:00
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. <br><br> 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 ) ,
} )
}
2020-04-22 21:56:39 +00:00
}
module . exports = exports = MFAController