Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. 'use strict';
  2.  
  3. module.exports = function CreateGroupKeyController ( $scope, $modalInstance, ToasterService, ApiService, collection ) {
  4. var self = this;
  5. var groupid, newData, key;
  6.  
  7. self.disableGroupKeyField = false;
  8. self.errorDuplicategroupKey = false;
  9.  
  10. function createUrlSuccessHandler ( urlResponse ) {
  11. console.log( urlResponse );
  12. newData.Return = urlResponse.data.DestinationUrl;
  13. newData.entityId = urlResponse.data.EntityId;
  14. newData.certificate = urlResponse.data.SigningCertificatePath;
  15. }
  16.  
  17. function commonErrorHandler ( err ) {
  18. ToasterService.error( err.data );
  19. }
  20.  
  21. function createContactSuccessHandler ( contactResponse ) {
  22. newData = contactResponse.data;
  23. newData.Key = key;
  24.  
  25. if ( self.samlChecked ) {
  26. ApiService.sso.createUrl( groupid, self.groupKey.url, self.groupKey.entityId, self.groupKey.certificate ).then( createUrlSuccessHandler, commonErrorHandler );
  27. }
  28.  
  29. collection.push( newData );
  30. $modalInstance.close();
  31. ToasterService.success( 'GroupKey was successfully added to a user.' );
  32. }
  33.  
  34. function createGroupKeySuccessHandler ( createResponse ) {
  35. self.errorDuplicategroupKey = false;
  36. self.disableGroupKeyField = true;
  37. self.groupKey.secret = createResponse.data.Secret;
  38. groupid = createResponse.data.GroupId;
  39. key = createResponse.data.Key;
  40.  
  41. ApiService.sso.createContact( groupid, self.groupKey.email ).then( createContactSuccessHandler, commonErrorHandler );
  42. }
  43.  
  44. function createGroupKeyErrorHandler () {
  45. self.errorDuplicategroupKey = true;
  46. }
  47.  
  48. function generate () {
  49. ApiService.sso.createGroupKey( self.groupKey.groupKey ).then( createGroupKeySuccessHandler, createGroupKeyErrorHandler );
  50. }
  51.  
  52. $scope.cancel = function () {
  53. $modalInstance.dismiss();
  54. };
  55.  
  56. $scope.ok = function () {
  57. generate();
  58. };
  59.  
  60. self.generate = generate;
  61. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement