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

user-managements-node-server

v2.0.1

Published

starter for express node server with user managements, authentication authorization

Downloads

23

Readme

README

What is this repository for?

  • This repository is node server to managements users on back-end side

  • This repository has the following APIs

    1. sign-up:

      • Sending activation link to to (user email that sign up / or to admin if verifyUserBy set to true)
      • route: /user/sign-up
      • body:
        	{
        		username: '[email protected]',
        		password: 'user-password'
        	}
      • method: 'POST'
      • response:
      • json:
        	{
        		message: 'User create, email verification sent'
        	}
        http-status: 200 OK
    2. verify-user

      • Verify user by clicking on activation link
      • The linked that sent with an email
      • route: /user/verify/:actionId
      • method: 'GET'
      • response: HTML that says if activation succeeded or faild
    3. sign-in

      • Sign in by user credentials or by thired party like (Facebook / Google) if loginWithThirdParty set to true return token that needs to be send each other api call to identify the user
      • route: /user/sign-in
      • body:
        • a.
          {
          	username: '[email protected]',
          	password: 'user-password'
          }
          Or in case sign in via thired party (Facebook/Google)
        • b.
          {
          	username: '[email protected]',
          	password: 'thired-party-token-reponse',
          	thireParty: 'FACEBOOK' | 'GOOGLE'
          }
      • method: 'POST'
      • response:
      • json:
        { token: 'generated-token' }
        http-status: 200 OK

      ** The above response should be send in an header of each other requests (via interceptor or other)

    4. forgot-password

      • Forgot password will send to the email link (changePasswordUrl + actionId that set in config)
      • route: /forgot-password
      • body:
        { username: '[email protected]' }
      • method: 'POST'
      • reaponse:
      • json:
        { message: 'Password reset link sent to your Email' }
        http-status: 200 OK
      • Email will be send to the user with a link to change password, this link will combine actionId as a part of thr URL
    5. change-password

      • Change password - post to /user/change-password/{actionId} with { password } as payload
      • route: /user/change-password/:actionId
      • body:
        { password: 'new-password' }
      • method: 'POST'
      • response:
      • json:
        { message: 'Password successfully changed' }
        http-status: 200 OK
    6. get user info /user/info (token needs to be send in header)

      • get user info
      • route: /user/info
      • method: 'GET'
      • header:
        { token: 'generated-token' }
    7. contact-us

      • Sending email to that admin user (admin user in config file) (token needs to be send in header)
      • route: /user/contact-us
      • body:
        {
        	username: '[email protected]',
        	subject: 'contact-us-subjet',
        	description: 'contact-us-description'
        }
      • method: 'POST'
      • response: email with the payload will be sen to the adminEmail
  • version: 1.0.7

How do I get set up?

  • yarn add user-managements-node-server / npm --save user-managements-node-server]
  • This module use Sequelize so, it supports the following databases
  • Create one of the following database 'postgres'|'mysql'|'sqlite'|'mssql'
  • Create database login user
  • Database Tables - You can create it manually or use the 'dbcreate' script below :
  • Table: ActionVerifications
	ActionVerifications: {
		actionId: {
			type: DataTypes.UUID,
			allowNull: false,
			primaryKey: true,
			defaultValue: () => uuid.v4()
		},
		username: {
			type: DataTypes.STRING,
			allowNull: false
		},
		actionType: {
			type: DataTypes.INTEGER,
			allowNull: false
		},
		deleted: {
			type: DataTypes.BOOLEAN,
			allowNull: false,
			defaultValue: false
		}
	}
	Tokens: {
		id: {
			type: DataTypes.UUID,
			allowNull: false,
			primaryKey: true,
			defaultValue: () => uuid.v4()
		},
		userId: {
			type: DataTypes.UUID,
			allowNull: false,
			primaryKey: true
		},
		ip: {
			type: DataTypes.STRING,
			allowNull: false,
			unique: true
		},
		token: {
			type: DataTypes.STRING,
			allowNull: true
		},
		userAgentIdentity: {
			type: DataTypes.STRING,
			allowNull: false
		}
	}
  • Table: Users
	Users:
	{
		id: {
			type: DataTypes.UUID,
			allowNull: false,
			primaryKey: true,
			defaultValue: () => uuid.v4()
		},
		username: {
			type: DataTypes.STRING,
			allowNull: false,
			unique: true
		},
		password: {
			type: DataTypes.TEXT
		},
		fullName: {
			type: DataTypes.STRING,
			allowNull: true
		},
		token: {
			type: DataTypes.STRING,
			allowNull: true
		},
		fbToken: {
			type: DataTypes.TEXT,
			allowNull: true
		},
		googleToken: {
			type: DataTypes.TEXT,
			allowNull: true
		},
		profilePhoto: {
			type: DataTypes.STRING,
			allowNull: true
		},
		isValid: {
			type: DataTypes.BOOLEAN,
			defaultValue: false
		},
		termsOfUse: {
			type: DataTypes.BOOLEAN,
			defaultValue: false
		}
	}
  • Table: Audit
	Audit: {
		id: {
			type: DataTypes.UUID,
			allowNull: false,
			primaryKey: true,
			defaultValue: () => uuid.v4()
		},
		username: {
			type: DataTypes.STRING,
			allowNull: false
		},
		actionName: {
			type: DataTypes.STRING,
			allowNull: false
		},
		requestParams: {
			type: DataTypes.TEXT,
			allowNull: true
		}
	}
  • Edit the following config with the above settings
  • Configuration:
    • Setup the following config file: [config.js]
{
  "verifyUserBy": "ADMIN", // "ADMIN" | "AUTO" : "EMAIL"
  "verify3rdPartyUserBy": "AUTO", // "ADMIN" | "AUTO" : "EMAIL"
  "useSingleToken": false, // true - Multiple tokens for diffrent devices
  "appName":"<Your application name>", // The appName will be uses when sending emails to user/admin
  "port": 5000,
  "database": {
    "name": "user-managements-db",
    "username": "user-managements-username",
    "password": "user-managements-password",
    "settings": {
      // Database location
      "host": "localhost",
      // You can use one of the the foolowing databases
      "dialect": " mysql | mariadb | sqlite | postgres | mssql ",
      // In case you use sqlite storage file path is required
      "storage": "/tmp/user-managements.sqlite",
      "pool": {
        "max": 5,
        "min": 0,
        "idle": 10000
      },
      // To log database queries set the following to true
      "logging": false
    }
  },
  // The following email setting are require if you want the system to send emails to users
  "email": {
    "service": "<Email Service>",
    "user": "<Email Username>",
    "pass": "<Email Password>",
    "from": "<Email From>"
  },
  "verificationUrl": "http://your-web-site-domain/user/verify/",
  "changePasswordUrl": "http://your-web-site-domain/change-password/",
  "loginUrl": "http://your-web-site-domain/login",
  "tokenHash": "dev-token-key",
  "adminEmail": "<admin@your-domain>",
  "log4js": {
    "appenders": { "app": { "type": "file", "filename": "/var/log/your-app-name/app-name.log" } },
    "categories": { "default": { "appenders": ["app"], "level": "all" } }
  },
  "templates": {
    "activation":{
      "body" : "./email-templates/activation/body.html",
      "subject" : "./email-templates/activation/subject.html"
    },
    "approved":{
      "body" : "./email-templates/approved-activation/body.html",
      "subject" : "./email-templates/approved-activation/subject.html"
    },
    "notify":{
      "body" : "./email-templates/notify-admin-when-user-created/body.html",
      "subject" : "./email-templates/notify-admin-when-user-created/subject.html"
    },
    "activationResponse" : "./email-templates/activation/response.html"
  },
  "userRoutePrefix": "/user"
}
  • Run: yarn dbcreate Or npm run dbcreate - This script will create the relevant tables

  • Run the server:

  • Please see example how to run this module: run-user-managements-node-server-exp

  • Templates - any of the following templates can be edited with your own HTML template I've choose to work with dot module. You need to build your custom template with dot syntax. For example the default activationBody look like

    	export default
    		`<!doctype html>
    			<html>
    					<head>
    							<meta charset='utf-8'>
    							<title>{{=it.appName}}</title>
    							<style type='text/css'>
    									body {
    											-webkit-text-size-adjust: 100%;
    											-ms-text-size-adjust: 100%;
    											font-family: sans-serif;
    									}
    							</style>
    					</head>
    					<body>
    							<div>
    									<div>Hello, {{=it.username}}</div>
    									Thank you for registration our app,
    									to finish activation please click <a href='{{=it.verificationUrl}}{{=it.actionId}}'>here</a>
    							</div>
    					</body>
    			</html>
    		`
   1. activationBody
   	Exposed fields:
   	a. appName - appName from config
   	b. username - current handled username
   	c. verificationUrl - verificationUrl from config
   	d. actionId - current handled actionId

   2. activationSubject
   	Exposed fields:
   	a. appName - appName from config

   3. activationResponse
   	Exposed fields:
   	a. appName - appName from config
   	b. error - boolean indicator
   	c. link - loginUrl from config

   4. activationBodyApproved
   	a. appName - appName from config
   	b. username - current handled username
   	c. loginUrl - loginUrl from config

   5. activationSubjectApproved
   	a. appName - appName from config

   6. notifyBodyAdminWhenUserCreated
   	a. appName - appName from config
   	b. admin - adminEmail from config
   	c. username - current handled username
   	d. fullName - current handled user's fullName

   7. notifySubjectAdminWhenUserCreated
   	a. appName - appName from config
   	b. username - current handled username

* Haim Rubin
* [email protected]
- Please let me know on any issue