Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #21170 - move password strength meter logic to react #4882

Merged
merged 1 commit into from
Jan 28, 2018

Conversation

amirfefer
Copy link
Member

@amirfefer amirfefer commented Oct 2, 2017

password_strength.js uses jquery_pwstrength_bootstrap wrapper
I've added react-password-strength - react component, which renders password input with integrated password strength meter by using zxcvbn to calculate a password strength score.
In addition, I moved verify password logic to wepback (it was in password_strength file as well)
Tests are missing for now.

after update:
Try online with Stroybook

before update:
oct 3 2017 4-14 pm - edited 1

@theforeman-bot
Copy link
Member

There were the following issues with the commit message:

  • bb7d2ce must be in the format fixes #redmine_number - brief description

If you don't have a ticket number, please create an issue in Redmine.

More guidelines are available in Coding Standards or on the Foreman wiki.


This message was auto-generated by Foreman's prprocessor

@@ -14,6 +14,7 @@ import PowerStatusInner from
import Store from '../assets/javascripts/react_app/redux';
import Toast from '../assets/javascripts/react_app/components/toastNotifications/toastListitem';
import StorageContainer from '../assets/javascripts/react_app/components/hosts/storage/vmware';
import PasswordStrength from '../assets/javascripts/react_app/components/passwordStrength'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon semi

else {
form.removeClass('has-success has-error');
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing curly brace does not appear on the same line as the subsequent block brace-style

if (password !== '') {
html = __('Password match');
form.removeClass('has-error').addClass('has-success');
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing curly brace does not appear on the same line as the subsequent block brace-style

@@ -47,3 +47,25 @@ export function testMail(item, url, param = {}) {
}
});
}

export function verifyPassword() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function 'verifyPassword' has too many statements (12). Maximum allowed is 10 max-statements

@amirfefer amirfefer changed the title Fixes 21170 - move password_strength.js logic to react Fixes 21170 - move password strength meter logic to react Oct 2, 2017
@amirfefer amirfefer changed the title Fixes 21170 - move password strength meter logic to react Fixes #21170 - move password strength meter logic to react Oct 2, 2017
@amirfefer
Copy link
Member Author

@Rohoover What do you say about the color scheme?

@Rohoover
Copy link

Rohoover commented Oct 3, 2017

I think it jumps from orange to green. Maybe a yellow in between for

Weak - Red
Normal - Orange
Medium -Yellow
Strong -Green
Very Strong - Dark Green

@@ -41,8 +40,13 @@
<% if User.current == @user %>
<%= password_f f, :current_password, :label => _('Current password'), :placeholder => '' %>
<% end %>
<%= password_f f, :password, :label => _('Password'), :error => @user.errors[:password_hash] %>
<%= password_f f, :password_confirmation, :label => _('Verify') %>
<div class="clearfix" id="password_react"></div>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the .clearfix needed here?


return (
<div className={`form-group ${error.length > 0 ? 'has-error' : ''}`}>
<label className="col-md-2 control-label"> { __('Password') } </label>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This label should include a for attribute to tie it to the input below for accessibility.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,10 @@
.ReactPasswordStrength-input {
width: 100% !important;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we style this without the !importants? Maybe add additional classes or elements to the selector if you need more specificity.

</div>
{ error.length > 0 &&
<span className="help-block help-inline">
<span className="error-message"> {error[0]} </span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could there be more than one error? should we only display the first one?

@@ -25,4 +25,4 @@ const CommonForm = ({
);
};

export default CommonForm;
export default CommonForm;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline required at end of file but not found eol-last

@@ -25,4 +25,4 @@ const CommonForm = ({
);
};

export default CommonForm;
export default CommonForm;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline required at end of file but not found eol-last

@amirfefer
Copy link
Member Author

amirfefer commented Oct 18, 2017

@waldenraines I've mentioned your comments.
@ohadlevy, I've switched verify password validation logic from jquery to react

I've changed color pattern to @Rohoover suggestion

Copy link

@waldenraines waldenraines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@amirfefer
Copy link
Member Author

@Rohoover
thoughts about color scheme , text placement ?
oct 19 2017 11-28 pm - edited

@ares
Copy link
Member

ares commented Oct 20, 2017

Copying out notes from UX demo with @Rohoover about this:

Password authorization - Weak/Normal/Strong visualization would not pass 528 compliance for those visually impaired. The colors associated with each strength level seems mismatched. For example: Normal is red. A red status as well as form field highlight indicates an error. Weak is grey, and also possibly not high enough contrast for the visually impaired. The solution may be to simplify the password strength to text only, “Weak Password, Strong Password”. Also - greater thought or discussion could be had around “Normal” or “Strong”. If a “Normal” indicator is shown, does this actually change user behavior in the same way “Weak” does? Perhaps only “weak” is needed.

While I think most of it is addressed and it's a great improvement already, I think there are some other things that could be considered while it's being touched.

  • If messages include icons, it would solve the coloring issue.
  • fonts seems to be different for pass match and pass strength (italic, different size)
  • "too short" should be perhaps "Too short" to be consistent
  • does medium password still get accepted?

Also when this gets in, please update/close http://projects.theforeman.org/issues/20740 which tracked this originally :-)

Copy link
Contributor

@sharvit sharvit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to me! 👍

@ohadlevy
Copy link
Member

@amirfefer please rebase.

Copy link
Member

@ohadlevy ohadlevy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial review looks good - I've added a few comments inline.

Please also adds action/reducers tests.

Thanks!

passwordNotMatched,
} from './passwordStrength.fixtures';

configure({ adapter: new Adapter() });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these setup are no longer need (see webpack/test_setup.js)

configure({ adapter: new Adapter() });

jest.unmock('./');
global.__ = jest.fn();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not required anymore

function setup(verify, error, state) {
const store = mockStore(state);

return mount(<PasswordStrength
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would shallow work here too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shallow doesn't render inner components therefore the resulted snapshot lacks in inner content

inputProps={{
name,
id,
className: `${className}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you really need the string interrelation here? I think the following would just work:

inputProps={{  name,  id, className }}

<CommonForm
label={__('Verify')}
touched={true}
error={matchMessage ? verify.error : __('Password do not matched')}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original string was passwords do not match

@amirfefer
Copy link
Member Author

@ohadlevy thanks, I've fixed and rebased. would you mind take another look?

@mmoll
Copy link
Contributor

mmoll commented Dec 26, 2017

@amirfefer Is the test failure in the foreman test related to these changes?

@ares
Copy link
Member

ares commented Jan 3, 2018

ping @amirfefer

@amirfefer
Copy link
Member Author

I've fixed the users integration test,
Apparently the react component did not render at all via capybara.

@mmoll
Copy link
Contributor

mmoll commented Jan 16, 2018

@amirfefer please rebase

I guess the travis test "failures" also need fixing/updating...

@amirfefer
Copy link
Member Author

amirfefer commented Jan 17, 2018

Rebased.
plus I've updated jest snapshot.

@ohadlevy
Copy link
Member

@amirfefer anything left here?

@@ -1 +1,7 @@
$pf-black-200: #ededed;
$pf-red-200: #a30000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use this from the patternfly package? @sharvit ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When my css pr will merge you would be able to import variables:
https://github.com/theforeman/foreman/pull/5212/files#diff-f430da9fad5e785cb1f815fd719fdc5aR1

@ohadlevy
Copy link
Member

@amirfefer can you please also include

diff --git a/config/webpack.vendor.js b/config/webpack.vendor.js
index aed3a4bde..e6e2f023a 100644
--- a/config/webpack.vendor.js
+++ b/config/webpack.vendor.js
@@ -9,6 +9,7 @@ module.exports = [
   'react-ellipsis-with-tooltip',
   'react-numeric-input',
   'react-onclickoutside',
+  'react-password-strength',
   'patternfly-react',
   'react-redux',
   'redux',

@amirfefer
Copy link
Member Author

@ohadlevy - done :)

@amirfefer
Copy link
Member Author

[test foreman]

Copy link
Contributor

@sharvit sharvit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@amirfefer
Copy link
Member Author

@ohadlevy tests are green :)

@ohadlevy ohadlevy merged commit 6850ad9 into theforeman:develop Jan 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants