-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary.js
More file actions
75 lines (57 loc) · 2.15 KB
/
library.js
File metadata and controls
75 lines (57 loc) · 2.15 KB
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
73
74
75
"use strict";
var controllers = require('./lib/controllers'),
plugin = {};
plugin.init = function(params, callback) {
var router = params.router,
hostMiddleware = params.middleware,
hostControllers = params.controllers;
function renderGlobal(req, res, next) {
Config.getTemplateData(function(data) {
res.render(Config.plugin.id, data);
});
}
// We create two routes for every view. One API call, and the actual route itself.
// Just add the buildHeader middleware to your route and NodeBB will take care of everything for you.
router.get('/admin/plugins/exam', hostMiddleware.admin.buildHeader, controllers.renderAdminPage);
router.get('/api/admin/plugins/exam', controllers.renderAdminPage);
// new middlewares
// get paper is unused in this version
// router.get('/exam/api/get_paper', controllers.renderGetPaper);
router.post('/exam/api/submit', controllers.renderSubmit);
// Cancelling is unneeded in this version
// router.post('/exam/api/cancel_exam', controllers.renderCancelExam);
router.get('/exam', params.middleware.buildHeader, controllers.renderExam);
callback();
};
plugin.addAdminNavigation = function(header, callback) {
header.plugins.push({
route: '/plugins/exam',
icon: 'fa-tint',
name: 'Registration Exam'
});
callback(null, header);
};
plugin.addInvitationInput = function(params, callback) {
// hook:register.build
var captcha = {
label: '[[exam:register-info]] (<a href="exam" target="_blank">[[exam:exam-link]]</a>)',
html: '<input class="form-control" name="exam-invitation-input" id="exam-invitation-input" /><br />'
};
if (params.templateData.regFormEntry && Array.isArray(params.templateData.regFormEntry)) {
params.templateData.regFormEntry.push(captcha);
} else {
params.templateData.captcha = captcha;
}
callback(null, params);
};
plugin.checkRegister = function(params, callback) {
// hook:register.check
controllers.checkRegister(params.req.body['exam-invitation-input'], (err, result) => {
if (result !== "success" || err) {
callback({source: 'registration-exam', message: '[[exam:bad-invitation-code]]'}, params);
} else {
callback(null, params);
}
})
};
module.exports = plugin;