зеркало из https://github.com/mozilla/gombot.git
adjust validation and error responses
This commit is contained in:
Родитель
abbacda529
Коммит
ecf3cf4987
|
@ -1,9 +1,10 @@
|
|||
var crypto = require('crypto'),
|
||||
Hapi = require('hapi'),
|
||||
db = require('../../db');
|
||||
var crypto = require('crypto');
|
||||
var Hapi = require('hapi');
|
||||
var db = require('../../db.js');
|
||||
var util = require('../../util.js');
|
||||
|
||||
var B = Hapi.Types.Boolean,
|
||||
S = Hapi.Types.String;
|
||||
var B = Hapi.Types.Boolean;
|
||||
var S = Hapi.Types.String;
|
||||
|
||||
module.exports = {
|
||||
method: 'POST',
|
||||
|
@ -13,20 +14,19 @@ module.exports = {
|
|||
mode: 'none'
|
||||
},
|
||||
description: 'Stage a new account',
|
||||
schema: {
|
||||
email: S(),
|
||||
pass: S(),
|
||||
newsletter: B()
|
||||
},
|
||||
response: {
|
||||
success: B()
|
||||
validate: {
|
||||
schema: {
|
||||
email: S().email().required(),
|
||||
pass: S().required(),
|
||||
newsletter: B()
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function handler(request) {
|
||||
db.stageAccount(request.payload, function(err) {
|
||||
if (err) request.reply(Hapi.Error.internal("error staging account"));
|
||||
if (err) return request.reply(Hapi.Error.badRequest("Could not create account: " + err));
|
||||
request.reply({
|
||||
success: true
|
||||
});
|
||||
|
|
|
@ -21,7 +21,7 @@ module.exports = {
|
|||
|
||||
function handler(request) {
|
||||
crypto.randomBytes(32, function(err, bytes) {
|
||||
if (err) return Hapi.Error.internal("error attaining entropy");
|
||||
if (err) return request.reply(Hapi.Error.internal("error attaining entropy"));
|
||||
request.reply({
|
||||
server_time: Math.round((new Date()).getTime() / 1000),
|
||||
entropy: bytes.toString('base64')
|
||||
|
|
|
@ -30,6 +30,7 @@ module.exports = {
|
|||
staged: false
|
||||
};
|
||||
setTimeout(function() {
|
||||
if (db[data.email]) return cb("That email has already been used");
|
||||
db[data.email] = account;
|
||||
cb(null);
|
||||
}, 0);
|
||||
|
|
Загрузка…
Ссылка в новой задаче