diff --git a/bemani/frontend/account/account.py b/bemani/frontend/account/account.py index a67b8af..ba2de03 100644 --- a/bemani/frontend/account/account.py +++ b/bemani/frontend/account/account.py @@ -411,16 +411,29 @@ def updateemail() -> Dict[str, Any]: @jsonify @loginrequired def updatepin() -> Dict[str, Any]: - pin = request.get_json()["pin"] + old = request.get_json()["old"] + pin1 = request.get_json()["pin1"] + pin2 = request.get_json()["pin2"] user = g.data.local.user.get_user(g.userID) if user is None: raise Exception("Unable to find user to update!") - if not valid_pin(pin, "card"): + # Make sure current password matches + if not g.data.local.user.validate_password(g.userID, old): + raise Exception("Current password is not correct!") + + # Make sure the PIN is valid. + if not valid_pin(pin1, "card"): + raise Exception("Invalid PIN, must be exactly 4 digits!") + if not valid_pin(pin2, "card"): raise Exception("Invalid PIN, must be exactly 4 digits!") + # Make sure it was confirmed twice. + if pin1 != pin2: + raise Exception("PINs do not match each other!") + # Update and save - g.data.local.user.update_pin(g.userID, pin) + g.data.local.user.update_pin(g.userID, pin1) # Return nothing return {} diff --git a/bemani/frontend/app.py b/bemani/frontend/app.py index adf4e04..288dd8c 100644 --- a/bemani/frontend/app.py +++ b/bemani/frontend/app.py @@ -119,7 +119,15 @@ def loginprohibited(func: Callable) -> Callable: def jsonify(func: Callable) -> Callable: @wraps(func) def decoratedfunction(*args: Any, **kwargs: Any) -> Response: - resp = func(*args, **kwargs) + try: + resp = func(*args, **kwargs) + except Exception as e: + print(traceback.format_exc()) + resp = { + "error": True, + "message": str(e), + } + try: return flask_jsonify(resp) except Exception as e: diff --git a/bemani/frontend/static/controllers/account/account.react.js b/bemani/frontend/static/controllers/account/account.react.js index 65347d5..ebf7aa9 100644 --- a/bemani/frontend/static/controllers/account/account.react.js +++ b/bemani/frontend/static/controllers/account/account.react.js @@ -9,7 +9,8 @@ var account_management = createReactClass({ editing_email: false, username: window.username, editing_pin: false, - new_pin: '', + new_pin1: '', + new_pin2: '', editing_password: false, old_password: '', new_password1: '', @@ -38,6 +39,7 @@ var account_management = createReactClass({ email_password: '', editing_email: false, }); + Messages.success("Your email address has been updated!") }.bind(this) ); event.preventDefault(); @@ -46,12 +48,19 @@ var account_management = createReactClass({ savePin: function(event) { AJAX.post( Link.get('updatepin'), - {pin: this.state.new_pin}, + { + old: this.state.old_password, + pin1: this.state.new_pin1, + pin2: this.state.new_pin2, + }, function(response) { this.setState({ - new_pin: '', + old_password: '', + new_pin1: '', + new_pin2: '', editing_pin: false, }); + Messages.success("Your PIN has been updated!") }.bind(this) ); event.preventDefault(); @@ -72,6 +81,7 @@ var account_management = createReactClass({ new_password2: '', editing_password: false, }); + Messages.success("Your password has been updated!") }.bind(this) ); event.preventDefault(); @@ -91,7 +101,7 @@ var account_management = createReactClass({ •••••• : @@ -113,6 +123,7 @@ var account_management = createReactClass({ New password (again): { this.state.email } : @@ -221,41 +233,78 @@ var account_management = createReactClass({ •••• :
- (this.focus_element = c)} - value={this.state.new_pin} - onChange={function(event) { - var intRegex = /^\d*$/; - if (event.target.value.length <= 4 && intRegex.test(event.target.value)) { - this.setState({new_pin: event.target.value}); - } - }.bind(this)} - name="pin" - /> - - +
+ + (this.focus_element = c)} + value={this.state.old_password} + onChange={function(event) { + this.setState({old_password: event.target.value}); + }.bind(this)} + name="old" + /> +
+
+ + (this.focus_element = c)} + value={this.state.new_pin1} + onChange={function(event) { + var intRegex = /^\d*$/; + if (event.target.value.length <= 4 && intRegex.test(event.target.value)) { + this.setState({new_pin1: event.target.value}); + } + }.bind(this)} + name="pin1" + /> +
+
+ + (this.focus_element = c)} + value={this.state.new_pin2} + onChange={function(event) { + var intRegex = /^\d*$/; + if (event.target.value.length <= 4 && intRegex.test(event.target.value)) { + this.setState({new_pin2: event.target.value}); + } + }.bind(this)} + name="pin2" + /> +
+
+ + +
} );