Giter Club home page Giter Club logo

restify-devise's Introduction

Restify Devise

Starter project for a rest api with restify & node-devise. Inspired by Advanced Node.js Project Structure Tutorial.

Travis Status Code Coverage

It also allows users to deploy in Heroku without leaving the web browser and with little configuration.

Deploy

Note

  • See the node-devise documentation for how to configure the user schema :).

  • For the tests will be used httpie

Table of Contents

Requirements

  • node >= 8
  • npm >= 5

Installation

You must configure the environment variables to be able to run the application, follow the table below for this:

Development-specific options must be added in the configuration file .env

You can also perform manual deployment on heroku through the installation file.

sh heroku.deploy.sh

Key Description
PROCESS_TYPE Defines a main process between the various application processes.
PORT Server communication port.
CLIENT_URI Define a URL for client redirection.
MONGODB_URI Sets the location of mongodb. You can use the mlab service to receive a remote database.
SECRET_KEY Encryption private key.
MAILER_USER Reply email may be fake.
MAILER_KEY By default, the application consumes the sendgrid service for sending emails. You must enter the access token for the project.

Usage

With the project installed correctly, you can test the endpoints below:

You can use the web project to see the result of the routes below., e.g:

http restify-devise.herokuapp.com/session payload:='{"email": "your@email", "password": "secret"}'

User registration

http :8088/registration payload:='{"email": "your@email", "password": "secret"}'
# HTTP/1.1 200 OK
# {}

You can change the language by changing the header accept-language:

http :8088/registration payload:='{"email": "your@email"}' 'accept-language: pt-BR'
# HTTP/1.1 400 Bad Request
# {
#   "code": "BadRequest",
#   "message": {
#     "context": {
#       "key": "password",
#       "label": "password"
#     },
#     "warn": "'Senha' é obrigatório"
#   }
# }

Signing in

When the account is not verified:

http :8088/session payload:='{"email": "your@email", "password": "secret"}'
# HTTP/1.1 401 Unauthorized
# {
#   "code": "InvalidCredentials",
#   "message": "Account not confirmed"
# }

When the password is incorrect:

http :8088/session payload:='{"email": "your@email", "password": "secret1"}'
# HTTP/1.1 401 Unauthorized
# {
#   "code": "InvalidCredentials",
#   "message": "Incorrect password"
# }

When the data is right:

http :8088/session payload:='{"email": "your@email", "password": "secret"}'
# HTTP/1.1 200 OK
# {
#   "token": "token"
# }

Accessing Protected Routes

Recovery needs a token, so create a token to continue:

this example is available here as well.

const createToken = () => {
  return jwt.sign({}, 'secret')
}

Password recovery

http :8088/password payload:='{"email": "your@email"}'
# HTTP/1.1 401 Unauthorized
# Unauthorized

the correct access returns 204 and forwards an email to the informed account

http :8088/password payload:='{"email": "your@email"}' token=='token'
# HTTP/1.1 204 No Content
# {}

User unlock

the project is set to lock the account after 3 incorrect access attempts, a blocked account will return the following response:

http :8088/session payload:='{"email": "your@email", "password": "secret1"}'
# HTTP/1.1 401 Unauthorized
# {
#   "code": "InvalidCredentials",
#   "message": "Account locked. Check unlock instructions sent to you."
# }

License

MIT

Copyright (c) 2018-present

restify-devise's People

Contributors

carvalhoviniciusluiz avatar viniciusluiz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.