Added new custom fields for GPG keys
This commit is contained in:
parent
b7e943d90e
commit
3b6fd47a61
10 changed files with 78 additions and 2 deletions
|
@ -12,6 +12,8 @@ module.exports.grouped = ['radio', 'checkbox', 'dropdown'];
|
|||
module.exports.types = {
|
||||
text: 'Text',
|
||||
website: 'Website',
|
||||
longtext: 'Multi-line text',
|
||||
gpg: 'GPG Public Key',
|
||||
number: 'Number',
|
||||
radio: 'Radio Buttons',
|
||||
checkbox: 'Checkboxes',
|
||||
|
@ -26,6 +28,8 @@ module.exports.types = {
|
|||
module.exports.genericTypes = {
|
||||
text: 'string',
|
||||
website: 'string',
|
||||
longtext: 'textarea',
|
||||
gpg: 'textarea',
|
||||
number: 'number',
|
||||
'date-us': 'date',
|
||||
'date-eur': 'date',
|
||||
|
@ -264,7 +268,7 @@ function addCustomField(listId, name, defaultValue, type, group, visible, callba
|
|||
|
||||
let column = null;
|
||||
let key = slugify('merge ' + name, '_').toUpperCase();
|
||||
let allowedTypes = ['text', 'number', 'radio', 'checkbox', 'dropdown', 'date-us', 'date-eur', 'birthday-us', 'birthday-eur', 'website', 'option'];
|
||||
let allowedTypes = ['text', 'number', 'radio', 'checkbox', 'dropdown', 'date-us', 'date-eur', 'birthday-us', 'birthday-eur', 'website', 'option', 'gpg', 'longtext'];
|
||||
|
||||
if (allowedTypes.indexOf(type) < 0) {
|
||||
return callback(new Error('Unknown column type ' + type));
|
||||
|
@ -308,7 +312,11 @@ function addCustomField(listId, name, defaultValue, type, group, visible, callba
|
|||
switch (type) {
|
||||
case 'text':
|
||||
case 'website':
|
||||
query = 'ALTER TABLE `subscription__' + listId + '` ADD COLUMN `' + column + '` VARCHAR(255) DEFAULT NULL';
|
||||
query = 'ALTER TABLE `subscription__' + listId + '` ADD COLUMN `' + column + '` VARCHAR(255) DEFAULT NULL, ADD INDEX (' + column + ')';
|
||||
break;
|
||||
case 'gpg':
|
||||
case 'longtext':
|
||||
query = 'ALTER TABLE `subscription__' + listId + '` ADD COLUMN `' + column + '` TEXT DEFAULT NULL';
|
||||
break;
|
||||
case 'number':
|
||||
query = 'ALTER TABLE `subscription__' + listId + '` ADD COLUMN `' + column + '` INT(11) DEFAULT NULL, ADD INDEX (' + column + ')';
|
||||
|
@ -358,6 +366,8 @@ module.exports.getRow = (fieldList, values, useDate, showAll) => {
|
|||
switch (field.type) {
|
||||
case 'text':
|
||||
case 'website':
|
||||
case 'gpg':
|
||||
case 'longtext':
|
||||
{
|
||||
let item = {
|
||||
type: field.type,
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
"mysql": "^2.10.2",
|
||||
"nodemailer": "^2.3.2",
|
||||
"npmlog": "^2.0.3",
|
||||
"openpgp": "^2.2.1",
|
||||
"passport": "^0.3.2",
|
||||
"passport-local": "^1.0.0",
|
||||
"request": "^2.71.0",
|
||||
|
|
|
@ -31,3 +31,7 @@ div.jumbotron{
|
|||
.code-editor {
|
||||
height: 400px;
|
||||
}
|
||||
|
||||
.gpg-text {
|
||||
font-family: monospace;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
let openpgp = require('openpgp');
|
||||
let passport = require('../lib/passport');
|
||||
let express = require('express');
|
||||
let router = new express.Router();
|
||||
|
@ -156,6 +157,26 @@ router.post('/ajax/:id', (req, res) => {
|
|||
].concat(fields.getRow(fieldList, row).map(cRow => {
|
||||
if (cRow.type === 'number') {
|
||||
return htmlescape(cRow.value && humanize.numberFormat(cRow.value, 0) || '');
|
||||
} else if (cRow.type === 'longtext') {
|
||||
let value = (cRow.value || '');
|
||||
if (value.length > 50) {
|
||||
value = value.substr(0, 47).trim() + '…';
|
||||
}
|
||||
return htmlescape(value);
|
||||
} else if (cRow.type === 'gpg') {
|
||||
let value = (cRow.value || '').trim();
|
||||
try {
|
||||
value = openpgp.key.readArmored(value);
|
||||
if (value) {
|
||||
value = value.keys && value.keys[0] && value.keys[0].primaryKey.fingerprint;
|
||||
if (value) {
|
||||
value = '0x' + value.substr(-16).toUpperCase();
|
||||
}
|
||||
}
|
||||
} catch (E) {
|
||||
value = 'parse error';
|
||||
}
|
||||
return htmlescape(value || '');
|
||||
} else {
|
||||
return htmlescape(cRow.value || '');
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
<option value="text" {{#if selectedText}} selected {{/if}}>Text</option>
|
||||
<option value="number" {{#if selectedNumber}} selected {{/if}}>Number</option>
|
||||
<option value="website" {{#if selectedWebsite}} selected {{/if}}>Website</option>
|
||||
<option value="gpg" {{#if selectedGpg}} selected {{/if}}>GPG Public Key</option>
|
||||
<option value="longtext" {{#if selectedLongtext}} selected {{/if}}>Multi-line text</option>
|
||||
<optgroup label="Date">
|
||||
<option value="date-us" {{#if selectedDateUs}} selected {{/if}}>Date (MM/DD/YYYY)</option>
|
||||
<option value="date-eur" {{#if selectedDateEur}} selected {{/if}}>Date (DD/MM/YYYY)</option>
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
<option value="text" {{#if selectedText}} selected {{/if}}>Text</option>
|
||||
<option value="number" {{#if selectedNumber}} selected {{/if}}>Number</option>
|
||||
<option value="website" {{#if selectedWebsite}} selected {{/if}}>Website</option>
|
||||
<option value="gpg" {{#if selectedGpg}} selected {{/if}}>GPG Public Key</option>
|
||||
<option value="longtext" {{#if selectedLongtext}} selected {{/if}}>Multi-line text</option>
|
||||
<optgroup label="Date">
|
||||
<option value="date-us" {{#if selectedDateUs}} selected {{/if}}>Date (MM/DD/YYYY)</option>
|
||||
<option value="date-eur" {{#if selectedDateEur}} selected {{/if}}>Date (DD/MM/YYYY)</option>
|
||||
|
|
|
@ -50,6 +50,15 @@
|
|||
<input type="url" class="form-control" name="{{column}}" value="{{value}}">
|
||||
{{/if}}
|
||||
|
||||
{{#if typeLongtext}}
|
||||
<textarea class="form-control" rows="3" name="{{column}}">{{value}}</textarea>
|
||||
{{/if}}
|
||||
|
||||
{{#if typeGpg}}
|
||||
<textarea class="form-control gpg-text" rows="3" name="{{column}}">{{value}}</textarea>
|
||||
<span class="help-block">Insert a GPG public key that will be used to encrypt messages sent this subscriber</span>
|
||||
{{/if}}
|
||||
|
||||
{{#if typeDateUs}}
|
||||
<div class="input-group date fm-date-us">
|
||||
<input type="text" class="form-control" name="{{column}}" placeholder="MM/DD/YYYY" value="{{value}}"><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
|
||||
|
|
|
@ -63,6 +63,15 @@
|
|||
<input type="url" class="form-control" name="{{column}}" value="{{value}}">
|
||||
{{/if}}
|
||||
|
||||
{{#if typeLongtext}}
|
||||
<textarea class="form-control" rows="3" name="{{column}}">{{value}}</textarea>
|
||||
{{/if}}
|
||||
|
||||
{{#if typeGpg}}
|
||||
<textarea class="form-control gpg-text" rows="3" name="{{column}}">{{value}}</textarea>
|
||||
<span class="help-block">Insert a GPG public key that will be used to encrypt messages sent this subscriber</span>
|
||||
{{/if}}
|
||||
|
||||
{{#if typeDateUs}}
|
||||
<div class="input-group date fm-date-us">
|
||||
<input type="text" class="form-control" name="{{column}}" placeholder="MM/DD/YYYY" value="{{value}}"><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
|
||||
|
|
|
@ -36,6 +36,15 @@
|
|||
<input type="url" class="form-control" name="{{column}}" value="{{value}}">
|
||||
{{/if}}
|
||||
|
||||
{{#if typeLongtext}}
|
||||
<textarea class="form-control" rows="3" name="{{column}}">{{value}}</textarea>
|
||||
{{/if}}
|
||||
|
||||
{{#if typeGpg}}
|
||||
<textarea class="form-control gpg-text" rows="3" name="{{column}}">{{value}}</textarea>
|
||||
<span class="help-block">Insert your GPG public key here to encrypt messages sent to your address</span>
|
||||
{{/if}}
|
||||
|
||||
{{#if typeDateUs}}
|
||||
<div class="input-group date fm-date-us">
|
||||
<input type="text" class="form-control" name="{{column}}" placeholder="MM/DD/YYYY" value="{{value}}"><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
|
||||
|
|
|
@ -33,6 +33,15 @@
|
|||
<input type="url" class="form-control" name="{{column}}" value="{{value}}">
|
||||
{{/if}}
|
||||
|
||||
{{#if typeLongtext}}
|
||||
<textarea class="form-control" rows="3" name="{{column}}">{{value}}</textarea>
|
||||
{{/if}}
|
||||
|
||||
{{#if typeGpg}}
|
||||
<textarea class="form-control gpg-text" rows="3" name="{{column}}">{{value}}</textarea>
|
||||
<span class="help-block">Insert your GPG public key here to encrypt messages sent to your address</span>
|
||||
{{/if}}
|
||||
|
||||
{{#if typeDateUs}}
|
||||
<div class="input-group date fm-date-us">
|
||||
<input type="text" class="form-control" name="{{column}}" placeholder="MM/DD/YYYY" value="{{value}}"><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue