2019-05-07 14:57:22 +08:00
import React from 'react' ;
import { gettext , siteRoot } from '../../utils/constants' ;
const {
defaultDevice ,
backupTokens
} = window . app . pageOptions ;
class TwoFactorAuthentication extends React . Component {
constructor ( props ) {
super ( props ) ;
}
renderEnabled = ( ) => {
return (
< React . Fragment >
< p className = "mb-2" > { gettext ( 'Status: enabled' ) } < / p >
2019-05-13 08:50:05 +08:00
< a className = "btn btn-outline-primary mb-4" href = { ` ${ siteRoot } profile/two_factor_authentication/disable/ ` } >
2019-05-07 14:57:22 +08:00
{ gettext ( 'Disable Two-Factor Authentication' ) } < / a >
< p className = "mb-2" >
{ gettext ( 'If you don\'t have any device with you, you can access your account using backup codes.' ) }
{ backupTokens == 1 ? gettext ( 'You have only one backup code remaining.' ) :
gettext ( 'You have {num} backup codes remaining.' ) . replace ( '{num}' , backupTokens ) }
< / p >
< a href = { ` ${ siteRoot } profile/two_factor_authentication/backup/tokens/ ` }
2019-05-13 08:50:05 +08:00
className = "btn btn-outline-primary" > { gettext ( 'Show Codes' ) } < / a >
2019-05-07 14:57:22 +08:00
< / R e a c t . F r a g m e n t >
) ;
}
renderDisabled = ( ) => {
return (
< React . Fragment >
< p className = "mb-2" > { gettext ( 'Two-factor authentication is not enabled for your account. Enable two-factor authentication for enhanced account security.' ) } < / p >
2019-05-13 08:50:05 +08:00
< a href = { ` ${ siteRoot } profile/two_factor_authentication/setup/ ` } className = "btn btn-outline-primary" >
2019-05-07 14:57:22 +08:00
{ gettext ( 'Enable Two-Factor Authentication' ) } < / a >
< / R e a c t . F r a g m e n t >
) ;
}
render ( ) {
return (
< div className = "setting-item" id = "two-factor-auth" >
< h3 className = "setting-item-heading" > { gettext ( 'Two-Factor Authentication' ) } < / h 3 >
{ defaultDevice ? this . renderEnabled ( ) : this . renderDisabled ( ) }
< / d i v >
) ;
}
}
export default TwoFactorAuthentication ;