GithubHelp home page GithubHelp logo

romanovroman / loopback-example-user-management Goto Github PK

View Code? Open in Web Editor NEW

This project forked from strongloop/loopback-example-user-management

0.0 1.0 0.0 78 KB

LoopBack user management example

Home Page: http://loopback.io/doc/en/lb3/Managing-users.html

License: Other

JavaScript 70.50% HTML 26.78% Dockerfile 2.72%

loopback-example-user-management's Introduction

loopback-example-user-management

$ git clone [email protected]:strongloop/loopback-example-user-management.git
$ cd loopback-example-user-management
$ npm install
$ node .
Notes

Project Layout

  • common/models contains the extended user files. user.js contains the logic for sending emails and password reset, while user.json contains the model definition.
  • server/boot/authentication.js enables authentication middleware with the enableAuth() method. It's this middleware that finds the access token id string (usually from the query string) and appends entire token instance onto the express request object as req.accessToken. From there, you can find the user's ID: req.accessToken.userId (used in the routes.js file, see directly below).
  • server/boot/routes.js contains all the routing logic. In this example, we have used Express to configure the routing since each LoopBack app is an extended version of an Express app.
  • server/viewscontains all the views (or pages) rendered by Express using the EJS templating framework
  • server/datasources.json contains the datasource configurations. Here is where we add an email datasource.
  • server/model-config.json contains the all the model configurations. Here is where we configure the extended user model (lowercase 'u') and the email model. The rest of the models are all built-in LoopBack models.
Note

All other files have not been modified from their defaults.

How do you register a new user?

  1. Create a form to gather sign up information
  2. Create a remote hook to send a verification email
Notes
  • Upon execution, user.verify sends an email using the provided options
  • The verification email is configured to redirect the user to the /verified route in our example. For your app, you should configure the redirect to match your use case
  • The options are self-explanatory except type, template and user
    • type - value must be email
    • template - the path to the template to use for the verification email
    • user - when provided, the information in the object will be used in the verification link email

How do you send an email verification for a new user registration?

See step 2 in the previous question

How do you log in a user?

  1. Create a form to accept login credentials
  2. Create an route to handle the login request

How do you log out a user?

  1. Create a logout link with the access token embedded into the URL
  2. Call User.logout with the access token
Notes
  • We use the LoopBack token middleware to process access tokens. As long as you provide access_token in the query string of URL, the access token object will be provided in req.accessToken property in your route handler

How do you perform a password reset for a registered user?

  1. Create a form to gather password reset info
  2. Create an endpoint to handle the password reset request. Calling User.resetPassword ultimately emits a resetPasswordRequest event and creates a temporary access token
  3. Register an event handler for the resetPasswordRequest that sends an email to the registered user. In our example, we provide a URL that redirects the user to a password reset page authenticated with a temporary access token
  4. Create a password reset form for the user to enter and confirm their new password
  5. Create an endpoint to process the password reset
  • For the resetPasswordRequest handler callback, you are provided with an info object which contains information related to the user that is requesting the password reset. Note that this example is set up to send an initial email to yourself (the FROM and TO fields are the same). You will eventually want to change the address in the FROM field.

More LoopBack examples

loopback-example-user-management's People

Contributors

0candy avatar adelriosantiago avatar alfred-nsh avatar b-admike avatar crandmck avatar deniselee avatar dhmlau avatar dstroot avatar jacky96623 avatar loay avatar richardpringle avatar rmg avatar romanovroman avatar sam-github avatar sequoia avatar shairez avatar siddhipai avatar simonhoibm avatar superkhau 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.