$stormpath
stormpath
This service allows you to enable application-wide features of the library.
At the moment the only feature is the UI Router integration, which is documented below.
Call this method to enable the integration with the ngRoute module.
When enabled, you can define Stormpath Route Configurations on your routes. This object allows you to define access control for the route.
You can pass config options to this integration, the options control the default behavior around "need to login" and "forbidden" situations. If you wish to implement your own logic for these situations, simply omit the options and use the events (documented below) to know what is happening in the application.
| Param | Type | Details |
|---|---|---|
| config | object |
|
angular.module('myApp')
.run(function($stormpath){
$stormpath.ngRouter({
forbiddenRoute: '/forbidden',
defaultPostLoginRoute: '/home',
loginRoute: '/login'
});
});
Call this method to enable the integration with the UI Router module.
When enabled, you can define Stormpath State Configurations on your UI states. This object allows you to define access control for the state.
You can pass config options to this integration, the options control the default behavior around "need to login" and "forbidden" situations. If you wish to implement your own logic for these situations, simply omit the options and use the events (documented below) to know what is happening in the application.
| Param | Type | Details |
|---|---|---|
| config | object |
|
angular.module('myApp')
.run(function($stormpath){
$stormpath.uiRouter({
forbiddenState: 'forbidden',
defaultPostLoginState: 'main',
loginState: 'login'
});
});
This event is broadcast when a route change is prevented, because the user is not logged in.
Use this event if you want to implement your own strategy for presenting the user with a login form.
To receive this event, you must be using the ngRoute module.
| Param | Type | Details |
|---|---|---|
| event | Object | Angular event object. |
| toRoute | Object | The route that the user attempted to access. |
$rootScope.$on('$routeChangeUnauthenticated', function(event, toRoute) {
// Your custom logic for deciding how the user should login, and
// if you want to redirect them to the desired route afterwards
});
This event is broadcast when a UI state change is prevented, because the user is not logged in.
Use this event if you want to implement your own strategy for presenting the user with a login form.
To receive this event, you must be using the UI Router integration.
| Param | Type | Details |
|---|---|---|
| event | Object | Angular event object. |
| toState | Object | The state that the user attempted to access. |
| toParams | Object | The state params of the state that the user attempted to access. |
$rootScope.$on('$stateChangeUnauthenticated',function(e,toState,toParams){
// Your custom logic for deciding how the user should login, and
// if you want to redirect them to the desired state afterwards
});