Skip to content

Commit

Permalink
Fixes #21170 - move password_strength.js to wepback
Browse files Browse the repository at this point in the history
  • Loading branch information
amirfefer committed Oct 18, 2017
1 parent b0fd1ab commit b396277
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 99 deletions.
81 changes: 0 additions & 81 deletions app/assets/javascripts/password_strength.js

This file was deleted.

11 changes: 0 additions & 11 deletions app/assets/stylesheets/password_strength.scss

This file was deleted.

10 changes: 7 additions & 3 deletions app/views/users/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<%= javascript 'password_strength' %>
<%= form_for @user do |f| %>
<%= base_errors_for @user %>
Expand Down Expand Up @@ -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 id="password_react"></div>
<%= mount_react_component('PasswordStrength', '#password_react',
{:className => 'form-control',
:id => 'user_password',
:name => 'user[password]',
:verify => {name: 'user[password_confirmation]'},
:error => f.object.errors[:password_hash].present? ? f.object.errors[:password_hash].to_sentence : false}.to_json) %>
</div>
</div>

Expand Down
1 change: 0 additions & 1 deletion app/views/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<%= javascript 'password_strength' %>
<% title _("Users") %>
<% title_actions new_link(_("Create User")) %>
Expand Down
1 change: 0 additions & 1 deletion bundler.d/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@
gem 'uglifier', '>= 1.0.3'
gem 'sass-rails', '~> 5.0'
gem 'spice-html5-rails', '~> 0.1.5'
gem 'jquery_pwstrength_bootstrap_4', :require => 'jquery_pwstrength_bootstrap'
1 change: 0 additions & 1 deletion config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
auth_source_ldap
subnets
hidden_values
password_strength
proxy_status
about
parameter_override)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"react-bootstrap": "^0.31.0",
"react-dom": "^15.6.2",
"react-numeric-input": "^2.0.7",
"react-password-strength": "^2.1.0",
"react-redux": "^5.0.2",
"redux": "^3.6.0",
"redux-form": "^7.0.3",
Expand Down
1 change: 1 addition & 0 deletions webpack/assets/javascripts/foreman_users.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ export function testMail(item, url, param = {}) {
}
});
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ToastsList from './toastNotifications/';
import StorageContainer from './hosts/storage/vmware/';
import forEach from 'lodash/forEach';
import map from 'lodash/map';
import PasswordStrength from '../components/passwordStrength/';

const componentRegistry = {
registry: {},
Expand Down Expand Up @@ -62,7 +63,8 @@ const coreComponets = [
{ name: 'PowerStatus', type: PowerStatus },
{ name: 'NotificationContainer', type: NotificationContainer },
{ name: 'ToastNotifications', type: ToastsList, data: false },
{ name: 'StorageContainer', type: StorageContainer }
{ name: 'StorageContainer', type: StorageContainer },
{ name: 'PasswordStrength', type: PasswordStrength }
];

componentRegistry.registerMultiple(coreComponets);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';
import CommonForm from '../common/forms/CommonForm';
import ReactPasswordStrength from 'react-password-strength';
import './password_strength.scss';

class PasswordStrength extends React.Component {
constructor() {
super();
this.checkRetype = this.checkRetype.bind(this);
this.state = {
pass: '',
error: undefined
};
}
checkRetype(event) {
if (event.target.value !== this.state.pass) {
this.setState({error: __('Passwords do not match')});
} else {
this.setState({error: undefined});
}
}

render() {
const {className, id, name, verify, error} = this.props.data;

return (
<div>
<CommonForm label={__('Password')} touched={true} error={error}>
<ReactPasswordStrength
changeCallback={(data) => {this.setState({pass: data.password});}}
minLength={0}
minScore={2}
scoreWords={[__('Weak'), __('Medium'), __('Normal'), __('Strong'), __('Stronger')]}
inputProps={{autoComplete: 'new-password', name: name,
id: id, className: `${className}`}}
/>
</CommonForm>
{ verify &&
<CommonForm label={__('Verify')} touched={true} error={this.state.error} >
<input name={verify.name} type="password"
onChange={this.checkRetype} className="form-control" />
</CommonForm>}
</div>
);
}
}

export default PasswordStrength;
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
.ReactPasswordStrength {
.ReactPasswordStrength-input {
width: 100%;
font-size: 12px;
font-family: 'Open Sans', Helvetica, Arial, sans-serif;
padding: 2px 30px 2px 6px;
}

.ReactPasswordStrength-strength-desc {
padding: 6px 10px;
right: 60px;
}
}

#password_react {
.is-strength-0 {
.ReactPasswordStrength-strength-desc {
color: #ff1318;
}

.ReactPasswordStrength-strength-bar {
background: #ff1318;
}
}

.is-strength-1 {
.ReactPasswordStrength-strength-desc {
color: orange;
}

.ReactPasswordStrength-strength-bar {
background: orange;
}
}

.is-strength-2 {
.ReactPasswordStrength-strength-desc {
color: #ffd435;
}

.ReactPasswordStrength-strength-bar {
background: #ffd435;
}
}

.is-strength-3 {
.ReactPasswordStrength-strength-desc {
color: lawngreen;
}

.ReactPasswordStrength-strength-bar {
background: lawngreen;
}
}

.is-strength-4 {
.ReactPasswordStrength-strength-desc {
color: green;
}

.ReactPasswordStrength-strength-bar {
background: green;
}
}
}
10 changes: 10 additions & 0 deletions webpack/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
import * as VMWareData from './data/storage/vmware';

storiesOf('Charts', module)
Expand Down Expand Up @@ -102,3 +103,12 @@ storiesOf('Host VMWare Storage', module)
.add('without any controllers', () =>
<StorageContainer store={Store} data={VMWareData.emptyState} />
);

storiesOf('Password Strength Meter', module)
.add('With no error ', () =>
<PasswordStrength data={{'className': 'form-control', 'id': 'password_id',
'name': 'name', 'error': []}} />)
.add('With error ', () =>
<PasswordStrength data={{'className': 'form-control', 'id': 'password_id',
'name': 'name', 'error': ["Can't be blank"]}} />
);

0 comments on commit b396277

Please sign in to comment.