mirror of
				https://github.com/KevinMidboe/zoff.git
				synced 2025-10-29 18:00:23 +00:00 
			
		
		
		
	Fix for non-selectable API-code
- Fixed issue where API-code couldn't be selected - Added view to see if the api-key has been fetched or not - Added option to try again with the same email if the previous link has timed-out after a day
This commit is contained in:
		| @@ -893,43 +893,50 @@ try { | ||||
|             var id = crypto.createHash('sha256').update(uniqid()).digest('base64'); | ||||
|             var uniqid_link = crypto.createHash('sha256').update(uniqid()).digest('hex'); | ||||
|             token_db.collection("api_token").find({name: name}, function(err, results_find) { | ||||
|                 var token = ""; | ||||
|                 if(results_find.length > 0) { | ||||
|                     res.send("failed"); | ||||
|                     return; | ||||
|                     token = results_find[0].token; | ||||
|                 } | ||||
|                 token_db.collection("api_token").insert({name: name, token: id, usage: 0, active: false, limit: 100}, 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); | ||||
|                 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)) { | ||||
|                         token_db.collection("api_token").insert({name: name, token: id, usage: 0, active: false, limit: 100}, 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); | ||||
|  | ||||
|                        transporter.verify(function(error, success) { | ||||
|                            if (error) { | ||||
|                                token_db.collection("api_links").remove({id: uniqid_link}, function(e,d) { | ||||
|                                    res.send("failed"); | ||||
|                                    return; | ||||
|                                }) | ||||
|                            } else { | ||||
|                                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 msg = { | ||||
|                                    from: mailconfig.from, | ||||
|                                    to: name, | ||||
|                                    subject: subject, | ||||
|                                    text: message, | ||||
|                                    html: message, | ||||
|                                } | ||||
|                                transporter.sendMail(msg, (error, info) => { | ||||
|                                transporter.verify(function(error, success) { | ||||
|                                    if (error) { | ||||
|                                        res.status(400).send("failed"); | ||||
|                                        transporter.close(); | ||||
|                                        return; | ||||
|                                        token_db.collection("api_links").remove({id: uniqid_link}, function(e,d) { | ||||
|                                            res.send("failed"); | ||||
|                                            return; | ||||
|                                        }) | ||||
|                                    } else { | ||||
|                                        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 msg = { | ||||
|                                            from: mailconfig.from, | ||||
|                                            to: name, | ||||
|                                            subject: subject, | ||||
|                                            text: message, | ||||
|                                            html: message, | ||||
|                                        } | ||||
|                                        transporter.sendMail(msg, (error, info) => { | ||||
|                                            if (error) { | ||||
|                                                res.status(400).send("failed"); | ||||
|                                                transporter.close(); | ||||
|                                                return; | ||||
|                                            } | ||||
|                                            res.status(200).send("success"); | ||||
|                                            transporter.close(); | ||||
|                                            return; | ||||
|                                        }); | ||||
|                                    } | ||||
|                                    res.status(200).send("success"); | ||||
|                                    transporter.close(); | ||||
|                                    return; | ||||
|                                }); | ||||
|                            } | ||||
|                        }); | ||||
|                    }) | ||||
|                            }) | ||||
|                         }); | ||||
|                     } else { | ||||
|                         res.send("failed"); | ||||
|                         return; | ||||
|                     } | ||||
|                 }); | ||||
|             }) | ||||
|         } else { | ||||
|   | ||||
| @@ -51,7 +51,7 @@ router.route('/api/apply/:id').get(function(req,res) { | ||||
|     token_db.collection('api_links').find({id: id}, function(err, result) { | ||||
|         if(result.length == 1) { | ||||
|             token_db.collection('api_links').remove({id: id}, function(e,d) { | ||||
|                 token_db.collection('api_token').update({id: result[0].token}, {$set: {active: true }}, function(e,d) { | ||||
|                 token_db.collection('api_token').update({token: result[0].token}, {$set: {active: true}}, function(e,d) { | ||||
|                     var data = { | ||||
|                         year: year, | ||||
|                         javascript_file: "token.min.js", | ||||
|   | ||||
		Reference in New Issue
	
	Block a user