Giter Club home page Giter Club logo

loopback-example-user-organization's Introduction

loopback-example-user-organization

This is a demo application to showcase how to customize the user model with an associated organization.

Models:

Org: The organization model

  • name: String
  • orgUsers: hasMany relation to OrgUser (mapping Org.name to OrgUser.realm

OrgUser: The user model (extends from User)

  • fname: String
  • lname: String
  • org: belongsTo relation to Org (FK: orgUserId)

Example code in server/boot/user-org-realm.js

module.exports = function(app) {
  var OrgUser = app.models.OrgUser;
  var Org = app.models.Org;

  // Create an organization named as 'myRealm'
  Org.create({name: 'myRealm'}, function(err, org) {
    console.log(err, org);
    // Create an user within the organization
    org.orgUsers.create(
      {
        username: 'john',
        lname: 'Smith',
        fname: 'John',
        email: '[email protected]',
        password: '123'
      },
      function(err, user) {
        console.log(err, user);

        // Now try to login with realm
        OrgUser.login({username: 'myRealm:john', password: '123'},
          function(err, result) {
            console.log(err, result);
          })
      });

  });
};

Run the example

node .

You should see the output similar as follows:

null { name: 'myRealm', id: 1 }
Browse your REST API at http://0.0.0.0:3000/explorer
Web server listening at: http://0.0.0.0:3000/
null { username: 'john',
  lname: 'Smith',
  fname: 'John',
  email: '[email protected]',
  password: '$2a$10$E.4BOagiUW2v7qZCRkZAHuRDgeJRwW4pw70nGitwMtaIaFuoXqP6K',
  orgUserId: 1,
  realm: 'myRealm',
  id: 1 }
null { ttl: 1209600,
  userId: 1,
  created: Tue Feb 10 2015 13:51:24 GMT-0800 (PST),
  id: 'e6l5U3LJ9PKyMrbkGHu5xKDO0Uv9en5NG69PMqwzAROBIwGJWpkyJx5YjvAF1Dcw' }

loopback-example-user-organization's People

Contributors

raymondfeng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

loopback-example-user-organization's Issues

same user email across different realms

I am trying to add same user across two different realms (in my case which are organisations).
When i do that by using the automigrate file it works fine. Allows me to have same user (with same email address) in the user table for different realms.
But, when i try to do the same using the AngularJS SDK it throws an error saying ""The UserModelName instance is not valid. Details: email Email already exists".
Yes, the email exist but for a different realm (or organisation) than the one i am trying to register the user for. Not sure what's going wrong.
Some help would be much appreciated.
Thanks

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.