Clean up log out methods
This commit is contained in:
parent
35cafff877
commit
89f65d792f
27
README.md
27
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.
|
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.
|
Extend a vanilla Loopback model using the built in User model.
|
||||||
|
|
||||||
|
@ -967,19 +967,6 @@ Extend a vanilla Loopback model using the built in User model.
|
||||||
|
|
||||||
**Note:** You must attach both the `User` and `User.session` model's to a data source!
|
**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
|
#### User Creation
|
||||||
|
|
||||||
Create a user like any other model.
|
Create a user like any other model.
|
||||||
|
@ -1024,7 +1011,9 @@ Setup an authentication strategy.
|
||||||
|
|
||||||
#### Login a User
|
#### 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) {
|
User.login({username: 'foo', password: 'bar'}, function(err, session) {
|
||||||
console.log(session);
|
console.log(session);
|
||||||
|
@ -1053,7 +1042,7 @@ You must provide a username and password over rest. To ensure these values are e
|
||||||
|
|
||||||
#### Logout a User
|
#### Logout a User
|
||||||
|
|
||||||
**NODE**
|
**Node.js**
|
||||||
|
|
||||||
// login a user and logout
|
// login a user and logout
|
||||||
User.login({"email": "foo@bar.com", "password": "bar"}, function(err, session) {
|
User.login({"email": "foo@bar.com", "password": "bar"}, function(err, session) {
|
||||||
|
@ -1069,7 +1058,11 @@ User.findOne({email: 'foo@bar.com'}, function(err, user) {
|
||||||
|
|
||||||
**REST**
|
**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": "<session id from user login>"
|
||||||
|
}
|
||||||
|
|
||||||
#### Verify Email Addresses
|
#### Verify Email Addresses
|
||||||
|
|
||||||
|
|
|
@ -313,18 +313,6 @@ User.setup = function () {
|
||||||
return UserModel;
|
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.
|
* Setup the base user.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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) {
|
function verify(sid, done) {
|
||||||
assert(sid);
|
assert(sid);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue