-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added csrf manager, changed way that session and user components cont…
…act api
- Loading branch information
Showing
16 changed files
with
307 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
widgets can attach callbacks to a deferred that waits until | ||
* a new csrf token has been requested | ||
* | ||
* */ | ||
define([ | ||
'backbone', | ||
'js/components/generic_module', | ||
'js/mixins/hardened', | ||
"js/components/api_request", | ||
"js/components/api_targets" | ||
], | ||
function( | ||
Backbone, | ||
GenericModule, | ||
Hardened, | ||
ApiRequest, | ||
ApiTargets | ||
) { | ||
|
||
|
||
var CSRFManager = GenericModule.extend({ | ||
|
||
activate: function (beehive) { | ||
this.beehive = beehive; | ||
this.pubsub = beehive.Services.get('PubSub'); | ||
this.key = this.pubsub.getPubSubKey(); | ||
_.bindAll(this, ["resolvePromiseWithNewKey"]); | ||
this.pubsub.subscribe(this.key, this.pubsub.DELIVERING_RESPONSE, this.resolvePromiseWithNewKey); | ||
}, | ||
|
||
getCSRF : function(){ | ||
this.deferred = $.Deferred(); | ||
|
||
var request = new ApiRequest({ | ||
target : ApiTargets.CSRF | ||
}); | ||
|
||
this.pubsub.publish(this.key, this.pubsub.EXECUTE_REQUEST, request); | ||
return this.deferred.promise(); | ||
}, | ||
|
||
resolvePromiseWithNewKey : function(response){ | ||
//get csrf here | ||
var csrf = response.toJSON().csrf; | ||
this.deferred.resolve(csrf); | ||
}, | ||
|
||
hardenedInterface: { | ||
getCSRF : "getCSRF" | ||
} | ||
|
||
}); | ||
|
||
_.extend(CSRFManager.prototype, Hardened); | ||
|
||
return CSRFManager; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.