express-forgot-password
Advanced tools
Comparing version 0.1.0 to 0.2.0
var express = require('express') | ||
, ForgotPassword = require('./model')(mongoose) | ||
module.exports = function(config, mongoose, Customer){ | ||
module.exports = function(ForgotPassword, Customer){ | ||
@@ -6,0 +5,0 @@ var app = express() |
28
index.js
module.exports = function(opts){ | ||
if (! opts.mongoose ) { | ||
throw "express-forgot-password needs a connected mongoose object" | ||
} | ||
if (! opts.mailFrom ) | ||
opts.mailFrom = "No Reply <noreply@noreply.com>" | ||
if (! opts.resetMailSubject ) | ||
opts.resetMailSubject = "Reset your password" | ||
if (! opts.mailConfig ) | ||
throw "express-forgot-password needs config for nodemailer" | ||
if (! opts.resetMailContent ) | ||
throw "express-forgot-password needs a function resetMailContent(user, token) to supply the email body" | ||
var model = require('./model')( | ||
opts.mongoose | ||
, opts.mailConfig | ||
, opts.mailFrom | ||
, opts.resetMailSubject | ||
, opts.resetMailContent | ||
) | ||
return { | ||
app : require('./app')(opts.config, opts.mongoose, opts.user) | ||
app : require('./app')(model, opts.user) | ||
} | ||
} |
23
model.js
var crypto = require('crypto') | ||
, mailer = require('nodemailer') | ||
module.exports = function(mongoose) { | ||
module.exports = function(mongoose, mailConfig, mailFrom, resetMailSubject, resetMailContent) { | ||
var Schema = mongoose.Schema | ||
@@ -23,3 +23,3 @@ | ||
if (Date.now() - forgot.sent > config.forgotpassword_expiry){ | ||
if (Date.now() - forgot.sent > (1000*60*60*12)){ | ||
return cb("Invalid Code: Expired") | ||
@@ -55,6 +55,12 @@ } | ||
console.log(">>> ForgotPassword sent:", customer.email) | ||
customer.sendEmail( | ||
"Reset your password for Hosted Strider" | ||
, 'customer-forgot-email.html' | ||
, { token : forgot.code}, cb) | ||
var emailTransport = mailer.createTransport("SMTP", mailConfig) | ||
var envelope = { | ||
from: mailFrom | ||
, to: customer.email | ||
, subject: resetMailSubject | ||
, text: resetMailContent(customer, '/reset-password?id=' + forgot.code) | ||
} | ||
emailTransport.sendMail(envelope, cb) | ||
}) | ||
@@ -65,4 +71,5 @@ | ||
var ForgotPassword = mongoose.model('ForgotPassword', ForgotPasswordSchema) | ||
return Forgot Password | ||
return ForgotPassword | ||
} |
{ | ||
"name": "express-forgot-password", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Express Forgotton Password sub-app", | ||
@@ -13,4 +13,5 @@ "main": "index.js", | ||
"express": "~3.4.0", | ||
"mongoose": "~3.6.20" | ||
"mongoose": "~3.6.20", | ||
"nodemailer": "~0.5.2" | ||
} | ||
} |
@@ -8,2 +8,4 @@ # Forgot Password Flow | ||
- User model has `.findByEmail` | ||
- config.mailConfig : nodemailer | ||
- config.name : app name | ||
@@ -14,5 +16,14 @@ ## Usage: | ||
var forgotton = require('express-forgotton-password')({ config: config, mongoose: mongoose, user : UserModel }) // Passing mongoose here _sucks_ | ||
var forgotton = require('express-forgotton-password')({ | ||
// None of this is optional :( | ||
mailConfig: config // config for nodemailer | ||
, mailFrom: "nomail" // mailer from address | ||
, mongoose: mongoose // Passing mongoose here _sucks_ | ||
, resetMailSubject : "Reset yout mysite password" | ||
, resetMailContent : function(user, token){ | ||
return "reset link: http://mysite" + token + " \n thanks" | ||
} | ||
, user : UserModel }) | ||
app.use(forgotton.app) | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
124084
127
28
3
17
+ Addednodemailer@~0.5.2
+ Addedaddressparser@0.3.2(transitive)
+ Addeddirectmail@0.1.8(transitive)
+ Addeddkim-signer@0.1.2(transitive)
+ Addedencoding@0.1.13(transitive)
+ Addedfollow-redirects@0.0.3(transitive)
+ Addedhe@0.3.6(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedmailcomposer@0.2.12(transitive)
+ Addedmimelib@0.2.19(transitive)
+ Addednodemailer@0.5.15(transitive)
+ Addedpublic-address@0.1.2(transitive)
+ Addedpunycode@1.2.4(transitive)
+ Addedrai@0.1.12(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsimplesmtp@0.3.35(transitive)
+ Addedunderscore@1.13.7(transitive)
+ Addedxoauth2@0.1.8(transitive)