Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- socket.on('REGISTER', function (data)
- {
- currentUser =
- {
- name:data.name,
- password:data.password,
- email:data.email,
- }
- pool.getConnection(function(err,connection)
- {
- if (!!err)
- {
- console.log('Error in connection');
- }
- connection.query("SELECT `UserID` FROM `users` ORDER BY `UserID` DESC LIMIT 1",function(error, rows,field)
- {
- if (!!error) {
- console.log('Error in the queryhj');
- }else
- {
- if ((parseInt(rows[0].UserID)) <=39) {
- portId = portIdarray[0];
- }else if ((parseInt(rows[0].UserID)) >=40 && (parseInt(rows[0].UserID)) <=44 ){
- portId = portIdarray[1];
- }else if ((parseInt(rows[0].UserID)) >=45 && (parseInt(rows[0].UserID)) <=47) {
- portId = portIdarray[2];
- }else if ((parseInt(rows[0].UserID)) >=48 && (parseInt(rows[0].UserID)) <=49) {
- portId = portIdarray[3];
- }else{
- portId = portIdarray[4];
- }
- }
- })
- connection.query("SELECT * FROM `users` WHERE `UserName`='"+currentUser.name+"' OR `UserEmail`='"+currentUser.email+"'",function(error, rows,field)
- {
- if (!!error)
- {
- console.log('Error in the queryhgtfh');
- }else
- {
- if (rows.length>0) {
- socket.emit('RegisterUnsuccess', {
- message : '0'
- });
- }else
- {
- timeLogin = 0; timeLogout = 0; timeResetMine = 0;
- connection.query("INSERT INTO `users` (`UserID`,`UserName`,`UserPass`,`password_recover_key`,`password_recover_key_expire`,`UserEmail`,`Diamond`,`Port`,`timeLogin`,`timeLogout`,`timeResetMine`) VALUES ('"+""+"','"
- +currentUser.name+"','"+currentUser.password+"','"+""+"','"+""+"','"+currentUser.email+"','"+1000+"','"+portId+"','"+timeLogin+"','"+timeLogout+"','"+timeResetMine+"')",function(error, result, field){
- connection.release();
- if(!!err) {
- console.log('Error in the querygfvhgf');
- socket.emit('RegisterUnsuccess', {
- message : '1'
- });
- }else
- {
- if (result.affectedRows > 0)
- {
- console.log('đang ki thanh cong: '+currentUser.name);
- let transporter = nodemailer.createTransport({
- service: 'gmail',
- auth: {
- user: 'aloevera.hoang@gmail.com',
- pass: '123456@A'
- }
- });
- // setup email data with unicode symbols
- let mailOptions = {
- from: '"Game VAE" <gameVae@demainvi.com>', // sender address
- to: currentUser.email, // list of receivers
- subject: 'Thông báo đăng kí tài khoản ✔', // Subject line
- text: 'Đăng kí tài khoản thành công?', // plain text body
- 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
- };
- // send mail with defined transport object
- transporter.sendMail(mailOptions, (error, info) =>
- {
- if (error) {
- return console.log(error);
- }
- console.log('Message %s sent: %s', info.messageId, info.response);
- });
- socket.emit('RegisterUnsuccess', {
- message : '2'
- });
- //gửi user name mới dk lên cho các user khác
- io.emit('USERREGISTER',{
- UserName : currentUser.name,
- });
- }
- }
- });
- connection.on('error', function(err) {
- return;
- });
- }
- }
- })
- });
- socket.emit('REGISTER',currentUser );
- socket.emit('USER_CONNECTED',currentUser );
- socket.broadcast.emit('USER_CONNECTED',currentUser);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement