diff --git a/package.json b/package.json index f8f40e3..db8bd19 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "react-bootstrap": "^0.30.6", "react-dom": "^15.3.2", "react-redux": "^4.4.6", + "react-redux-form": "^1.2.4", "react-router": "^3.0.0", "react-router-bootstrap": "^0.23.1", "react-router-redux": "^4.0.7", diff --git a/src/internal/users/handlers.go b/src/internal/users/handlers.go index 7f95366..eda6af9 100644 --- a/src/internal/users/handlers.go +++ b/src/internal/users/handlers.go @@ -134,7 +134,7 @@ func EditHandler(e *web.Env, w http.ResponseWriter, r *http.Request) error { return err } - if data.Password == "" && data.PasswordConfirm != "" { + if data.Password != "" && data.PasswordConfirm != "" { if data.Password != data.PasswordConfirm { return e.RenderError(w, fmt.Errorf("Passwords empty or missmatch")) } @@ -145,10 +145,6 @@ func EditHandler(e *web.Env, w http.ResponseWriter, r *http.Request) error { if err != nil { return err } - - if err := user.Update(e.Database); err != nil { - return err - } } // Update the polochon config @@ -162,5 +158,10 @@ func EditHandler(e *web.Env, w http.ResponseWriter, r *http.Request) error { return err } + // Save the user with the new configurations + if err := user.Update(e.Database); err != nil { + return err + } + return e.RenderOK(w, "user updated") } diff --git a/src/internal/users/users.go b/src/internal/users/users.go index ad1b224..30b7d25 100644 --- a/src/internal/users/users.go +++ b/src/internal/users/users.go @@ -55,8 +55,7 @@ func (u *User) GetConfig(key string, v interface{}) error { // SetConfig marshal v into json for specified config key func (u *User) SetConfig(key string, v interface{}) error { var configMap map[string]*json.RawMessage - err := u.RawConfig.Unmarshal(&configMap) - if err != nil { + if err := u.RawConfig.Unmarshal(&configMap); err != nil { return err } @@ -65,6 +64,10 @@ func (u *User) SetConfig(key string, v interface{}) error { return err } + if configMap == nil { + configMap = map[string]*json.RawMessage{} + } + r := json.RawMessage(b) configMap[key] = &r b, err = json.Marshal(configMap) diff --git a/src/public/js/components/users/edit.js b/src/public/js/components/users/edit.js index ca34331..4e28e8b 100644 --- a/src/public/js/components/users/edit.js +++ b/src/public/js/components/users/edit.js @@ -1,4 +1,5 @@ import React from 'react' +import { Control, Form } from 'react-redux-form'; export default class UserEdit extends React.Component { componentWillMount() { @@ -8,19 +9,15 @@ export default class UserEdit extends React.Component { super(props); this.handleSubmit = this.handleSubmit.bind(this); } - handleSubmit(e) { - e.preventDefault(); + handleSubmit() { this.props.updateUser({ - 'polochon_url': this.refs.polochonUrl.value, - 'polochon_token': this.refs.polochonToken.value, + 'polochon_url': this.props.userStore.polochonUrl, + 'polochon_token': this.props.userStore.polochonToken, 'password': this.refs.newPassword.value, 'password_confirm': this.refs.newPasswordConfirm.value, }); } render() { - // TODO make this fields editable - const polochonUrl = this.props.userStore.polochonUrl; - const polochonToken = this.props.userStore.polochonToken; return (