Skip to content

Commit

Permalink
Remove getAttemptedPath functionality
Browse files Browse the repository at this point in the history
* Functionality does not need to be recorded internally in the service
and if desired can be handled by the caller.
  • Loading branch information
justinsa committed Mar 14, 2017
1 parent d4ba15f commit d7f1dcc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 28 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,6 @@ $authentication.isInAnyRoles('role1', 'role2', ...);
$authentication.permit('role1', 'role2', ...);
```

This function also stores the current ```$location.path()``` for redirecting to if the user is required to login again.

###getAttemptedPath()
```JAVASCRIPT
// Return the last attempted path set by the permit call.
$authentication.getAttemptedPath();
```

###getConfiguration()
```JAVASCRIPT
// Return the configuration object.
Expand Down
20 changes: 4 additions & 16 deletions ng-authentication-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,23 +213,11 @@
* call this function to determine if a user is permitted and redirect if not.
*/
permit: function () {
if (this.allowed.apply(this, _.toArray(arguments))) {
storageService().remove('attemptedPath');
return;
if (!this.allowed.apply(this, _.toArray(arguments))) {
$location.path(
this.isAuthenticated() ? configuration.notPermittedRedirectPath : configuration.unauthenticatedRedirectPath
);
}
storageService().set('attemptedPath', $location.path());
if (this.isAuthenticated()) {
$location.path(configuration.notPermittedRedirectPath);
} else {
$location.path(configuration.unauthenticatedRedirectPath);
}
},

/**
* Returns the path that the user attempts to access before being redirected.
*/
getAttemptedPath: function () {
return storageService().get('attemptedPath');
},

/**
Expand Down
4 changes: 0 additions & 4 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ describe('services', function () {
'isInAllRoles',
'isInAnyRoles',
'permit',
'getAttemptedPath',
'getConfiguration',
'reauthenticate'
];
Expand Down Expand Up @@ -472,7 +471,6 @@ describe('services', function () {
$location.path().should.match('/about');
$authentication.permit('anonymous');
$location.path().should.match('/about');
($authentication.getAttemptedPath() === null).should.be.true; // jshint ignore:line
})
);

Expand All @@ -482,7 +480,6 @@ describe('services', function () {
$location.path().should.match('/about');
$authentication.permit('all');
$location.path().should.match('/unauthenticated');
$authentication.getAttemptedPath().should.equal('/about');
})
);

Expand All @@ -492,7 +489,6 @@ describe('services', function () {
$location.path().should.match('/about');
$authentication.permit('a', 'b');
$location.path().should.match('/unauthenticated');
$authentication.getAttemptedPath().should.equal('/about');
})
);
});
Expand Down

0 comments on commit d7f1dcc

Please sign in to comment.