Guest User

Untitled

a guest
Nov 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. Error: Connection lost: The server closed the connection.
  2. at Protocol.end (/var/www/html/node_modules/mysql/lib/protocol/Protocol.js:113:13)
  3. at Socket.<anonymous> (/var/www/html/node_modules/mysql/lib/Connection.js:109:28)
  4. at Socket.EventEmitter.emit (events.js:117:20)
  5. at _stream_readable.js:920:16
  6. at process._tickCallback (node.js:415:13)
  7.  
  8. var http = require('http');
  9. var fs = require('fs');
  10. var url = require('url');
  11. var qs = require('querystring');
  12. var controller = require('./controller.js');
  13.  
  14. global.dbOptions = {
  15. host : 'localhost',
  16. user : 'root',
  17. password : 'pass',
  18. database : 'db'
  19. }
  20.  
  21.  
  22. function server_handler(req, res){
  23. var urlObject = url.parse(req.url, true);
  24. var path = urlObject.pathname;
  25. if(req.method=='GET'){
  26. var getParams = urlObject.query;
  27. controller.handler(req, res, path, getParams);
  28. } else if(req.method=='POST'){
  29. var pdata = '';
  30. req.on('data', function(chunk){
  31. pdata += chunk;
  32. });
  33. req.on('end', function(){
  34. var postParams = qs.parse(pdata);
  35. controller.handler(req, res, path, postParams)
  36. })
  37. }
  38.  
  39. }
  40.  
  41. var s = http.createServer(server_handler)
  42.  
  43. s.listen(8080);
  44.  
  45. exports.handler = function(req, res, path, params) {
  46. try {
  47. var view = require('.'+path);
  48. try{
  49. params['ip'] = req.connection.remoteAddress;
  50. callback = function(err, result){
  51. if(err != null){
  52. res.writeHead(500, {"Content-Type" : "application/json"});
  53. res.end(JSON.stringify({error: "true", data: result }));
  54. }
  55. res.writeHead(200, {"Content-Type" : "application/json"});
  56. res.end(JSON.stringify({error: "false", data: result }));
  57. }
  58. view.execute(params, callback);
  59. } catch (err) {
  60. res.writeHead(500, {"Content-Type" : "application/json"});
  61. res.end(JSON.stringify({error: "true", data: err.message }));
  62. }
  63. } catch (err) {
  64. res.writeHead(404, {'Content-Type': 'application/json'});
  65. res.end(JSON.stringify({error : "true", data: 'URL not found1.'}));
  66. }
  67. }
  68.  
  69. var fn = require('./../../../includes/functions.js');
  70. var mysql = require('mysql');
  71. var md5 = require("md5");
  72. exports.execute = function(params, callback) {
  73. if(params['id']!=undefined && params['pass']!=undefined && params['token']!=undefined){
  74. fn.verifyCustomerToken(params, callback, function(){
  75. var id = fn.mysql_real_escape_string(params['id']);
  76. if(fn.validateString(params['pass'])==false){
  77. callback('true', 'Invalid password.')
  78. } else {
  79. var connection = mysql.createConnection(global['dbOptions']);
  80. connection.connect();
  81. pass = md5(params['pass']);
  82. connection.query("update customer set password ='"+pass+"' where id = '"+id+"' limit 1", function (error, results, fields) {
  83. if(error==null){
  84. callback(null, 'Password updated successfully.')
  85. } else {
  86. callback('true', 'Some error occured while updating password.')
  87. }
  88. connection.end();
  89. });
  90.  
  91. }
  92. })
  93.  
  94. } else {
  95. callback('true', 'Invalid parameteres.');
  96. }
  97. }
Add Comment
Please, Sign In to add comment