-
Notifications
You must be signed in to change notification settings - Fork 1
/
library.js
108 lines (89 loc) · 3.08 KB
/
library.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"use strict";
var plugin = {},
fields = [
'website',
'location',
'birthday',
'signature',
'aboutme'
],
User = module.parent.require('./user'),
meta = module.parent.require('./meta');
plugin.init = function(params, callback) {
var app = params.router,
middleware = params.middleware,
controllers = params.controllers;
app.get('/admin/registration-profile-field', middleware.admin.buildHeader, renderAdmin);
app.get('/api/admin/registration-profile-field', renderAdmin);
callback();
};
plugin.addAdminNavigation = function(header, callback) {
header.plugins.push({
route: '/registration-profile-field',
icon: 'fa-tint',
name: 'Registration Profile Field'
});
callback(null, header);
};
plugin.customHeaders = function(headers, callback) {
var field = meta.config['registration-profile-field:field'];
headers.headers.push({
label: '[[user:' + field + ']]',
});
callback(null, headers);
};
plugin.customFields = function(params, callback) {
var field = meta.config['registration-profile-field:field'];
var users = params.users.map(function(user) {
if (!user.customRows) {
user.customRows = [];
}
user.customRows.push({value: user[field]});
return user;
});
callback(null, {users: users});
};
plugin.addCaptcha = function(params, callback) {
var field = meta.config['registration-profile-field:field'];
var comment = meta.config['registration-profile-field:description'];
console.log("Field: " + field);
if (field == "") {
callback(null, params);
return;
}
if (field === 'aboutme') {
var html = '<textarea class="form-control" name="registration-profile-field" id="registration-profile-field"></textarea><span class="help-block">' + comment + '</span>';
} else {
var html = '<input class="form-control" name="registration-profile-field" id="registration-profile-field" /><span class="help-block">' + comment + '</span>';
}
var captcha = {
label: '[[user:' + field + ']]',
html: html
};
if (params.templateData.regFormEntry && Array.isArray(params.templateData.regFormEntry)) {
params.templateData.regFormEntry.push(captcha);
} else {
params.templateData.captcha = captcha;
}
callback(null, params);
};
plugin.createUser = function(params, callback) {
var field = meta.config['registration-profile-field:field'];
var fieldData = params.data[field] || params.data['registration-profile-field'];
var userData = params.user;
if (!userData[field] && fieldData && fieldData != "")
userData[field] = fieldData;
params.user = userData
callback(null, params);
};
plugin.addToApprovalQueue = function(params, callback) {
var field = meta.config['registration-profile-field:field'];
var fieldData = params.userData['registration-profile-field'];
var userData = params.data;
userData[field] = fieldData;
callback(null, {data: userData});
};
function renderAdmin(req, res, next) {
res.render('admin/registration-profile-field', {fields:fields});
}
module.exports = plugin;