File size: 5,742 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
import { Card } from '@automattic/components';
import { localizeUrl } from '@automattic/i18n-utils';
import { localize } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { Component } from 'react';
import { connect } from 'react-redux';
import FormButton from 'calypso/components/forms/form-button';
import FormSectionHeading from 'calypso/components/forms/form-section-heading';
import InlineSupportLink from 'calypso/components/inline-support-link';
import Security2faCodePrompt from 'calypso/me/security-2fa-code-prompt';
import Security2faStatus from 'calypso/me/security-2fa-status';
import { recordGoogleEvent } from 'calypso/state/analytics/actions';
import { successNotice } from 'calypso/state/notices/actions';
import getUserSettings from 'calypso/state/selectors/get-user-settings';
import './style.scss';
class Security2faDisable extends Component {
static propTypes = {
onFinished: PropTypes.func.isRequired,
userSettings: PropTypes.object.isRequired,
translate: PropTypes.func,
recordGoogleEvent: PropTypes.func,
successNotice: PropTypes.func,
};
constructor() {
super( ...arguments );
this.state = {
showingCodePrompt: false,
};
}
onRevealCodePrompt = () => {
this.props.recordGoogleEvent( 'Me', 'Clicked On Disable Two-Step Authentication Button' );
this.setState( { showingCodePrompt: true } );
};
onCancelCodePrompt = () => {
this.setState( { showingCodePrompt: false } );
};
onCodePromptSuccess = () => {
const { onFinished, translate } = this.props;
this.setState( { showingCodePrompt: false } );
this.props.successNotice( translate( 'Successfully disabled Two-Step Authentication.' ), {
duration: 4000,
} );
onFinished();
};
renderVerificationCodeMeansMessage() {
const { userSettings, translate } = this.props;
if ( userSettings.two_step_sms_enabled ) {
return (
<Card>
<div>
<p>
{ translate(
"You've enabled two-step authentication. " +
'While enabled, logging in to WordPress.com ' +
'requires you to enter a unique passcode, sent via text message, ' +
'in addition to your username and password.'
) }
</p>
<p>
{ translate(
"You're all set to receive authentication codes at " +
'{{strong}}%(smsNumber)s{{/strong}}. ' +
'Want to switch to a different number? No problem! ' +
"You'll need to disable two-step authentication, " +
'then complete the setup process again on another device.',
{
components: {
strong: <strong />,
},
args: {
smsNumber: userSettings.two_step_sms_phone_number,
},
}
) }
</p>
</div>
</Card>
);
}
return (
<div>
<p>
{ translate(
"You've enabled two-step authentication on your account — smart move! " +
"When you log in to WordPress.com, you'll need to enter your " +
'username and password, as well as a unique passcode generated ' +
'by an app on your mobile device.'
) }
</p>
<p>
{ translate(
'Switching to a new device? ' +
'{{changephonelink}}Follow these steps{{/changephonelink}} ' +
'to avoid losing access to your account.',
{
components: {
changephonelink: (
<InlineSupportLink
supportPostId={ 39178 }
supportLink={ localizeUrl(
'https://wordpress.com/support/security/two-step-authentication/#moving-to-a-new-device'
) }
showIcon={ false }
/>
),
},
}
) }
</p>
</div>
);
}
renderCodePromptToggle() {
const { translate, userSettings } = this.props;
if ( this.state.showingCodePrompt ) {
return (
<div className="security-2fa-disable__prompt">
<FormSectionHeading>
{ translate( 'Disable two-step authentication' ) }
</FormSectionHeading>
<p>
{ translate(
'You are about to disable two-step authentication. ' +
'This means we will no longer ask for your authentication ' +
'code when you sign into your {{strong}}%(userlogin)s{{/strong}} account.',
{
components: {
strong: <strong />,
},
args: {
userlogin: userSettings.user_login,
},
}
) }
</p>
<p>
{ translate(
'This will also disable your application passwords, ' +
'though you can access them again if you ever re-enable ' +
'two-step authentication. If you decide to re-enable ' +
"two-step authentication, keep in mind you'll need to " +
'generate new backup codes.'
) }
</p>
<p>
{ translate(
'To verify that you wish to disable two-step authentication, ' +
'enter the verification code from your device or a backup code, ' +
'and click "Disable two-step."'
) }
</p>
<Security2faCodePrompt
action="disable-two-step"
onCancel={ this.onCancelCodePrompt }
onSuccess={ this.onCodePromptSuccess }
requestSMSOnMount={ userSettings.two_step_sms_enabled }
/>
</div>
);
}
return (
<FormButton isPrimary={ false } scary onClick={ this.onRevealCodePrompt }>
{ translate( 'Disable two-step authentication' ) }
</FormButton>
);
}
render() {
return (
<div>
{ this.renderVerificationCodeMeansMessage() }
<Security2faStatus twoStepEnabled={ this.props.userSettings.two_step_enabled } />
{ this.renderCodePromptToggle() }
</div>
);
}
}
export default connect(
( state ) => ( {
userSettings: getUserSettings( state ),
} ),
{
successNotice,
recordGoogleEvent,
}
)( localize( Security2faDisable ) );
|