121 lines
4.2 KiB
HTML
121 lines
4.2 KiB
HTML
<!DOCTYPE html>
|
|
|
|
<html>
|
|
<head>
|
|
<title>utils.js</title>
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
|
|
<link rel="stylesheet" media="all" href="docco.css" />
|
|
</head>
|
|
<body>
|
|
<div id="container">
|
|
<div id="background"></div>
|
|
|
|
<ul id="jump_to">
|
|
<li>
|
|
<a class="large" href="javascript:void(0);">Jump To …</a>
|
|
<a class="small" href="javascript:void(0);">+</a>
|
|
<div id="jump_wrapper">
|
|
<div id="jump_page">
|
|
|
|
|
|
<a class="source" href="config.html">
|
|
config.js
|
|
</a>
|
|
|
|
|
|
<a class="source" href="middleware.html">
|
|
middleware.js
|
|
</a>
|
|
|
|
|
|
<a class="source" href="seed.html">
|
|
seed.js
|
|
</a>
|
|
|
|
|
|
<a class="source" href="server.html">
|
|
server.js
|
|
</a>
|
|
|
|
|
|
<a class="source" href="utils.html">
|
|
utils.js
|
|
</a>
|
|
|
|
</div>
|
|
</li>
|
|
</ul>
|
|
|
|
<ul class="sections">
|
|
|
|
<li id="title">
|
|
<div class="annotation">
|
|
<h1>utils.js</h1>
|
|
</div>
|
|
</li>
|
|
|
|
|
|
|
|
<li id="section-1">
|
|
<div class="annotation">
|
|
|
|
<div class="pilwrap ">
|
|
<a class="pilcrow" href="#section-1">¶</a>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="content"><div class='highlight'><pre><span class="keyword">var</span> nodemailer = require(<span class="string">'nodemailer'</span>);
|
|
<span class="keyword">var</span> nconf = require(<span class="string">'nconf'</span>);
|
|
<span class="keyword">var</span> crypto = require(<span class="string">'crypto'</span>);
|
|
|
|
module.exports.sendEmail = <span class="keyword">function</span>(mailData) {
|
|
<span class="keyword">var</span> smtpTransport = nodemailer.createTransport(<span class="string">"SMTP"</span>,{
|
|
service: nconf.get(<span class="string">'SMTP_SERVICE'</span>),
|
|
auth: {
|
|
user: nconf.get(<span class="string">'SMTP_USER'</span>),
|
|
pass: nconf.get(<span class="string">'SMTP_PASS'</span>)
|
|
}
|
|
});
|
|
smtpTransport.sendMail(mailData, <span class="keyword">function</span>(error, response){
|
|
<span class="keyword">if</span>(error){
|
|
console.log(error);
|
|
}<span class="keyword">else</span>{
|
|
console.log(<span class="string">"Message sent: "</span> + response.message);
|
|
}
|
|
smtpTransport.close(); <span class="comment">// shut down the connection pool, no more messages</span>
|
|
});
|
|
}</pre></div></div>
|
|
|
|
</li>
|
|
|
|
|
|
<li id="section-2">
|
|
<div class="annotation">
|
|
|
|
<div class="pilwrap ">
|
|
<a class="pilcrow" href="#section-2">¶</a>
|
|
</div>
|
|
<p>Encryption using <a href="http://dailyjs.com/2010/12/06/node-tutorial-5/">http://dailyjs.com/2010/12/06/node-tutorial-5/</a>
|
|
Note: would use <a href="https://github.com/davidwood/node-password-hash">password-hash</a>, but we need to run
|
|
model.query().equals(), so it's a PITA to work in their verify() function</p>
|
|
|
|
</div>
|
|
|
|
<div class="content"><div class='highlight'><pre>module.exports.encryptPassword = <span class="keyword">function</span>(password, salt) {
|
|
<span class="keyword">return</span> crypto.createHmac(<span class="string">'sha1'</span>, salt).update(password).digest(<span class="string">'hex'</span>);
|
|
}
|
|
|
|
module.exports.makeSalt = <span class="keyword">function</span>() {
|
|
<span class="keyword">var</span> len = <span class="number">10</span>;
|
|
<span class="keyword">return</span> crypto.randomBytes(Math.ceil(len / <span class="number">2</span>)).toString(<span class="string">'hex'</span>).substring(<span class="number">0</span>, len);
|
|
}</pre></div></div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|