From 0863e61631ca6c4b6a398c757675c0b52a9b6774 Mon Sep 17 00:00:00 2001 From: Dario Chiappetta Date: Fri, 3 Apr 2015 16:03:17 +0200 Subject: [PATCH] Added change passphrase logic in MainController --- .../UI/Components/ExtraFeatures/Passphrase.js | 97 +++++++++++++++++++ .../delta/js/Clipperz/PM/UI/MainController.js | 21 +++- 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 frontend/delta/js/Clipperz/PM/UI/Components/ExtraFeatures/Passphrase.js diff --git a/frontend/delta/js/Clipperz/PM/UI/Components/ExtraFeatures/Passphrase.js b/frontend/delta/js/Clipperz/PM/UI/Components/ExtraFeatures/Passphrase.js new file mode 100644 index 0000000..057b11a --- /dev/null +++ b/frontend/delta/js/Clipperz/PM/UI/Components/ExtraFeatures/Passphrase.js @@ -0,0 +1,97 @@ +/* + +Copyright 2008-2015 Clipperz Srl + +This file is part of Clipperz, the online password manager. +For further information about its features and functionalities please +refer to http://www.clipperz.com. + +* Clipperz is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + +* Clipperz is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Affero General Public License for more details. + +* You should have received a copy of the GNU Affero General Public + License along with Clipperz. If not, see http://www.gnu.org/licenses/. + +*/ + +"use strict"; +Clipperz.Base.module('Clipperz.PM.UI.Components.ExtraFeatures'); + +Clipperz.PM.UI.Components.ExtraFeatures.PassphraseClass = React.createClass({ + + propTypes: { +// featureSet: React.PropTypes.oneOf(['FULL', 'EXPIRED', 'TRIAL']).isRequired, +// 'level': React.PropTypes.oneOf(['hide', 'info', 'warning', 'error']).isRequired + }, + + getInitialState: function() { + return { +// 'username': '', +// 'old-passphrase': '', + 'new-passphrase': '', + 'confirm-new-passphrase': '' + }; + }, + + //========================================================================= + + shouldEnableChangePassphraseButton: function() { + return ( +// this.state['username'] && +// this.state['old-passphrase'] && + this.state['new-passphrase'] && + this.state['confirm-new-passphrase'] && + (this.state['new-passphrase'] == this.state['confirm-new-passphrase']) + ); + }, + + handleFormChange: function() { + this.setState({ +// 'username': this.refs['username'].getDOMNode().value, +// 'old-passphrase': this.refs['old-passphrase'].getDOMNode().value, + 'new-passphrase': this.refs['new-passphrase'].getDOMNode().value, + 'confirm-new-passphrase': this.refs['confirm-new-passphrase'].getDOMNode().value + }); + }, + + handleChangePassphrase: function(event) { + event.preventDefault(); + + this.refs['new-passphrase'].getDOMNode().value = ''; + this.refs['confirm-new-passphrase'].getDOMNode().value = ''; + + MochiKit.Signal.signal(Clipperz.Signal.NotificationCenter, 'changePassphrase', this.refs['new-passphrase'].getDOMNode().value); + }, + + //========================================================================= + + render: function () { + return React.DOM.div({className:'extraFeature passphrase'}, [ + React.DOM.h1({}, "Change Passphrase"), + React.DOM.form({'key':'form', 'className':'changePassphraseForm', 'onChange': this.handleFormChange, 'onSubmit':this.handleChangePassphrase}, [ + React.DOM.div({'key':'fields'},[ +// React.DOM.label({'key':'username-label', 'htmlFor' :'name'}, "username"), +// React.DOM.input({'key':'username', 'type':'text', 'name':'name', 'ref':'username', 'placeholder':"username", 'autoCapitalize':'none'}), +// React.DOM.label({'key':'old-passphrase-label', 'htmlFor' :'old-passphrase'}, "old passphrase"), +// React.DOM.input({'key':'old-passphrase', 'type':'password', 'name':'old-passphrase', 'ref':'old-passphrase', 'placeholder':"old passphrase"}), + React.DOM.label({'key':'new-passphrase-label', 'autoFocus': 'true', 'htmlFor' :'new-passphrase'}, "new passphrase"), + React.DOM.input({'key':'new-passphrase', 'type':'password', 'name':'new-passphrase', 'ref':'new-passphrase', 'placeholder':"new passphrase"}), + React.DOM.label({'key':'confirm-new-passphrase-label', 'htmlFor' :'confirm-new-passphrase'}, "confirm new passphrase"), + React.DOM.input({'key':'confirm-new-passphrase', 'type':'password', 'name':'confirm-new-passphrase', 'ref':'confirm-new-passphrase', 'placeholder':"confirm new passphrase"}) + ]), + React.DOM.button({'key':'button', 'type':'submit', 'disabled':!this.shouldEnableChangePassphraseButton(), 'className':'button'}, "Change") + ]), + ]); + }, + + //========================================================================= +}); + +Clipperz.PM.UI.Components.ExtraFeatures.Passphrase = React.createFactory(Clipperz.PM.UI.Components.ExtraFeatures.PassphraseClass); diff --git a/frontend/delta/js/Clipperz/PM/UI/MainController.js b/frontend/delta/js/Clipperz/PM/UI/MainController.js index 640e1e5..54f1578 100644 --- a/frontend/delta/js/Clipperz/PM/UI/MainController.js +++ b/frontend/delta/js/Clipperz/PM/UI/MainController.js @@ -1208,7 +1208,26 @@ console.log("THE BROWSER IS OFFLINE"); //---------------------------------------------------------------------------- changePassphrase_handler: function(newPassphrase) { - console.log("changePassphrase", newPassphrase); + var currentPage = this.pages()[this.currentPage()]; + var deferredResult; + var getPassphraseDelegate; + var user; + + getPassphraseDelegate = MochiKit.Base.partial(MochiKit.Async.succeed, newPassphrase); + user = new Clipperz.PM.DataModel.User({'username':this.user().username(), 'getPassphraseFunction':getPassphraseDelegate}); + + deferredResult = new Clipperz.Async.Deferred("MainController.changePassphrase_handler", {trace: false}); +// deferredResult.addMethod(currentPage, 'setProps', {'showGlobalMask':true}); + deferredResult.addMethod(this.overlay(), 'show', "changing …", true); + deferredResult.addMethod(this.user(), 'changePassphrase', newPassphrase); + deferredResult.addMethod(user, 'login'); + deferredResult.addMethod(this, 'setUser', user); +// deferredResult.addMethod(currentPage, 'setProps', {'mode':'view', 'showGlobalMask':false}); + deferredResult.addMethod(this.overlay(), 'done', "saved", 1); + + deferredResult.callback(); + + return deferredResult; }, //----------------------------------------------------------------------------