From 4274b13aa7dfa0cb1fb6bbe68c2bc32423be938c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Wed, 15 Dec 2021 15:26:34 +0100 Subject: [PATCH 1/3] Add ShowablePassword component MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/components/showable_password.js | 64 +++++++++++++++++++ .../auth_login/components/login_form.js | 25 ++++---- .../components/registration_form.js | 5 +- app/soapbox/features/security/index.js | 12 ++-- app/soapbox/features/security/mfa_form.js | 6 +- app/soapbox/locales/pl.json | 2 + app/styles/about.scss | 1 + app/styles/forms.scss | 25 ++++++++ 8 files changed, 118 insertions(+), 22 deletions(-) create mode 100644 app/soapbox/components/showable_password.js diff --git a/app/soapbox/components/showable_password.js b/app/soapbox/components/showable_password.js new file mode 100644 index 000000000..a6dbdad24 --- /dev/null +++ b/app/soapbox/components/showable_password.js @@ -0,0 +1,64 @@ +import React from 'react'; +import ImmutablePureComponent from 'react-immutable-pure-component'; +import { defineMessages, injectIntl } from 'react-intl'; +import PropTypes from 'prop-types'; +import classNames from 'classnames'; +import IconButton from 'soapbox/components/icon_button'; +import { FormPropTypes, InputContainer, LabelInputContainer } from 'soapbox/features/forms'; + +const messages = defineMessages({ + showPassword: { id: 'forms.show_password', defaultMessage: 'Show password' }, + hidePassword: { id: 'forms.hide_password', defaultMessage: 'Hide password' }, +}); + +export default @injectIntl +class ShowablePassword extends ImmutablePureComponent { + + static propTypes = { + intl: PropTypes.object.isRequired, + label: FormPropTypes.label, + className: PropTypes.string, + hint: PropTypes.node, + error: PropTypes.bool, + } + + state = { + revealed: false, + } + + toggleReveal = () => { + if (this.props.onToggleVisibility) { + this.props.onToggleVisibility(); + } else { + this.setState({ revealed: !this.state.revealed }); + } + } + + render() { + const { intl, hint, error, label, className, ...props } = this.props; + const { revealed } = this.state; + + const revealButton = ( + + ); + + return ( + + {label ? ( + + + {revealButton} + + ) : (<> + + {revealButton} + )} + + ); + } + +} \ No newline at end of file diff --git a/app/soapbox/features/auth_login/components/login_form.js b/app/soapbox/features/auth_login/components/login_form.js index 842e38832..fbfe4afb3 100644 --- a/app/soapbox/features/auth_login/components/login_form.js +++ b/app/soapbox/features/auth_login/components/login_form.js @@ -5,6 +5,7 @@ import { Link } from 'react-router-dom'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { getFeatures } from 'soapbox/utils/features'; import { getBaseURL } from 'soapbox/utils/state'; +import ShowablePassword from 'soapbox/components/showable_password'; const messages = defineMessages({ username: { id: 'login.fields.username_placeholder', defaultMessage: 'Username' }, @@ -45,19 +46,21 @@ class LoginForm extends ImmutablePureComponent { required /> -
+ + {/*
-
+
*/}

{hasResetPasswordAPI ? ( diff --git a/app/soapbox/features/auth_login/components/registration_form.js b/app/soapbox/features/auth_login/components/registration_form.js index a4c52ef62..ff8c987ae 100644 --- a/app/soapbox/features/auth_login/components/registration_form.js +++ b/app/soapbox/features/auth_login/components/registration_form.js @@ -5,6 +5,7 @@ import ImmutablePropTypes from 'react-immutable-proptypes'; import { connect } from 'react-redux'; import { injectIntl, FormattedMessage, defineMessages } from 'react-intl'; import { Link } from 'react-router-dom'; +import ShowablePassword from 'soapbox/components/showable_password'; import { SimpleForm, SimpleInput, @@ -231,7 +232,7 @@ class RegistrationForm extends ImmutablePureComponent { )} - - - {intl.formatMessage(messages.passwordHeader)}

- - -
-
-
- Date: Wed, 15 Dec 2021 15:29:25 +0100 Subject: [PATCH 2/3] no point in passing type=password MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/features/auth_login/components/login_form.js | 1 - .../features/auth_login/components/registration_form.js | 2 -- app/soapbox/features/security/index.js | 5 ----- app/soapbox/features/security/mfa_form.js | 2 -- 4 files changed, 10 deletions(-) diff --git a/app/soapbox/features/auth_login/components/login_form.js b/app/soapbox/features/auth_login/components/login_form.js index fbfe4afb3..8368cbb68 100644 --- a/app/soapbox/features/auth_login/components/login_form.js +++ b/app/soapbox/features/auth_login/components/login_form.js @@ -50,7 +50,6 @@ class LoginForm extends ImmutablePureComponent { aria-label={intl.formatMessage(messages.password)} className='password user_password' placeholder={intl.formatMessage(messages.password)} - type='password' name='password' autoComplete='off' autoCorrect='off' diff --git a/app/soapbox/features/auth_login/components/registration_form.js b/app/soapbox/features/auth_login/components/registration_form.js index ff8c987ae..f0d27c297 100644 --- a/app/soapbox/features/auth_login/components/registration_form.js +++ b/app/soapbox/features/auth_login/components/registration_form.js @@ -235,7 +235,6 @@ class RegistrationForm extends ImmutablePureComponent {
@@ -314,7 +313,6 @@ class OtpConfirmForm extends ImmutablePureComponent {
From 81abb7d49e349a5333733fd7b8f1027068a9f831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Wed, 15 Dec 2021 15:39:07 +0100 Subject: [PATCH 3/3] update snapshots MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- .../__snapshots__/login_form-test.js.snap | 66 +++++++++++++++++-- .../__snapshots__/login_page-test.js.snap | 33 +++++++++- 2 files changed, 93 insertions(+), 6 deletions(-) diff --git a/app/soapbox/features/auth_login/components/__tests__/__snapshots__/login_form-test.js.snap b/app/soapbox/features/auth_login/components/__tests__/__snapshots__/login_form-test.js.snap index ad357af03..0588d8a02 100644 --- a/app/soapbox/features/auth_login/components/__tests__/__snapshots__/login_form-test.js.snap +++ b/app/soapbox/features/auth_login/components/__tests__/__snapshots__/login_form-test.js.snap @@ -25,19 +25,48 @@ exports[` renders for Mastodon 1`] = ` />
+

renders for Pleroma 1`] = ` />

+

renders correctly on load 1`] = ` />

+