-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.js
72 lines (57 loc) · 3.48 KB
/
routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict';
var express = require('express');
var config = require('config');
var Mailer = require('./libs/Mailer');
var mailer = new Mailer(config.get('mail'));
var UsersModel = require('./models/UsersModel');
var SessionsModel = require('./models/SessionsModel');
var DevicesModel = require('./models/DevicesModel');
var MyDevicesModel = require('./models/MyDevicesModel');
var usersModel = new UsersModel();
var sessionsModel = new SessionsModel();
var devicesModel = new DevicesModel();
var myDevicesModel = new MyDevicesModel();
var UsersController = require('./controllers/UsersController');
var Oauth2Controller = require('./controllers/Oauth2Controller');
var ProfileController = require('./controllers/ProfileController');
var DevicesController = require('./controllers/DevicesController');
var MyDevicesController = require('./controllers/MyDevicesController');
var usersController = new UsersController(mailer, usersModel);
var oauth2Controller = new Oauth2Controller(sessionsModel);
var profileController = new ProfileController(mailer, usersModel);
var devicesController = new DevicesController(devicesModel);
var myDevicesController = new MyDevicesController(myDevicesModel);
var sessionChecker = require('./middlewares/sessionChecker');
var checkSession = sessionChecker(sessionsModel);
var router = express.Router({
caseSensitive: false,
strict : true
});
// Users
router.post('/users' , usersController.create);
router.put( '/users/activate/:token', usersController.activate);
// OAuth2
router.post('/oauth2/authorization', oauth2Controller.getToken);
// Profile
router.get( '/profile' , checkSession, profileController.get);
router.put( '/profile' , checkSession, profileController.update);
router.put( '/profile/password' , checkSession, profileController.updatePassword);
router.post('/profile/email-update-request', checkSession, profileController.requestEmailUpdate);
router.put( '/profile/email/:token' , profileController.updateEmail);
// Devices
router.post( '/devices' , checkSession, devicesController.register);
router.delete('/devices/:deviceId', checkSession, devicesController.delete);
// User Devices
router.post( '/my-devices' , checkSession, myDevicesController.link);
router.get( '/my-devices' , checkSession, myDevicesController.list);
router.delete('/my-devices/:linkageId' , checkSession, myDevicesController.unlink);
router.put( '/my-devices/:linkageId/password' , checkSession, myDevicesController.updatePassword);
router.put( '/my-devices/:linkageId/name' , checkSession, myDevicesController.updateName);
router.post( '/my-devices/:linkageId/settings' , checkSession, myDevicesController.addSetting);
router.get( '/my-devices/:linkageId/settings' , checkSession, myDevicesController.getSettings);
router.put( '/my-devices/:linkageId/settings/:settingId/activate' , checkSession, myDevicesController.activateSetting);
router.put( '/my-devices/:linkageId/settings/:settingId/deactivate', checkSession, myDevicesController.deactivateSetting);
router.delete('/my-devices/:linkageId/settings/:settingId' , checkSession, myDevicesController.deleteSetting);
// Prototype
router.get('/config', myDevicesController.config);
module.exports = router;