Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Error: Connection lost: The server closed the connection.
- at Protocol.end (/var/www/html/node_modules/mysql/lib/protocol/Protocol.js:113:13)
- at Socket.<anonymous> (/var/www/html/node_modules/mysql/lib/Connection.js:109:28)
- at Socket.EventEmitter.emit (events.js:117:20)
- at _stream_readable.js:920:16
- at process._tickCallback (node.js:415:13)
- var http = require('http');
- var fs = require('fs');
- var url = require('url');
- var qs = require('querystring');
- var controller = require('./controller.js');
- global.dbOptions = {
- host : 'localhost',
- user : 'root',
- password : 'pass',
- database : 'db'
- }
- function server_handler(req, res){
- var urlObject = url.parse(req.url, true);
- var path = urlObject.pathname;
- if(req.method=='GET'){
- var getParams = urlObject.query;
- controller.handler(req, res, path, getParams);
- } else if(req.method=='POST'){
- var pdata = '';
- req.on('data', function(chunk){
- pdata += chunk;
- });
- req.on('end', function(){
- var postParams = qs.parse(pdata);
- controller.handler(req, res, path, postParams)
- })
- }
- }
- var s = http.createServer(server_handler)
- s.listen(8080);
- exports.handler = function(req, res, path, params) {
- try {
- var view = require('.'+path);
- try{
- params['ip'] = req.connection.remoteAddress;
- callback = function(err, result){
- if(err != null){
- res.writeHead(500, {"Content-Type" : "application/json"});
- res.end(JSON.stringify({error: "true", data: result }));
- }
- res.writeHead(200, {"Content-Type" : "application/json"});
- res.end(JSON.stringify({error: "false", data: result }));
- }
- view.execute(params, callback);
- } catch (err) {
- res.writeHead(500, {"Content-Type" : "application/json"});
- res.end(JSON.stringify({error: "true", data: err.message }));
- }
- } catch (err) {
- res.writeHead(404, {'Content-Type': 'application/json'});
- res.end(JSON.stringify({error : "true", data: 'URL not found1.'}));
- }
- }
- var fn = require('./../../../includes/functions.js');
- var mysql = require('mysql');
- var md5 = require("md5");
- exports.execute = function(params, callback) {
- if(params['id']!=undefined && params['pass']!=undefined && params['token']!=undefined){
- fn.verifyCustomerToken(params, callback, function(){
- var id = fn.mysql_real_escape_string(params['id']);
- if(fn.validateString(params['pass'])==false){
- callback('true', 'Invalid password.')
- } else {
- var connection = mysql.createConnection(global['dbOptions']);
- connection.connect();
- pass = md5(params['pass']);
- connection.query("update customer set password ='"+pass+"' where id = '"+id+"' limit 1", function (error, results, fields) {
- if(error==null){
- callback(null, 'Password updated successfully.')
- } else {
- callback('true', 'Some error occured while updating password.')
- }
- connection.end();
- });
- }
- })
- } else {
- callback('true', 'Invalid parameteres.');
- }
- }
Add Comment
Please, Sign In to add comment