mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Signing up for the API work again
- Can use the same email more than once, the only difference is that it wont create a new key, only a new link to the key
This commit is contained in:
@@ -24,9 +24,11 @@ window.addEventListener("DOMContentLoaded", function(e) {
|
|||||||
Helper.toggleClass(".submit", "disabled");
|
Helper.toggleClass(".submit", "disabled");
|
||||||
Helper.removeClass(".full-form-token", "hide");
|
Helper.removeClass(".full-form-token", "hide");
|
||||||
var captcha_response = grecaptcha.getResponse();
|
var captcha_response = grecaptcha.getResponse();
|
||||||
|
console.log(captcha_response);
|
||||||
Helper.ajax({
|
Helper.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "/api/apply",
|
url: "/api/apply",
|
||||||
|
headers: {"Content-Type": "application/json;charset=UTF-8"},
|
||||||
data: {
|
data: {
|
||||||
origin: origin,
|
origin: origin,
|
||||||
email: email,
|
email: email,
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ var List = require(pathThumbnails + '/handlers/list.js');
|
|||||||
var Functions = require(pathThumbnails + '/handlers/functions.js');
|
var Functions = require(pathThumbnails + '/handlers/functions.js');
|
||||||
var Frontpage = require(pathThumbnails + '/handlers/frontpage.js');
|
var Frontpage = require(pathThumbnails + '/handlers/frontpage.js');
|
||||||
var Search = require(pathThumbnails + '/handlers/search.js');
|
var Search = require(pathThumbnails + '/handlers/search.js');
|
||||||
|
var uniqid = require('uniqid');
|
||||||
|
|
||||||
var toShowChannel = {
|
var toShowChannel = {
|
||||||
start: 1,
|
start: 1,
|
||||||
@@ -1254,9 +1255,22 @@ try {
|
|||||||
token_db.collection("api_links").find({token: token}, function(e, d) {
|
token_db.collection("api_links").find({token: token}, function(e, d) {
|
||||||
if(results_find.length == 0 || (d.length == 0 && results_find.length > 0 && !results_find[0].active)) {
|
if(results_find.length == 0 || (d.length == 0 && results_find.length > 0 && !results_find[0].active)) {
|
||||||
token_db.collection("api_token").insert({name: name, origin: origin, token: id, usage: 0, active: false, limit: 20}, function(err, docs){
|
token_db.collection("api_token").insert({name: name, origin: origin, token: id, usage: 0, active: false, limit: 20}, function(err, docs){
|
||||||
|
createApiLink(req, res, uniqid_link, id, name);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
createApiLink(req, res, uniqid_link, token, name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
res.send("failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function createApiLink(req, res, uniqid_link, id, name) {
|
||||||
token_db.collection("api_links").insert({id: uniqid_link, token: id, createdAt: new Date()}, function(err, docs) {
|
token_db.collection("api_links").insert({id: uniqid_link, token: id, createdAt: new Date()}, function(err, docs) {
|
||||||
let transporter = nodemailer.createTransport(mailconfig);
|
let transporter = nodemailer.createTransport(mailconfig);
|
||||||
|
|
||||||
transporter.verify(function(error, success) {
|
transporter.verify(function(error, success) {
|
||||||
if (error) {
|
if (error) {
|
||||||
token_db.collection("api_links").remove({id: uniqid_link}, function(e,d) {
|
token_db.collection("api_links").remove({id: uniqid_link}, function(e,d) {
|
||||||
@@ -1265,7 +1279,7 @@ try {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
var subject = 'ZOFF: API-key';
|
var subject = 'ZOFF: API-key';
|
||||||
var message = "Link to API-key: <a href='https://zoff.me/api/apply/" + uniqid_link + "'/>https://zoff.me/api/apply/" + uniqid_link + "</a>\n\nThis link expires in 1 day.";
|
var message = "Hello,<br><br>Thanks for signing up for the API, here is your key: <a href='https://zoff.me/api/apply/" + uniqid_link + "'/>https://zoff.me/api/apply/" + uniqid_link + "</a><br><br>This link will expire in 1 day, so please write it down.<br><br><img src='https://zoff.me/assets/images/small-square.jpg' width='100' height='100' alt='zoff-logo' />";
|
||||||
var msg = {
|
var msg = {
|
||||||
from: mailconfig.from,
|
from: mailconfig.from,
|
||||||
to: name,
|
to: name,
|
||||||
@@ -1275,7 +1289,7 @@ try {
|
|||||||
}
|
}
|
||||||
transporter.sendMail(msg, (error, info) => {
|
transporter.sendMail(msg, (error, info) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
res.status(400).send("failed");
|
res.send("failed");
|
||||||
transporter.close();
|
transporter.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1286,18 +1300,7 @@ try {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
});
|
|
||||||
} else {
|
|
||||||
res.send("failed");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
res.send("failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
router.route('/api/mail').post(recaptcha.middleware.verify, function(req, res) {
|
router.route('/api/mail').post(recaptcha.middleware.verify, function(req, res) {
|
||||||
if(req.recaptcha.error == null) {
|
if(req.recaptcha.error == null) {
|
||||||
|
|||||||
@@ -54,7 +54,23 @@ router.route('/').post(function(req, res, next){
|
|||||||
root(req, res, next);
|
root(req, res, next);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.route('/api/apply/:id').get(function(req,res) {
|
router.route('/api/apply').get(function(req, res, next) {
|
||||||
|
var data = {
|
||||||
|
year: year,
|
||||||
|
javascript_file: "token.min.js",
|
||||||
|
captcha: res.recaptcha,
|
||||||
|
analytics: analytics,
|
||||||
|
activated: false,
|
||||||
|
id: "",
|
||||||
|
correct: false,
|
||||||
|
stylesheet: "style.css",
|
||||||
|
embed: false,
|
||||||
|
og_image: "https://zoff.me/assets/images/small-square.jpg",
|
||||||
|
}
|
||||||
|
res.render('layouts/client/token', data);
|
||||||
|
});
|
||||||
|
|
||||||
|
router.route('/api/apply/:id').get(function(req, res) {
|
||||||
var id = req.params.id;
|
var id = req.params.id;
|
||||||
token_db.collection('api_links').find({id: id}, function(err, result) {
|
token_db.collection('api_links').find({id: id}, function(err, result) {
|
||||||
if(result.length == 1) {
|
if(result.length == 1) {
|
||||||
@@ -74,7 +90,7 @@ router.route('/api/apply/:id').get(function(req,res) {
|
|||||||
}
|
}
|
||||||
res.render('layouts/client/token', data);
|
res.render('layouts/client/token', data);
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
} else {
|
} else {
|
||||||
var data = {
|
var data = {
|
||||||
year: year,
|
year: year,
|
||||||
@@ -94,22 +110,6 @@ router.route('/api/apply/:id').get(function(req,res) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
router.route('/api/apply').get(function(req, res, next) {
|
|
||||||
var data = {
|
|
||||||
year: year,
|
|
||||||
javascript_file: "token.min.js",
|
|
||||||
captcha: res.recaptcha,
|
|
||||||
analytics: analytics,
|
|
||||||
activated: false,
|
|
||||||
id: "",
|
|
||||||
correct: false,
|
|
||||||
stylesheet: "style.css",
|
|
||||||
embed: false,
|
|
||||||
og_image: "https://zoff.me/assets/images/small-square.jpg",
|
|
||||||
}
|
|
||||||
res.render('layouts/client/token', data);
|
|
||||||
});
|
|
||||||
|
|
||||||
function root(req, res, next) {
|
function root(req, res, next) {
|
||||||
try{
|
try{
|
||||||
var url = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'] : req.headers.host.split(":")[0];
|
var url = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'] : req.headers.host.split(":")[0];
|
||||||
|
|||||||
Reference in New Issue
Block a user