зеркало из https://github.com/mozilla/fxa.git
stubbed /create route
This commit is contained in:
Родитель
248a90b2f1
Коммит
93f7d18d7a
|
@ -1,3 +1,7 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const Hapi = require('hapi');
|
||||
const CC = require('compute-cluster')
|
||||
const config = require('../lib/config')
|
||||
|
@ -5,7 +9,7 @@ const config = require('../lib/config')
|
|||
const hour = 1000 * 60 * 60
|
||||
|
||||
var cc = new CC({ module: __dirname + '/sign.js' })
|
||||
var db = {} // TODO
|
||||
var kv = require('../lib/kvstore').connect()
|
||||
|
||||
var routes = [
|
||||
{
|
||||
|
@ -33,6 +37,21 @@ var routes = [
|
|||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
method: 'POST',
|
||||
path: '/create',
|
||||
config: {
|
||||
handler: create,
|
||||
validate: {
|
||||
payload: {
|
||||
email: Hapi.types.String().email().required(),
|
||||
verifier: Hapi.types.String().required(),
|
||||
params: Hapi.types.String(),
|
||||
kB: Hapi.types.String()
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
method: 'POST',
|
||||
path: '/sign',
|
||||
|
@ -50,13 +69,25 @@ var routes = [
|
|||
},
|
||||
{
|
||||
method: 'POST',
|
||||
path: '/login',
|
||||
path: '/beginLogin',
|
||||
config: {
|
||||
handler: login,
|
||||
handler: beginLogin,
|
||||
validate: {
|
||||
payload: {
|
||||
email: Hapi.types.String().email().required(),
|
||||
password: Hapi.types.String().required() // for testing only
|
||||
email: Hapi.types.String().email().required()
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
method: 'POST',
|
||||
path: '/finishLogin',
|
||||
config: {
|
||||
handler: finishLogin,
|
||||
validate: {
|
||||
payload: {
|
||||
sessionId: Hapi.types.String().required(),
|
||||
password: Hapi.types.String().required()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +102,24 @@ function wellKnown(request) {
|
|||
})
|
||||
}
|
||||
|
||||
function create(request) {
|
||||
kv.get(
|
||||
request.payload.email,
|
||||
function (err, record) {
|
||||
if (err) {
|
||||
request.reply(Hapi.error.internal('Database errror', err))
|
||||
}
|
||||
else if (record) {
|
||||
request.reply('ok')
|
||||
}
|
||||
else {
|
||||
//TODO do stuff
|
||||
request.reply('ok')
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function sign(request) {
|
||||
// TODO validate token, get email from token
|
||||
cc.enqueue(
|
||||
|
@ -86,8 +135,8 @@ function sign(request) {
|
|||
)
|
||||
}
|
||||
|
||||
function login(request) {
|
||||
db.get(
|
||||
function beginLogin(request) {
|
||||
kv.get(
|
||||
request.payload.email,
|
||||
function (err, record) {
|
||||
if (err) {
|
||||
|
@ -98,12 +147,24 @@ function login(request) {
|
|||
}
|
||||
else {
|
||||
var token = 'TODO'
|
||||
request.reply({ token: token })
|
||||
request.reply({ sessionId: token })
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function finishLogin(request) {
|
||||
// TODO lookup sessionId, verify email/password
|
||||
var accountToken = 'TODO'
|
||||
var kA = 'TODO'
|
||||
var kB = 'TODO'
|
||||
request.reply({
|
||||
accountToken: accountToken,
|
||||
kA: kA,
|
||||
kB: kB
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
routes: routes
|
||||
}
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const jwcrypto = require('jwcrypto');
|
||||
const config = require('../lib/config')
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче