npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-user-activator

v0.1.12

Published

simple user activation and password reset for express.js

Downloads

19

Readme

Express.JS User Activator

Usage

var _ = require('lodash-node');
var express = require('express'),
    bodyParser = require('body-parser'),
    app = express();

// lets assume that your model is here
// Make sure to specify following fields if you use mongoose:
//
// password_reset_code: String
// password_reset_time: Number
// activation_code: String
// password: String
// validated: Boolean
//
// Obviously password hashing is not handled here, either pre-process it yourself,
// or use mongoose middleware
//
var User = require('./models/user');

var activator = require('express-user-activator');
var config = {
  user: {},
  protocol: 'http://',
  domain: 'localhost',
  // this will be used to craft email activation links
  pathActivate: '/api/1/users/activate',
  // this will be used to craft password reset confirmation links
  pathResetPassword: '/api/1/users/forgot'
};

// method to find user
config.user.find = function (searchQuery, callback) {
  // it should return user in the callback, signature is <err, user>
  User.findOne(searchQuery, callback);
};

// method to update user
// this is used to save data into user,
// it's your responsibility to setup protection here
config.user.save = function (id, data, callback) {
  // data contains $set and $del properties, we need to perform actions based
  // on these properties
  // Lets assume we use mongodb, then the example would be as simple as this:
  // You might want to take care of error handling though, since here we just
  // spit them out
  User.update({ _id: id }, data, callback);
};

// make sure to initialize it
activator.init(config);


// handling activation
var activateRoutes = express.router(config.pathActivate)
  .get(activator.createActivate)
  .post(activator.completeActivate);

// handling password reset
var passwordResetRoutes = express.router(config.pathResetPassword)
  .get(activator.createPasswordReset)
  .post(activator.completePasswordReset);


app.use(bodyParser);
app.use(activateRoutes);
app.use(passwordResetRoutes);

Configuration

Everything in the code is pretty much commented, but here is a little helper to get you started quicker

  • user {Object}: must override
    1. find {Function} <userId, callback> signature
    2. save {Function} <userId, dataToSave, callback> signature
  • user {Object}: can override
    1. throttle {Function} <userModel, type, callback> signature

Note
User must have these fields available: password_reset_code, password_reset_time, activation_code, password

  • templates {String} - directory for templates used by smtp
  • resetExpire {Number} - duration of expiration link validity, default: 60
  • smtp: {Function|Object} - function which accepts type, lang, data, to, subject, callback and callback params and sends emails based on them, defaults: built-in mail composer
  • from: {String|Object|Null} - to be used in nodemailer's from field must override
  • emailProperty: {String} - defaults to email
  • idProperty: {String} - defaults to _id
  • createNextHandler: {Function}
  • createResponse: {Function}
  • transport: {Function} - set this if you want to use preconfigured transport setup these for generating links in the email templates
  • protocol: {String} - defaults to http://
  • domain: {String} - defaults to localhost, must override
  • pathActivate: {String} - defaults to /api/1/users/activate
  • pathResetPassword: {String} - defaults to /api/1/users/forgot
  • password_reset_subject: {String} - subject for password reset emails
  • activation_subject: {String} - subject for account activation emails
  • validatedProperty: {String} - use this to mark account as validated

Testing

To run the tests, from the root directory, run npm test.

License

Released under the MIT License.

Originally developed by Avi Deitcher

Rewritten by Vitaly Aminev