diff --git a/README.md b/README.md index 56275b52..51982f91 100644 --- a/README.md +++ b/README.md @@ -944,7 +944,7 @@ Defining a model with `loopback.createModel()` is really just extending the base Register and authenticate users of your app locally or against 3rd party services. -#### Create a User Model +#### Define a User Model Extend a vanilla Loopback model using the built in User model. @@ -966,19 +966,6 @@ Extend a vanilla Loopback model using the built in User model. **Note:** By default the `loopback.User` model uses the `loopback.Session` model to persist sessions. You can change this by setting the `session` property. **Note:** You must attach both the `User` and `User.session` model's to a data source! - - // define a custom session model - var MySession = loopback.Session.extend('my-session'); - - // define a custom User model - var User = loopback.User.extend('user'); - - // use the custom session model - User.session = MySession; - - // attaching to - - #### User Creation @@ -1024,7 +1011,9 @@ Setup an authentication strategy. #### Login a User -Create a session for a user. +Create a session for a user using the local auth strategy. + +**Node.js** User.login({username: 'foo', password: 'bar'}, function(err, session) { console.log(session); @@ -1053,23 +1042,27 @@ You must provide a username and password over rest. To ensure these values are e #### Logout a User -**NODE** +**Node.js** -// login a user and logout -User.login({"email": "foo@bar.com", "password": "bar"}, function(err, session) { - User.logout(session.id, function(err) { - // user logged out - }); -}); + // login a user and logout + User.login({"email": "foo@bar.com", "password": "bar"}, function(err, session) { + User.logout(session.id, function(err) { + // user logged out + }); + }); -// logout a user (server side only) -User.findOne({email: 'foo@bar.com'}, function(err, user) { - user.logout(); -}); + // logout a user (server side only) + User.findOne({email: 'foo@bar.com'}, function(err, user) { + user.logout(); + }); **REST** -**Note:** When calling this method remotely, the first argument will be populated with the current user's id. If the caller is not logged in the method will fail with an error status code `401`. + POST /users/logout + ... + { + "sid": "" + } #### Verify Email Addresses diff --git a/lib/models/user.js b/lib/models/user.js index 0c9006af..bf0b4884 100644 --- a/lib/models/user.js +++ b/lib/models/user.js @@ -313,18 +313,6 @@ User.setup = function () { return UserModel; } -/** - * Logout a user. - */ - -User.prototype.logout = function (fn) { - fn = fn || function() {}; // noop - - this.constructor.session.findOne({email: this.email}, function (err, session) { - session.destroy(fn); - }); -} - /*! * Setup the base user. */ diff --git a/test/user.test.js b/test/user.test.js index a7215122..3a6f6f8b 100644 --- a/test/user.test.js +++ b/test/user.test.js @@ -138,20 +138,6 @@ describe('User', function(){ } }); - it('Logout a user using the instance method', function(done) { - login(logout); - - function login(fn) { - User.login({email: 'foo@bar.com', password: 'bar'}, fn); - } - - function logout(err, session) { - User.findOne({email: 'foo@bar.com'}, function (err, user) { - user.logout(verify(session.id, done)); - }); - } - }); - function verify(sid, done) { assert(sid);