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-reset-password

v0.0.5

Published

For the express server to reset user password by aws ses and redis cache, typescript base.

Downloads

4

Readme

Express Reset Password

For the express server to reset user password by aws ses and redis cache, typescript base.

Installation

yarn add express-reset-password

Uses

const express = require('express');
const bodyParser = require('body-parser');
const {
  resetPassword,
  resetPasswordToken
} = require('express-reset-password').default;
const app = express();

const resetCallback = (req, res) => {
  const body = req.body;
  console.log(body);
};

app.use(bodyParser());
app.post('/reset', resetPassword);
app.post('/reset/token', resetPasswordToken, resetCallback);
app.get('/reset-password', (req, res) => {
  const { token } = req.query;
  res.status(200).send(token);
});

app.listen(8080, () => console.log('Server run on port 8080'));

Environment

  • REDIS_HOST - default (redis://localhost:6379)

  • AWS_SES_REGION - default (us-west-2)

  • EMAIL_RESETPASSWORD_HOST default (http://localhost:8080/reset-password)

  • EMAIL_RESETPASSWORD_SENDER (required)

  • EMAIL_RESETPASSWORD_EXPIREDTIME default (300sec)

[Options Environment]

AWS ENVIRONMENT

  • AWS_SECRET_ACCESS_KEY

  • AWS_ACCESS_KEY_ID

Custom Email Template

Default email template

`
Hello, <br />
This is your password reset url, please click to open it. <br />
<a href='${host}?token=${token}'>${host}?token=${token}</a> <br />
* Don't send this mail for other people.
`;

Custom email template

The module can let you send your own email template, use Inject to change it. use HTML to design the custom email template.

const { inject } = require('express-reset-password').default;
inject.emailTemplate = (token, host) => `
Hi, <br />
This is a custom email template <br />
you can reset your email from link <br />
${host}?token=${token} <br />
Don't share this email for any one. <br />
`;

Reset callback data

From next() callback, the reset payload will merge into req.body object.

Successed

// req.body
{
  token: 'c1a6b06ec9ebf5b43039b0322748f422a8dce40bbd26c629f6bd294ce3fd4aa8',
  success: true,
  resetPayload: {
    email: '[email protected]',
    token: 'c1a6b06ec9ebf5b43039b0322748f422a8dce40bbd26c629f6bd294ce3fd4aa8'
  }
};

Failed

// req.body
{
  token: 'notreall',
  success: false,
  resetPayload: {}
};

Q&A

  • resetPassword middleware request body ?

You should use express middleware body-parser to parse your request into req.body, and your server just receive the email only.

(req, res) => {
  const { email } = req.body;
};

Error Handle: If your undefined or null, you can receive the The email shouldn't be empty. response.

  • resetPasswordToken middleware request body ?

You should use express middleware body-parser to parse your request into req.body, and your server just receive the email only.

(req, res) => {
  const { token } = req.body;
};
  • how to set AWS credentials ?

See the aws credentials setting document.

always in ~/.aws/credentials

[default]
aws_access_key_id = your_key_id
aws_secret_access_key = your_access_key
  • how to connection redis ?

When you use local or test env, you can just use default host redis:localhost:6379, or you can set your own redis host enviroment.

  • how to set my express router ?

The express-reset-password like the middleware, so you can set your own express router.

License

MIT