Advertisement
Guest User

Untitled

a guest
Jul 8th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. define([
  2. 'bundle',
  3. 'lodash'
  4. ], function (bundle, _) {
  5.  
  6. touchIdController.$inject = ['$rootScope', '$scope', '$q', '$state', '$ionicModal', '$ionicPopover', 'authenticationService', '$cordovaKeychain', '$localstorage', 'toastService', 'modalService'];
  7.  
  8. function touchIdController($rootScope, $scope, $q, $state, $ionicModal, $ionicPopover, authenticationService, $cordovaKeychain, $localstorage, toastService, modalService) {
  9. $scope.credentialModal = {};
  10.  
  11. //Our model
  12. $scope.touchIdCredentials = {
  13. username: '',
  14. password: ''
  15. };
  16.  
  17. //This is a modal that prompts the user to enter their username and password to store in the device keychain
  18. modalService.fromTemplateUrl('./app/profile/directives/touch-id-credentials-modal.html', {
  19. scope: $scope,
  20. animation: 'slide-in-right',
  21. backdropClickToClose: false
  22. },'hq-full-modal').then(function (modal) {
  23. $scope.credentialModal = modal;
  24. });
  25.  
  26. //When the user agrees with the agreement we show the username/password modal
  27. $scope.agree = function () {
  28. $scope.credentialModal.show();
  29. };
  30.  
  31. //If they don't agree we take them back to the home page and disable touch id
  32. $scope.notAgree = function () {
  33. $localstorage.set('touchIdEnabled', 'false');
  34.  
  35. $state.go('home.dashboard');
  36. }
  37.  
  38. //After the user enters in their credentials we verify they are correct, enable touch id and save the credentials in the keychain
  39. $scope.verifyCredentials = function () {
  40. authenticationService.login($scope.touchIdCredentials.username, $scope.touchIdCredentials.password)
  41. .then(function success(data) {
  42. authenticationService.saveCredentialsInKeychain($scope.touchIdCredentials.username, $scope.touchIdCredentials.password);
  43.  
  44. $localstorage.set('touchIdEnabled', 'true');
  45.  
  46. $scope.removeCredentialModal();
  47.  
  48. toastService.simple('Touch ID Enabled.');
  49.  
  50. $state.go('home.dashboard');
  51. },
  52. function failure(data) {
  53. toastService.showSimpleError('Validation failed. Please try again.');
  54. }
  55. );
  56. };
  57.  
  58. //closes the modal
  59. $scope.removeCredentialModal = function() {
  60. $scope.credentialModal.remove();
  61.  
  62. $rootScope.modalActive = '';
  63. }
  64.  
  65. //cancel entering the credentials
  66. $scope.cancelVerification = function () {
  67. $scope.credentialModal.remove();
  68.  
  69. $cordovaKeychain.removeForKey(username);
  70. $cordovaKeychain.removeForKey(password);
  71. };
  72.  
  73. //remove these modals on state change
  74. $scope.$on('$stateChangeStart', function(){
  75. $scope.credentialModal.remove();
  76. $rootScope.modalActive = '';
  77. });
  78. };
  79.  
  80. return touchIdController;
  81. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement