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

dhn-accounts

v1.1.2

Published

An account management library for Node.js and MongoDB

Downloads

12

Readme

dhn-accounts

A promise based account management library for Node.js and MongoDB

Usage

Api

Usage

Basic Configurations

const { MongoClient } = require('mongodb')
const dhnAccounts  = require('dhn-accounts')
const accounts = new dhnAccounts

MongoClient.connect('mongodb://127.0.0.1:27017', { useNewUrlParser: true })
  .then(db => {
    accounts.init({
      db,
      database: 'database',
      collection: 'users'
    })
  }).catch(err => console.error(err))

accounts.secret = 'secretKey' // Secret key for JWT

//smtp setup | optional
const nodemailer = require('nodemailer') // not included in dhn-accounts

accounts.smtpSetup({
nodemailer, // you need to pass nodemailer by yourself
from:  '"Duhan BALCI" <[email protected]>',
host:  '',
port:  465,
secure:  true,
user:  '',
pass:  '',
})

Functions

accounts.createUser({
  email:  '[email protected]',
  password:  'p@ssw0rd'
  }).then(() => console.log('user created'))
  .catch(err  =>  console.error(err.message))

accounts.login('[email protected]', '123123')
  .then(res => console.log(res)) // returns jwt
  .catch(err => console.error(err.message))
  
accounts.verifyToken(`${jwtToken}`)
  .then(res => console.log(res)) // returns payload
  .catch(err => console.error(err.message))

accounts.changePassword(`${userId}`, `${newPassword}`)
  .then(() => console.log('changed'))
  .catch(err => console.log(err.message))

accounts.changePasswordByUser(`${userId}`, `${oldPass}`, `${newPass}`)
  .then(() => console.log('changed'))
  .catch(err => console.log(err.message))

accounts.sendVerificationEmail(`${emailAdress}`)
  .then(() => console.log('sent'))
  .catch(err => console.error(err.message))

accounts.verifyEmail(`${verificationCode}`)
  .then(() => console.log('verified'))
  .catch(err => console.error(err.message))

accounts.sendPasswordRecoveryEmail(`${emailAdress}`)
  .then(() => console.log('sent'))
  .catch(err => console.error(err.message))

accounts.passwordRecovery(`${recoveryCode}`, `${newPassword}`)
  .then(() => console.log('changed'))
  .catch(err => console.error(err.message))

accounts.setUsername(`${userId}`, `${newUsername}`)
  .then(() => console.log('change'))
  .catch(err => console.error(err.message))

accounts.addEmail(`${userId}`, `${newEmail}`)
  .then(() => console.log('added'))
  .catch(err => console.error(err.message))

accounts.removeEmail(`${emailAdress}`)
  .then(() => console.log('deleted'))
  .catch(err => console.error(err.message))

Email Templates

//defaults
accounts.emailVerificationEmail.template  =  '<a href="http://example.com/verifyEmail/{verificationCode}" >Click here</a> for validte your email adress.'
accounts.emailVerificationEmail.subject  =  'Email Verification Mail'

accounts.passwordRecoveryEmail.template  =  '<a href="{passwordRecoveryCode}">Click here</a> for recover your password.'
accounts.passwordRecoveryEmail.subject  =  'Password Recovery Mail'

Internationalization

//Defaults
accounts.lang = 'en'
accounts.i18n.en = {
  passwordCantBeEmpty: 'password can not be empty',
  usernameAndEmailCantBeEmpty: 'username and email adress cannot be empty at the same time',
  usernameAlreadyUsing: 'username already using',
  emailAdressAlreadyUsing: 'email adress already using',
  wrongUsername: 'wrong username',
  wrongEmailAdress: 'wrong email adress',
  wrongPassword: 'wrong password',
  userNotFound: 'user not found',
  emailAdressNotFound: 'email adress not found',
  loginError: 'login error',
  wrongToken: 'wrong token',
  verificationEmailFail: 'failed to send verification email',
  recoveryEmailFail: 'failed to send password recovery email',
}

Api

accounts.createUser(options)

options Object

  • username string: optional if email entered
  • email string: optional if username entered
  • password string: password
  • profile? object: optional. You can access it from jwt payload

accounts.login(login, password)

  • login string: username or email adress
  • password string: password

accounts.verifyToken(jwtToken)

  • jwtToken string: json web token

accounts.changePassword(userId, newPassword)

  • userId string: user id
  • newPassword string: new password

accounts.changePasswordByUser(userId, oldPass, newPass)

  • userId string: user id
  • oldPass string: old password
  • newPass string: new password

accounts.sendVerificationEmail(emailAdress)

  • emailAdress string: email adress

accounts.verifyEmail(verificationCode)

  • verificationCode string: verificationCode from email

accounts.sendPasswordRecoveryEmail(emailAdress)

  • emailAdress string: email adress

accounts.passwordRecovery(recoveryCode, newPassword)

  • recoveryCode string: recovery code from email
  • newPassword string: email adress

accounts.setUsername(userId, newUsername)

  • userId string: user id
  • newUsername string: new username

accounts.addEmail(userId, newEmail)

  • userId string: user id
  • newEmail string: email adress

accounts.removeEmail(emailAdress)

  • emailAdress string: email adress