module.exports = { 'connection': { 'host': '127.0.0.1', // local or ip adress . 'user': 'root', // mysql user name 'password': 'password', // password 'database': 'dbname'// database name . }, 'database': 'dbname',};
CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(100) DEFAULT NULL, `password` varchar(100) DEFAULT NULL, `verification` tinyint(1) DEFAULT '0', `code` varchar(100) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
app.post("/email",isLoggedIn,function(req,res){console.log(req.body); var row=[]; var code=""; var email=""; connection.query('select * from users where id = ?',[req.user.id], function (err, rows) { if (err) { console.log(err); } else { if (rows.length) { for (var i = 0, len = rows.length; i < len; i++) { //query den gelen bütün parametreleri rows sınıfına ekliyoruz . row[i] = rows[i]; code = bcrypt.hashSync(rows[i].username, null, null) console.log(rows[i].username); console.log(code); email = rows[i].username; } } console.log(row); } connection.query("UPDATE users SET code='"+code+"' WHERE id='"+req.user.id+"'"); sendMail(email,code); }); });
function sendMail(mail_adress,code){var mail=mail_adress; var code=code; console.log(mail,code); var nodemailer = require('nodemailer'); var transporter = nodemailer.createTransport({ service: 'gmail', auth: { user: '[email protected]', pass: 'your_gmail_pass' } }); var mailOptions = { from: 'from_gmail_adres', to: mail, subject: 'click this button', text: 'That was easy!', html: " <a href='http://127.0.0.1/verification/"+code+"'> http://127.0.0.1/verification/"+code+" </a> " }; transporter.sendMail(mailOptions, function(error, info){ if (error) { console.log(error); } else { console.log('Email sent: ' + info.response); } });
}
app.get("/verification/:code",isLoggedIn,function(req,res){ console.log("burda"); var code = req.params.code; var row = [];connection.query('select * from users where code = ?',[code], function (err, rows) { if (err) { console.log(err); } else { if (rows.length) { connection.query("UPDATE users set verification = '"+1+"' where code = '"+code+"'"); res.redirect("/"); } else{ res.redirect("/error"); } console.log(row); } }); });
$(document).ready(function(){ $('#sendemail').click(function(){ $("#sendemail").hide(); var data = {}; data.userID = '<%=rows.id%>'; $.ajax({ url: '/email', type: 'POST', contentType: 'application/json', data: JSON.stringify(data), success: function(data) { console.log(data); } }); }); });nodejs-send-verification-mail-project-with-gmail-and-mysql's People
Recommend Projects
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
TensorFlow
An Open Source Machine Learning Framework for Everyone
Django
The Web framework for perfectionists with deadlines.
Laravel
A PHP framework for web artisans
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
Recommend Topics
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
web
Some thing interesting about web. New door for the world.
server
A server is a program made to process requests and deliver data to clients.
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Visualization
Some thing interesting about visualization, use data art
Game
Some thing interesting about game, make everyone happy.
Recommend Org
We are working to build community through open source technology. NB: members must have two-factor auth.
Microsoft
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba
Alibaba Open Source for everyone
D3
Data-Driven Documents codes.
Tencent
China tencent open source team.