Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Update password fields everywhere to avoid allowing save when not cor…
Browse files Browse the repository at this point in the history
…rectly set.
  • Loading branch information
cdujeu committed Dec 11, 2017
1 parent c63bc35 commit 7fa17a6
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ const React = require('react')
const {TextField, FlatButton} = require('material-ui')
const Pydio = require('pydio');
const {ActionDialogMixin, CancelButtonProviderMixin, SubmitButtonProviderMixin} = Pydio.requireLib('boot');
const PassUtils = require('pydio/util/pass');

export default React.createClass({

mixins: [
ActionDialogMixin, CancelButtonProviderMixin, SubmitButtonProviderMixin
AdminComponents.MessagesConsumerMixin,
ActionDialogMixin,
CancelButtonProviderMixin,
SubmitButtonProviderMixin
],

propTypes: {
Expand All @@ -42,23 +46,21 @@ export default React.createClass({
},

getInitialState: function () {
return {okEnabled: false};
const pwdState = PassUtils.getState();
return {...pwdState};
},

onChange: function (event, value) {
const minLength = parseInt(global.pydio.getPluginConfigs("core.auth").get("PASSWORD_MINLENGTH"));

const enabled = (this.refs.pass.getValue()
&& this.refs.pass.getValue().length >= minLength
&& this.refs.pass.getValue() == this.refs.confirm.getValue()
);

this.setState({okEnabled: enabled});
const passValue = this.refs.pass.getValue();
const confirmValue = this.refs.confirm.getValue();
const newState = PassUtils.getState(passValue, confirmValue, this.state);
this.setState(newState);
},

submit: function () {

if(!this.state.okEnabled){
if(!this.state.valid){
this.props.pydio.UI.displayMessage('ERROR', this.state.passErrorText || this.state.confirmErrorText);
return;
}

Expand All @@ -84,13 +86,16 @@ export default React.createClass({
return (
<div style={{width: '100%'}}>
<TextField ref="pass" type="password" fullWidth={true}
onChange={this.onChange}
floatingLabelText={getMessage('523')}
errorText={!this.state.okEnabled ? getMessage('378') : null}
onChange={this.onChange}
floatingLabelText={getMessage('523')}
errorText={this.state.passErrorText}
hintText={this.state.passHintText}
/>
<TextField ref="confirm" type="password" fullWidth={true}
onChange={this.onChange}
floatingLabelText={getMessage('199')}/>
onChange={this.onChange}
floatingLabelText={getMessage('199')}
errorText={this.state.confirmErrorText}
/>
</div>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
*
* The latest code can be found at <https://pydio.com>.
*/
const PassUtils = require('pydio/util/pass');
const PydioDataModel = require('pydio/model/data-model');
import React from 'react'
import {TextField} from 'material-ui'

const CreateUserForm = React.createClass({

Expand All @@ -39,47 +43,44 @@ const CreateUserForm = React.createClass({
}
},

checkPassword:function(){
var value1 = this.refs.pass.getValue();
var value2 = this.refs.passconf.getValue();
var minLength = parseInt(global.pydio.getPluginConfigs("core.auth").get("PASSWORD_MINLENGTH"));
if(value1 && value1.length < minLength){
this.refs.pass.setErrorText(this.context.getMessage('378'));
return;
}
if(value1 && value2 && value2 != value1){
this.refs.passconf.setErrorText(this.context.getMessage('238'));
return;
}
this.refs.pass.setErrorText(null);
this.refs.passconf.setErrorText(null);
},

getInitialState: function(){
const passState = PassUtils.getState();
return {
step:1
step:1,
...passState
}
},

checkPassword:function(){
const value1 = this.refs.pass.getValue();
const value2 = this.refs.passconf.getValue();
this.setState(PassUtils.getState(value1, value2, this.state));
},

submit: function(dialog){
var parameters = {};
var ctx = this.props.dataModel.getUniqueNode() || this.props.dataModel.getContextNode();
if(!this.state.valid){
this.props.pydio.UI.displayMessage('ERROR', this.state.passErrorText || this.state.confirmErrorText);
return;
}

let parameters = {};
const ctx = this.props.dataModel.getUniqueNode() || this.props.dataModel.getContextNode();
parameters['get_action'] = 'create_user';
parameters['new_user_login'] = this.refs.user_id.getValue();
parameters['new_user_pwd'] = this.refs.pass.getValue();
var currentPath = ctx.getPath();
const currentPath = ctx.getPath();
if(currentPath.startsWith("/data/users")){
parameters['group_path'] = currentPath.substr("/data/users".length);
}
PydioApi.getClient().request(parameters, function(transport){
var xml = transport.responseXML;
var message = XMLUtils.XPathSelectSingleNode(xml, "//reload_instruction");
const xml = transport.responseXML;
const message = XMLUtils.XPathSelectSingleNode(xml, "//reload_instruction");
if(message){
var node = new AjxpNode(currentPath + "/"+ parameters['new_user_login'], true);
let node = new AjxpNode(currentPath + "/"+ parameters['new_user_login'], true);
node.getMetadata().set("ajxp_mime", "user");
//global.pydio.UI.openCurrentSelectionInEditor(node);
this.props.openRoleEditor(node);
var currentNode = global.pydio.getContextNode();
let currentNode = global.pydio.getContextNode();
if(global.pydio.getContextHolder().getSelectedNodes().length){
currentNode = global.pydio.getContextHolder().getSelectedNodes()[0];
}
Expand All @@ -90,9 +91,9 @@ const CreateUserForm = React.createClass({
},

render: function(){
var ctx = this.props.dataModel.getUniqueNode() || this.props.dataModel.getContextNode();
var currentPath = ctx.getPath();
var path;
const ctx = this.props.dataModel.getUniqueNode() || this.props.dataModel.getContextNode();
const currentPath = ctx.getPath();
let path;
if(currentPath.startsWith("/data/users")){
path = currentPath.substr("/data/users".length);
if(path){
Expand All @@ -102,28 +103,27 @@ const CreateUserForm = React.createClass({
return (
<div>
{path}
<div>
<ReactMUI.TextField
ref="user_id"
floatingLabelText={this.context.getMessage('ajxp_admin.user.21')}
/>
</div>
<div>
<ReactMUI.TextField
ref="pass"
type="password"
floatingLabelText={this.context.getMessage('ajxp_admin.user.22')}
onChange={this.checkPassword}
/>
</div>
<div>
<ReactMUI.TextField
ref="passconf"
type="password"
floatingLabelText={this.context.getMessage('ajxp_admin.user.23')}
onChange={this.checkPassword}
/>
</div>
<TextField
ref="user_id"
fullWidth={true}
floatingLabelText={this.context.getMessage('ajxp_admin.user.21')}
/>
<TextField
ref="pass"
type="password"
fullWidth={true}
floatingLabelText={this.context.getMessage('ajxp_admin.user.22')}
onChange={this.checkPassword}
errorText={this.state.passErrorText || this.state.passHintText}
/>
<TextField
ref="passconf"
type="password"
fullWidth={true}
floatingLabelText={this.context.getMessage('ajxp_admin.user.23')}
onChange={this.checkPassword}
errorText={this.state.confirmErrorText}
/>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,25 @@ class ButtonsComputer{
modelUpdated(){
this._buttonsUpdater(this.getButtons());
}
validStatusObserver(status){
if(status) this.enableSave();
else this.disableSave();
}
start(){
this._modelObserver = this.modelUpdated.bind(this);
this._disableSaveObserver = this.disableSave.bind(this);
this._enableSaveObserver = this.enableSave.bind(this);
this._validStatusObserver = this.validStatusObserver.bind(this);
this._shareModel.observe("status_changed", this._modelObserver);
this._shareModel.observe('saving', this._disableSaveObserver);
this._shareModel.observe('saved', this._enableSaveObserver);
this._shareModel.observe('valid_status', this._validStatusObserver);
}
stop(){
this._shareModel.stopObserving("status_changed", this._modelObserver);
this._shareModel.stopObserving('saving', this._disableSaveObserver);
this._shareModel.stopObserving('saved', this._enableSaveObserver);
this._shareModel.stopObserving('valid_status', this._validStatusObserver);
}
getButtons(){
let buttons = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ let PublicLinkPanel = React.createClass({
},

getInitialState: function(){
return {showTemporaryPassword: false, temporaryPassword: null, disabled: false};
return {showTemporaryPassword: false, temporaryPassword: null, passValid: false, disabled: false};
},

updateTemporaryPassword: function(value, event){
if(value == undefined) value = event.currentTarget.getValue();
this.setState({temporaryPassword:value});
let passValid = this.refs.passField.isValid();
this.setState({temporaryPassword:value, passValid: passValid});
},

enableLinkWithPassword:function(){
Expand Down Expand Up @@ -88,13 +89,14 @@ let PublicLinkPanel = React.createClass({
<div style={{display:'flex', alignItems:'baseline'}}>
<div style={{flex:1}}>
<ValidPassword
ref="passField"
attributes={{label:this.props.getMessage('23')}}
value={this.state.temporaryPassword}
onChange={this.updateTemporaryPassword}
/>
</div>
<div style={{marginLeft:7,marginTop: 26}}>
<RaisedButton label={this.props.getMessage('92')} secondary={true} onClick={this.enableLinkWithPassword}/>
<RaisedButton label={this.props.getMessage('92')} secondary={true} disabled={!this.state.passValid} onClick={this.enableLinkWithPassword}/>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ let PublicLinkSecureOptions = React.createClass({
},

updatePassword: function(newValue, oldValue){
if(newValue && !this.refs.passField.isValid()){
this.props.shareModel.setValidStatus(false);
} else{
this.props.shareModel.setValidStatus(true);
}
this.props.shareModel.updatePassword(this.props.linkData.hash, newValue);
},


renderPasswordContainer: function(){
var linkId = this.props.linkData.hash;
var passwordField;
Expand All @@ -60,14 +66,14 @@ let PublicLinkSecureOptions = React.createClass({
floatingLabelText={this.props.getMessage('23')}
disabled={true}
value={'********'}
onChange={this.updatePassword}
fullWidth={true}
/>
);
}else if(!this.props.isReadonly()){
passwordField = (
<ValidPassword
name="share-password"
ref="passField"
attributes={{label:this.props.getMessage('23')}}
value={this.props.shareModel.getPassword(linkId)}
onChange={this.updatePassword}
Expand Down
4 changes: 4 additions & 0 deletions core/src/plugins/action.share/res/react/model/ShareModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,10 @@
/*********************************/
/* GENERIC: STATUS / LOAD / SAVE */
/*********************************/
setValidStatus(status){
this.notify('valid_status', status);
}

_setStatus(status){
this._status = status;
this.notify('status_changed', {
Expand Down
3 changes: 2 additions & 1 deletion core/src/plugins/action.user/res/js/PasswordPopover.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ class PasswordPopover extends React.Component{
anchorOrigin={{horizontal: 'left', vertical: 'top'}}
targetOrigin={{horizontal: 'left', vertical: 'bottom'}}
onRequestClose={this.passClosePopover.bind(this)}
zDepth={2}
>
<div>
<PasswordForm
style={{padding:10, backgroundColor:'#fafafa'}}
style={{padding:10, paddingBottom: 30, backgroundColor:'#fafafa'}}
pydio={pydio}
ref="passwordForm"
onValidStatusChange={this.passValidStatusChange.bind(this)}
Expand Down
Loading

0 comments on commit 7fa17a6

Please sign in to comment.