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

sql_user_manager

v0.0.2

Published

sql_user_manager is a complete drop-in middleware solution for user management. sql_user_manager is [Express](https://expressjs.com/) middleware and is compatible with any database supported by [Knex](http://knexjs.org/) (Postgres, MSSQL, MySQL, MariaDB,

Downloads

4

Readme

About

sql_user_manager is a complete drop-in middleware solution for user management. sql_user_manager is Express middleware and is compatible with any database supported by Knex (Postgres, MSSQL, MySQL, MariaDB, SQLite3, and Oracle). sql_user_manager also provides optional Knex backed session management via connect-session-knex.

sql_user_manager supports the following featues:

  • Registration
  • Login
  • Logout
  • Email Confirmation
  • Password reset
  • Session management(optional)

Screenshots

Register

Register Errors

Login

Password Reset

Depedencies

sql_user_manager requires an initialized Knex object and an initialized (Nodemailer)[https://github.com/nodemailer/nodemailer] tansporter (to handle password resets and email confirmations).

Example Usage

var app = require('express')()

var knex = require('knex')
var bodyParser = require('body-parser')
var secret = require('../secret'); // nodemailer SMTP config

var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');

var transporter = nodemailer.createTransport(smtpTransport(secret.smtp));

var dbCreds = {
    client: 'mysql',
    connection: {
        host: 'localhost',
        user: 'root',
        password: 'root',
        database: 'sql_login',
        port:  8889
    }
}

var knex = require('knex')(dbCreds)

var sqlLoginMiddleware = require('sql_user_manager')(app, {
    rootUrl: 'http://localhost:3010/test',
    knex: knex,
    transporter: transporter,
    siteName: 'Test Site',
    sessionSecret: 'super duper secret',
    loginSuccessRedirect: 'http://localhost:3010/test'
});

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));

app.use('/auth', sqlLoginMiddleware);

var server = app.listen(3010, function () {
    var host = server.address().address
    var port = server.address().port

    console.log("Example app listening at http://%s:%s", host, port)
})

Documentation

Session info

After registration or login, session will include a user object with a user.id property (you can check this to determin if the user is logged in)

Initialization:

npm install sql_user_manager

var sqlUserManager = require('sql_user_manager')(app, options);

Options

options.knex - required - initialized Knex object

options.loginSuccessRedirect - optional - url to redirect user to after successful login

options.manageSessions - optional - defaults to true. If true, user sessions get stored in DB

options.registerSuccesRedirect - optional - url to redirect user to after registration

options.requireTerms - optional - if true, registration will include a checkbox that user's are required to check indicating they agree to the terms

options.sessionSecret - required if useing manageSessions

options.sessionExpiration - optional - session expiration in ms, defaults to 12 hours

options.termsLink - optional - link for terms if requireTerms is used

options.tablename - optional - defatuls to 'sql_user_manager'

options.transporter - required - Nodemail transporter

options.siteName - required - name of site

Template Options

options.bodyBottom - optional - string that gets injected at the bottom of the body on any sql_user_manager pages

options.bodyTop - optional - string that gets injected at the top of the body on any sql_user_manager pages

options.header - optional - string that gets injected into the header of all sql_user_manager pages

Testing

node ./test/index.js

Todo

  • add brute force check
  • add optional terms checkbox and link for registration
  • add api routes for all existint routes