create account is done

This commit is contained in:
Sukchan Lee 2017-09-22 16:13:25 +09:00
parent ec3530524a
commit 7e8e421ebe
3 changed files with 67 additions and 21 deletions

View File

@ -10,7 +10,7 @@ const schema = {
"properties": {
"username": {
"type": "string",
"title": "Username",
"title": "Username*",
"required": true,
},
"roles": {
@ -20,22 +20,40 @@ const schema = {
"type": "string",
"title": "Role",
"enum": [ "user", "admin" ],
}
"required": true,
},
},
"password1": {
"type": "string",
"title": "Password*",
},
"password2": {
"type": "string",
"title": "Confirm Password*",
},
}
};
const uiSchema = {
"username" : {
classNames: "col-xs-12",
},
"roles" : {
"classNames" : "col-xs-12",
"ui:options": {
"addable": false,
"orderable": false,
"removable": false
}
}
},
"username" : {
"classNames" : "col-xs-12",
},
"password1" : {
"classNames" : "col-xs-6",
"ui:widget": "password",
},
"password2" : {
"classNames" : "col-xs-6",
"ui:widget": "password",
},
}
class Edit extends Component {
@ -110,7 +128,7 @@ class Edit extends Component {
visible={visible}
title={(action === 'update') ? 'Edit Account' : 'Create Account'}
width="480px"
height="240px"
height="400px"
schema={this.state.schema}
uiSchema={this.state.uiSchema}
formData={formData}

View File

@ -431,7 +431,7 @@ class Edit extends Component {
"properties": {
profile: {
type: "string",
title: "Profile",
title: "Profile*",
enum: profiles.map(profile => profile._id),
enumNames: profiles.map(profile => profile.title),
default: state.profile

View File

@ -12,9 +12,10 @@ import * as Notification from 'modules/notification/actions';
import { Account } from 'components';
import traverse from 'traverse';
import crypto from 'crypto';
const formData = {
"roles": [ "user" ]
"roles": [ "user" ],
}
class Document extends Component {
@ -112,22 +113,49 @@ class Document extends Component {
return errors;
}
generatePassword = function(password, cb) {
crypto.randomBytes(32, function(randomBytesErr, buf) {
if (randomBytesErr) {
return cb(randomBytesErr);
}
var salt = buf.toString('hex');
crypto.pbkdf2(password, salt, 25000, 512, 'sha256', function(pbkdf2Err, hashRaw) {
if (pbkdf2Err) {
return cb(pbkdf2Err);
}
var hash = new Buffer(hashRaw, 'binary').toString('hex');
cb(null, salt, hash);
});
});
};
handleSubmit = (formData) => {
const { dispatch, action } = this.props;
NProgress.configure({
parent: '#nprogress-base-form',
trickleSpeed: 5
});
NProgress.start();
this.generatePassword(formData.password1, (err, salt, hash) => {
if (err) throw err
if (action === 'create') {
dispatch(createAccount({}, formData));
} else if (action === 'update') {
dispatch(updateAccount(formData.username, {}, formData));
} else {
throw new Error(`Action type '${action}' is invalid.`);
}
formData = Object.assign(formData, {
salt,
hash,
})
NProgress.configure({
parent: '#nprogress-base-form',
trickleSpeed: 5
});
NProgress.start();
if (action === 'create') {
dispatch(createAccount({}, formData));
} else if (action === 'update') {
dispatch(updateAccount(formData.username, {}, formData));
} else {
throw new Error(`Action type '${action}' is invalid.`);
}
})
}
handleError = errors => {