mirror of https://gitee.com/bigwinds/arangodb
Migrated session/user routes and models to joi.
This commit is contained in:
parent
e73ab38720
commit
e0e003d060
|
@ -3,10 +3,12 @@
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
var _ = require('underscore'),
|
var _ = require('underscore'),
|
||||||
|
joi = require('joi'),
|
||||||
Foxx = require('org/arangodb/foxx'),
|
Foxx = require('org/arangodb/foxx'),
|
||||||
errors = require('./errors'),
|
errors = require('./errors'),
|
||||||
controller = new Foxx.Controller(applicationContext),
|
controller = new Foxx.Controller(applicationContext),
|
||||||
api = Foxx.requireApp(applicationContext.mount).sessionStorage;
|
api = Foxx.requireApp(applicationContext.mount).sessionStorage,
|
||||||
|
sessionId = joi.string().description('Session ID');
|
||||||
|
|
||||||
controller.post('/', function (req, res) {
|
controller.post('/', function (req, res) {
|
||||||
var session = api.create(req.body());
|
var session = api.create(req.body());
|
||||||
|
@ -21,10 +23,7 @@
|
||||||
var session = api.get(req.urlParameters.sid);
|
var session = api.get(req.urlParameters.sid);
|
||||||
res.json(session.forClient());
|
res.json(session.forClient());
|
||||||
})
|
})
|
||||||
.pathParam('sid', {
|
.pathParam('sid', {type: sessionId})
|
||||||
description: 'Session ID',
|
|
||||||
type: 'string'
|
|
||||||
})
|
|
||||||
.errorResponse(errors.SessionExpired, 404, 'Session has expired')
|
.errorResponse(errors.SessionExpired, 404, 'Session has expired')
|
||||||
.errorResponse(errors.SessionNotFound, 404, 'Session does not exist')
|
.errorResponse(errors.SessionNotFound, 404, 'Session does not exist')
|
||||||
.summary('Read session')
|
.summary('Read session')
|
||||||
|
@ -37,10 +36,7 @@
|
||||||
session.save();
|
session.save();
|
||||||
res.json(session.forClient());
|
res.json(session.forClient());
|
||||||
})
|
})
|
||||||
.pathParam('sid', {
|
.pathParam('sid', {type: sessionId})
|
||||||
description: 'Session ID',
|
|
||||||
type: 'string'
|
|
||||||
})
|
|
||||||
.errorResponse(errors.SessionExpired, 404, 'Session has expired')
|
.errorResponse(errors.SessionExpired, 404, 'Session has expired')
|
||||||
.errorResponse(errors.SessionNotFound, 404, 'Session does not exist')
|
.errorResponse(errors.SessionNotFound, 404, 'Session does not exist')
|
||||||
.errorResponse(SyntaxError, 400, 'Malformed or non-JSON session data.')
|
.errorResponse(SyntaxError, 400, 'Malformed or non-JSON session data.')
|
||||||
|
@ -54,10 +50,7 @@
|
||||||
session.save();
|
session.save();
|
||||||
res.json(session.forClient());
|
res.json(session.forClient());
|
||||||
})
|
})
|
||||||
.pathParam('sid', {
|
.pathParam('sid', {type: sessionId})
|
||||||
description: 'Session ID',
|
|
||||||
type: 'string'
|
|
||||||
})
|
|
||||||
.errorResponse(errors.SessionExpired, 404, 'Session has expired')
|
.errorResponse(errors.SessionExpired, 404, 'Session has expired')
|
||||||
.errorResponse(errors.SessionNotFound, 404, 'Session does not exist')
|
.errorResponse(errors.SessionNotFound, 404, 'Session does not exist')
|
||||||
.errorResponse(SyntaxError, 400, 'Malformed or non-JSON session data.')
|
.errorResponse(SyntaxError, 400, 'Malformed or non-JSON session data.')
|
||||||
|
@ -68,10 +61,7 @@
|
||||||
api.destroy(req.urlParameters.sid);
|
api.destroy(req.urlParameters.sid);
|
||||||
res.status(204);
|
res.status(204);
|
||||||
})
|
})
|
||||||
.pathParam('sid', {
|
.pathParam('sid', {type: sessionId})
|
||||||
description: 'Session ID',
|
|
||||||
type: 'string'
|
|
||||||
})
|
|
||||||
.errorResponse(errors.SessionNotFound, 404, 'Session does not exist')
|
.errorResponse(errors.SessionNotFound, 404, 'Session does not exist')
|
||||||
.summary('Delete session')
|
.summary('Delete session')
|
||||||
.notes('Removes the session with the given sid from the database.');
|
.notes('Removes the session with the given sid from the database.');
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
var _ = require('underscore'),
|
var _ = require('underscore'),
|
||||||
|
joi = require('joi'),
|
||||||
internal = require('internal'),
|
internal = require('internal'),
|
||||||
arangodb = require('org/arangodb'),
|
arangodb = require('org/arangodb'),
|
||||||
db = arangodb.db,
|
db = arangodb.db,
|
||||||
|
@ -11,15 +12,15 @@
|
||||||
Foxx = require('org/arangodb/foxx'),
|
Foxx = require('org/arangodb/foxx'),
|
||||||
errors = require('./errors'),
|
errors = require('./errors'),
|
||||||
cfg = applicationContext.configuration,
|
cfg = applicationContext.configuration,
|
||||||
Session = Foxx.Model.extend({}, {
|
Session = Foxx.Model.extend({
|
||||||
attributes: {
|
schema: {
|
||||||
_key: {type: 'string', required: true},
|
_key: joi.string().required(),
|
||||||
uid: {type: 'string', required: false},
|
uid: joi.string().optional(),
|
||||||
sessionData: {type: 'object', required: true},
|
sessionData: joi.object().required(),
|
||||||
userData: {type: 'object', required: true},
|
userData: joi.object().required(),
|
||||||
created: {type: 'integer', required: true},
|
created: joi.number().integer().required(),
|
||||||
lastAccess: {type: 'integer', required: true},
|
lastAccess: joi.number().integer().required(),
|
||||||
lastUpdate: {type: 'integer', required: true}
|
lastUpdate: joi.number().integer().required()
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
sessions = new Foxx.Repository(
|
sessions = new Foxx.Repository(
|
||||||
|
|
|
@ -3,15 +3,16 @@
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
var _ = require('underscore'),
|
var _ = require('underscore'),
|
||||||
|
joi = require('joi'),
|
||||||
arangodb = require('org/arangodb'),
|
arangodb = require('org/arangodb'),
|
||||||
db = arangodb.db,
|
db = arangodb.db,
|
||||||
Foxx = require('org/arangodb/foxx'),
|
Foxx = require('org/arangodb/foxx'),
|
||||||
errors = require('./errors'),
|
errors = require('./errors'),
|
||||||
User = Foxx.Model.extend({}, {
|
User = Foxx.Model.extend({
|
||||||
attributes: {
|
schema: {
|
||||||
user: {type: 'string', required: true},
|
user: joi.string().required(),
|
||||||
authData: {type: 'object', required: true},
|
authData: joi.object().required(),
|
||||||
userData: {type: 'object', required: true}
|
userData: joi.object().required()
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
users = new Foxx.Repository(
|
users = new Foxx.Repository(
|
||||||
|
|
Loading…
Reference in New Issue