Fix user edit frontend and backend
This commit is contained in:
parent
d6df379fc4
commit
85672b5242
@ -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",
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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 (
|
||||
<div className="container">
|
||||
<div className="content-fluid">
|
||||
@ -28,15 +25,15 @@ export default class UserEdit extends React.Component {
|
||||
<h2>Edit user</h2>
|
||||
<hr />
|
||||
|
||||
<form ref="userEditForm" className="form-horizontal" onSubmit={(e) => this.handleSubmit(e)}>
|
||||
<Form model="userStore" className="form-horizontal" onSubmit={(val) => this.handleSubmit(val)}>
|
||||
<div className="form-group">
|
||||
<label className="control-label">Polochon URL</label>
|
||||
<input autoFocus="autofocus" className="form-control" type="text" ref="polochonUrl" value={polochonUrl} />
|
||||
<Control.text model="userStore.polochonUrl" className="form-control" />
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label className="control-label">Polochon token</label>
|
||||
<input className="form-control" ref="polochonToken" type="text" value={polochonToken} />
|
||||
<Control.text model="userStore.polochonToken" className="form-control"/>
|
||||
</div>
|
||||
|
||||
<hr />
|
||||
@ -54,7 +51,7 @@ export default class UserEdit extends React.Component {
|
||||
<div>
|
||||
<input className="btn btn-primary pull-right" type="submit" value="Update"/>
|
||||
</div>
|
||||
</form>
|
||||
</Form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,11 +1,14 @@
|
||||
import { combineReducers } from 'redux';
|
||||
import { combineForms } from 'react-redux-form'
|
||||
import { routerReducer } from 'react-router-redux'
|
||||
|
||||
import movieStore from './movies'
|
||||
import userStore from './users'
|
||||
import errors from './errors'
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
// Use combine form form react-redux-form, it's a thin wrapper arround the
|
||||
// default combinedReducers provided with React. It allows the forms to be
|
||||
// linked directly to the store.
|
||||
const rootReducer = combineForms({
|
||||
routing: routerReducer,
|
||||
movieStore,
|
||||
userStore,
|
||||
|
18
yarn.lock
18
yarn.lock
@ -1795,6 +1795,10 @@ https-browserify@0.0.0:
|
||||
version "0.0.0"
|
||||
resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-0.0.0.tgz#b3ffdfe734b2a3d4a9efd58e8654c91fce86eafd"
|
||||
|
||||
icepick@^1.1.0:
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/icepick/-/icepick-1.3.0.tgz#e4942842ed8f9ee778d7dd78f7e36627f49fdaef"
|
||||
|
||||
iconv-lite@~0.4.13:
|
||||
version "0.4.13"
|
||||
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.13.tgz#1f88aba4ab0b1508e8312acc39345f36e992e2f2"
|
||||
@ -1866,7 +1870,7 @@ invariant@^2.0.0, invariant@^2.2.0, invariant@^2.2.1:
|
||||
dependencies:
|
||||
loose-envify "^1.0.0"
|
||||
|
||||
invariant@^2.1.0:
|
||||
invariant@^2.1.0, invariant@~2.2.1:
|
||||
version "2.2.2"
|
||||
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.2.tgz#9e1f56ac0acdb6bf303306f338be3b204ae60360"
|
||||
dependencies:
|
||||
@ -2306,6 +2310,10 @@ lodash.templatesettings@^3.0.0:
|
||||
lodash._reinterpolate "^3.0.0"
|
||||
lodash.escape "^3.0.0"
|
||||
|
||||
lodash@^4.10.0:
|
||||
version "4.17.2"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.2.tgz#34a3055babe04ce42467b607d700072c7ff6bf42"
|
||||
|
||||
lodash@^4.2.0:
|
||||
version "4.16.6"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.16.6.tgz#d22c9ac660288f3843e16ba7d2b5d06cca27d777"
|
||||
@ -3093,6 +3101,14 @@ react-redux:
|
||||
lodash "^4.2.0"
|
||||
loose-envify "^1.1.0"
|
||||
|
||||
react-redux-form:
|
||||
version "1.2.4"
|
||||
resolved "https://registry.yarnpkg.com/react-redux-form/-/react-redux-form-1.2.4.tgz#924c5ac06dd52f21efc961df6aed9c10bfe27de9"
|
||||
dependencies:
|
||||
icepick "^1.1.0"
|
||||
invariant "~2.2.1"
|
||||
lodash "^4.10.0"
|
||||
|
||||
react-router:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/react-router/-/react-router-3.0.0.tgz#3f313e4dbaf57048c48dd0a8c3cac24d93667dff"
|
||||
|
Loading…
x
Reference in New Issue
Block a user