Skip to content

Commit

Permalink
add events
Browse files Browse the repository at this point in the history
  • Loading branch information
zemirco committed Jul 1, 2014
1 parent 6828f8c commit 8f5b9d4
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions index.js
@@ -1,5 +1,7 @@

var path = require('path');
var events = require('events');
var util = require('util');
var express = require('express');
var uuid = require('node-uuid');
var pwd = require('couch-pwd');
Expand Down Expand Up @@ -27,6 +29,9 @@ var ForgotPassword = module.exports = function(config, adapter) {

if (!(this instanceof ForgotPassword)) return new ForgotPassword(config, adapter);

// call super constructor function
events.EventEmitter.call(this);

this.config = config;
this.adapter = adapter;

Expand All @@ -49,6 +54,8 @@ var ForgotPassword = module.exports = function(config, adapter) {

};

util.inherits(ForgotPassword, events.EventEmitter);



/**
Expand Down Expand Up @@ -85,6 +92,7 @@ ForgotPassword.prototype.getForgot = function(req, res, next) {
ForgotPassword.prototype.postForgot = function(req, res, next) {
var config = this.config;
var adapter = this.adapter;
var that = this;

var email = req.body.email;

Expand Down Expand Up @@ -151,6 +159,9 @@ ForgotPassword.prototype.postForgot = function(req, res, next) {
mail.forgot(user.name, user.email, token, function(err, response) {
if (err) return next(err);

// emit event
that.emit('forgot::sent', user, res);

// send only JSON when REST is active
if (config.rest) return res.send(204);

Expand Down Expand Up @@ -249,6 +260,7 @@ ForgotPassword.prototype.getToken = function(req, res, next) {
ForgotPassword.prototype.postToken = function(req, res, next) {
var config = this.config;
var adapter = this.adapter;
var that = this;

var password = req.body.password;
var token = req.params.token;
Expand Down Expand Up @@ -334,6 +346,9 @@ ForgotPassword.prototype.postToken = function(req, res, next) {
adapter.update(user, function(err, user) {
if (err) return next(err);

// emit event
that.emit('forgot::success', user, res);

// send only JSON when REST is active
if (config.rest) return res.send(204);

Expand Down

0 comments on commit 8f5b9d4

Please sign in to comment.