Advertisement
Guest User

Untitled

a guest
Dec 24th, 2017
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. socket.on('REGISTER', function (data)
  2.             {
  3.                 currentUser =
  4.                 {
  5.                     name:data.name,
  6.                     password:data.password,
  7.                     email:data.email,
  8.                 }
  9.                 pool.getConnection(function(err,connection)
  10.                 {
  11.                     if (!!err)
  12.                     {
  13.                             console.log('Error in connection');
  14.                     }
  15.                     connection.query("SELECT `UserID` FROM `users` ORDER BY `UserID` DESC LIMIT 1",function(error, rows,field)
  16.                     {
  17.                         if (!!error) {
  18.                             console.log('Error in the queryhj');
  19.                         }else
  20.                         {
  21.                             if ((parseInt(rows[0].UserID)) <=39) {
  22.                                 portId = portIdarray[0];
  23.                             }else if ((parseInt(rows[0].UserID)) >=40 && (parseInt(rows[0].UserID)) <=44 ){
  24.                                 portId = portIdarray[1];
  25.                             }else if ((parseInt(rows[0].UserID)) >=45 && (parseInt(rows[0].UserID)) <=47) {
  26.                                 portId = portIdarray[2];
  27.                             }else if ((parseInt(rows[0].UserID)) >=48 && (parseInt(rows[0].UserID)) <=49) {
  28.                                 portId = portIdarray[3];
  29.                             }else{
  30.                                 portId = portIdarray[4];
  31.                             }
  32.                         }
  33.                     })
  34.  
  35.                     connection.query("SELECT * FROM `users` WHERE `UserName`='"+currentUser.name+"' OR `UserEmail`='"+currentUser.email+"'",function(error, rows,field)
  36.                     {
  37.                         if (!!error)
  38.                         {
  39.                             console.log('Error in the queryhgtfh');
  40.                         }else
  41.                         {                  
  42.                             if (rows.length>0) {
  43.                                 socket.emit('RegisterUnsuccess', {
  44.                                     message : '0'
  45.                                 });
  46.                             }else
  47.                             {
  48.                                 timeLogin = 0; timeLogout = 0; timeResetMine = 0;
  49.                                 connection.query("INSERT INTO `users` (`UserID`,`UserName`,`UserPass`,`password_recover_key`,`password_recover_key_expire`,`UserEmail`,`Diamond`,`Port`,`timeLogin`,`timeLogout`,`timeResetMine`) VALUES ('"+""+"','"
  50.                                     +currentUser.name+"','"+currentUser.password+"','"+""+"','"+""+"','"+currentUser.email+"','"+1000+"','"+portId+"','"+timeLogin+"','"+timeLogout+"','"+timeResetMine+"')",function(error, result, field){
  51.                                     connection.release();
  52.                                     if(!!err) {
  53.                                         console.log('Error in the querygfvhgf');
  54.                                         socket.emit('RegisterUnsuccess', {
  55.                                             message : '1'
  56.                                         });
  57.                                     }else
  58.                                     {
  59.                                         if (result.affectedRows > 0)
  60.                                         {
  61.                                             console.log('đang ki thanh cong: '+currentUser.name);
  62.                                             let transporter = nodemailer.createTransport({
  63.                                                 service: 'gmail',
  64.                                                 auth: {
  65.                                                     user: 'aloevera.hoang@gmail.com',
  66.                                                     pass: '123456@A'
  67.                                                 }
  68.                                             });
  69.  
  70.                                             // setup email data with unicode symbols
  71.                                             let mailOptions = {
  72.                                                 from: '"Game VAE" <gameVae@demainvi.com>', // sender address
  73.                                                 to: currentUser.email, // list of receivers
  74.                                                 subject: 'Thông báo đăng kí tài khoản ✔', // Subject line
  75.                                                 text: 'Đăng kí tài khoản thành công?', // plain text body
  76.                                                 html: '<b>Bạn đã đăng kí tài khoản thành công với tên: '+currentUser.name+ ' và email:'+currentUser.email+'</b>' // html body
  77.                                             };
  78.  
  79.                                             // send mail with defined transport object
  80.                                             transporter.sendMail(mailOptions, (error, info) =>
  81.                                             {
  82.                                                 if (error) {
  83.                                                     return console.log(error);
  84.                                                 }
  85.                                                 console.log('Message %s sent: %s', info.messageId, info.response);
  86.                                             });
  87.                                             socket.emit('RegisterUnsuccess', {
  88.                                                 message : '2'
  89.  
  90.                                             });
  91.                                             //gửi user name mới dk lên cho các user khác
  92.                                            
  93.                                             io.emit('USERREGISTER',{
  94.                                                 UserName : currentUser.name,
  95.                                             });
  96.                                            
  97.                                         }
  98.                                     }
  99.                                 });
  100.                                 connection.on('error', function(err) {
  101.                                       return;
  102.                                 });
  103.                             }
  104.                         }
  105.                     })
  106.                 });
  107.  
  108.                 socket.emit('REGISTER',currentUser );
  109.                 socket.emit('USER_CONNECTED',currentUser );
  110.                 socket.broadcast.emit('USER_CONNECTED',currentUser);
  111.             });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement