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

cantina-app-users

v4.1.2

Published

Drop-in users system for Cantina apps

Downloads

10

Readme

cantina-app-users

Provides a basic, extensible user system for a cantina application. Includes the user model (with an extensible default schema), authentication, and default email templates for basic user account-related emails.

Table of Contents

Usage

Most of the provided defaults are easily overridden via configuration (etc) or application hooks (app.hook). Default email templates can be overridden by providing an alternative template having the same name.

Default Schema

Provides the default user schema.

Extending

module.exports = function (app) {
  app.Schema.extend(app.schemas.user, {
    properties: {
      someprop: {
      type: 'string',
      default: '',
      required: true
      }
    }
  });
};

Default Admin User

Provides the default admin user, Web Team [email protected], with password "admin".

Configuring

# In etc/app/users.yml
admin:
  attributes:
    username: webteam
    password: ryd9ebyz

Schemas

Provides schemas for cantina-models

See cantina-models-schemas for details.

Authentication

Provides a standard implementation of the functionality required by cantina-auth, as well as session management.

Example

module.exports = function (app) {
  var controller = app.controller();

  controller.post('/login', function (req, res, next) {
    if (!req.body) {
        return next(new Error('Invalid post data'));
      }
      if (!req.body.email || !req.body.pass) {
        res.formError('login', 'Email and password are both required.');
        return next();
      }

      app.collections.users.findByAuth(req.body.email.trim(), req.body.pass, function (err) {
        if (err) {
          res.formError('login', err.message);
          return next();
        }
        res.redirect('/');
      });
  }

  controller.post('/logout', function (req, res, next) {
    app.auth.logOut(req, function (err) {
      if (err) return res.renderError(err);
      res.redirect('/login');
    });
  });

  return controller;
};
module.exports = function (app) {
  app.hook('model:destroy:user', function (user, next) {

    // Kill the user's active sessions
    app.auth.killSession(user, next);
  });
};

Email

Provides templates and hooks for cantina-email user account related emails.

Templates

Provides defaults for:

  • users/account_confirm
  • users/email_confirm
  • users/account_invitation
  • users/password_reset

Your application may override any of these by providing its own template with the same name.

Hooks

Adds a hook to email:send:before for the email templates above. The hook will perform the following:

  • Generate an expiring token
    • prefix: Defaults to "password-reset" for users/password_reset template, "account" for all others. Your application may override this by setting vars.preset in the app.email.send vars.
    • expire: Defaults to 24 hours for users/password_reset template, 7 days for all others. Your application may override this by setting vars.expire in the app.email.send vars.
  • Add vars.app
    • The result of app.conf.get('app').
    • Required for the default email templates:
      • app.title
      • app.email
    • Your application may override this by setting vars.app in the app.email.send vars.
  • Add vars.url
    • A url build of the conf's app.protocol, app.domain, and a pathname appended with the generated token. The pathnames are:
      • /forgot/{token}
      • /account-confirm/{token}
      • /email-confirm/{token}
      • /account-invitation/{token} Your application may override this by setting vars.pathname or vars.url in the app.email.send vars.

API Reference

app.collections.users

Exentded namespace for user models

app.collections.users.findByAuth(email, password, cb)

Load user with matching email from the database and verifies password. Returns a sanitized user model, if match is found.

app.auth

Namespace for authentication-related API

app.auth.logIn(user, req, res, next)

Invokes req.logIn and adds the req.sessionID to a set of sessionIDs for the user in redis.

app.auth.setPassword(user, password, cb)

Sets the auth property on the user model to be a bcrypt hash of the password

app.auth.checkPassword(user, password, cb)

Checks the password against the user's auth property using bcrypt.compare

app.auth.killSession(user, sessionID, cb)

Destroys the session and removes the sessionID from user's set in redis.

app.auth.killAllSessions(user, cb)

Loads the user's sessionIDs from redis and destroys each. Deletes the user's set of sessionIDs in redis.

app.auth.logOut(req, cb)

Invokes req.logOut and app.auth.killSession for the authenticated user

app.serializeUser(user, cb)

Implements user serialization for cantina-auth. Returns the user model's id property.

app.deserializeUser(id, cb)

Implements user deserialization for cantina-auth. Loads and returns the user with matching id in app.collections.user.

app.verifyTwitterUser(token, tokenSecret, profile, done)

Implements account verification for cantina-auth-twitter. Creates or updates the existing user account with matching emailon app.collections.user.

app.verifyFacebookUser(token, tokenSecret, profile, done)

Implements account verification for cantina-auth-facebook. Creates or updates the existing user account with matching emailon app.collections.user.


Developed by Terra Eclipse

Terra Eclipse, Inc. is a nationally recognized political technology and strategy firm located in Santa Cruz, CA and Washington, D.C.