From 00ab234ed879d0ca674677bb1147b3d35f129301 Mon Sep 17 00:00:00 2001 From: Dario Chiappetta Date: Tue, 14 Apr 2015 10:36:12 +0200 Subject: [PATCH] Added Delete Account feature (no dev backend support yet) --- .../Components/ExtraFeatures/DeleteAccount.js | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 frontend/delta/js/Clipperz/PM/UI/Components/ExtraFeatures/DeleteAccount.js diff --git a/frontend/delta/js/Clipperz/PM/UI/Components/ExtraFeatures/DeleteAccount.js b/frontend/delta/js/Clipperz/PM/UI/Components/ExtraFeatures/DeleteAccount.js new file mode 100644 index 0000000..a38c17d --- /dev/null +++ b/frontend/delta/js/Clipperz/PM/UI/Components/ExtraFeatures/DeleteAccount.js @@ -0,0 +1,138 @@ +/* + +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.DeleteAccount'); + +Clipperz.PM.UI.Components.ExtraFeatures.DeleteAccountClass = React.createClass({ + + propTypes: { +// featureSet: React.PropTypes.oneOf(['FULL', 'EXPIRED', 'TRIAL']).isRequired, +// 'level': React.PropTypes.oneOf(['hide', 'info', 'warning', 'error']).isRequired + }, + + getInitialState: function() { + return { + 'username': 'empty', + 'passphrase': 'empty', + 'confirm': '', + //~ 'error': '' + }; + }, + + //========================================================================= + + handleDeleteAccount: function(event) { + event.preventDefault(); + + //~ if (this.refs['username'].getDOMNode().value != this.props.userInfo['username']) { + //~ this.setState({error: "Invalid username"}); + //~ return; + //~ } + //~ + //~ var deferredResult; + //~ + //~ deferredResult = new Clipperz.Async.Deferred("DeleteAccount.handleDeleteAccount", {trace: false}); + //~ deferredResult.addCallback(this.props.userInfo['checkPassphraseCallback'], this.refs['passphrase'].getDOMNode().value); + //~ deferredResult.addIf( + //~ [MochiKit.Base.partial(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'deleteAccount')], + //~ [MochiKit.Base.bind(this.setState, this, {error: "Invalid password"})] + //~ ); + //~ + //~ deferredResult.callback(); + //~ + //~ return deferredResult; + + MochiKit.Signal.signal(Clipperz.Signal.NotificationCenter, 'deleteAccount'); + }, + + handleFormChange: function() { + + + //~ if (this.refs['username'].getDOMNode().value != this.props.userInfo['username']) { + //~ this.setState({error: "Invalid username"}); + //~ return; + //~ } + + var deferredResult; + + deferredResult = new Clipperz.Async.Deferred("DeleteAccount.handleDeleteAccount", {trace: false}); + deferredResult.addCallback(this.props.userInfo['checkPassphraseCallback'], this.refs['passphrase'].getDOMNode().value); + deferredResult.addMethod(this, function(passCheck){ + var username = this.refs['username'].getDOMNode().value; + var passphrase = this.refs['passphrase'].getDOMNode().value; + + this.setState({ + 'username': (username != '') ? (username == this.props.userInfo['username']) ? 'valid' : 'invalid' : 'empty', + 'passphrase': (passphrase != '') ? (passCheck) ? 'valid' : 'invalid' : 'empty', + 'confirm': this.refs['confirm'].getDOMNode().checked, + }); + }); + + deferredResult.callback(); + + return deferredResult; + + + + //~ this.setState({ + //~ 'username': this.refs['username'].getDOMNode().value, + //~ 'passphrase': this.refs['passphrase'].getDOMNode().value, + //~ 'confirm': this.refs['confirm'].getDOMNode().checked, + //~ }); + }, + + shouldEnableDeleteAccountButton: function() { + return (this.state['username'] == 'valid' && this.state['passphrase'] == 'valid' && this.state['confirm']); + }, + + //========================================================================= + + render: function () { + //~ var errorVisibility = (this.state.error) ? 'visible' : 'hidden'; + + return React.DOM.div({className:'extraFeature deleteAccount'}, [ + React.DOM.h1({}, "Delete Account"), + React.DOM.form({'key':'form', 'className':'deleteAccountForm', 'onChange': this.handleFormChange, 'onSubmit':this.handleDeleteAccount}, [ + React.DOM.div({'key':'fields'},[ + React.DOM.label({'key':'username-label', 'htmlFor' :'name'}, "username"), + React.DOM.input({'key':'username', 'className': this.state['username'], 'type':'text', 'name':'name', 'ref':'username', 'placeholder':"username", 'autoCapitalize':'none'}), + React.DOM.span({'className': 'invalidMsg'},'Invalid username!'), + React.DOM.label({'key':'passphrase-label', 'autoFocus': 'true', 'htmlFor' :'passphrase'}, "passphrase"), + React.DOM.input({'key':'passphrase', 'className': this.state['passphrase'], 'type':'password', 'name':'passphrase', 'ref':'passphrase', 'placeholder':"passphrase"}), + React.DOM.span({'className': 'invalidMsg'},'Invalid passphrase!'), + React.DOM.p({}, [ + React.DOM.input({'key':'confirm', 'className':'confirmCheckbox', 'type':'checkbox', 'name':'confirm', 'ref':'confirm'}), + React.DOM.span({}, "I understand that all my data will be deleted and that this action is irreversible.") + ]), + ]), + React.DOM.button({'key':'button', 'type':'submit', 'disabled':!this.shouldEnableDeleteAccountButton(), 'className':'button'}, "Delete my account") + //~ React.DOM.div({ref: 'errorMessage', className: 'errorMessage', style: {visibility: errorVisibility} }, this.state.error) + ]) + ]); + }, + + //========================================================================= +}); + +Clipperz.PM.UI.Components.ExtraFeatures.DeleteAccount = React.createFactory(Clipperz.PM.UI.Components.ExtraFeatures.DeleteAccountClass);