Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- define([
- 'bundle',
- 'lodash'
- ], function (bundle, _) {
- touchIdController.$inject = ['$rootScope', '$scope', '$q', '$state', '$ionicModal', '$ionicPopover', 'authenticationService', '$cordovaKeychain', '$localstorage', 'toastService', 'modalService'];
- function touchIdController($rootScope, $scope, $q, $state, $ionicModal, $ionicPopover, authenticationService, $cordovaKeychain, $localstorage, toastService, modalService) {
- $scope.credentialModal = {};
- //Our model
- $scope.touchIdCredentials = {
- username: '',
- password: ''
- };
- //This is a modal that prompts the user to enter their username and password to store in the device keychain
- modalService.fromTemplateUrl('./app/profile/directives/touch-id-credentials-modal.html', {
- scope: $scope,
- animation: 'slide-in-right',
- backdropClickToClose: false
- },'hq-full-modal').then(function (modal) {
- $scope.credentialModal = modal;
- });
- //When the user agrees with the agreement we show the username/password modal
- $scope.agree = function () {
- $scope.credentialModal.show();
- };
- //If they don't agree we take them back to the home page and disable touch id
- $scope.notAgree = function () {
- $localstorage.set('touchIdEnabled', 'false');
- $state.go('home.dashboard');
- }
- //After the user enters in their credentials we verify they are correct, enable touch id and save the credentials in the keychain
- $scope.verifyCredentials = function () {
- authenticationService.login($scope.touchIdCredentials.username, $scope.touchIdCredentials.password)
- .then(function success(data) {
- authenticationService.saveCredentialsInKeychain($scope.touchIdCredentials.username, $scope.touchIdCredentials.password);
- $localstorage.set('touchIdEnabled', 'true');
- $scope.removeCredentialModal();
- toastService.simple('Touch ID Enabled.');
- $state.go('home.dashboard');
- },
- function failure(data) {
- toastService.showSimpleError('Validation failed. Please try again.');
- }
- );
- };
- //closes the modal
- $scope.removeCredentialModal = function() {
- $scope.credentialModal.remove();
- $rootScope.modalActive = '';
- }
- //cancel entering the credentials
- $scope.cancelVerification = function () {
- $scope.credentialModal.remove();
- $cordovaKeychain.removeForKey(username);
- $cordovaKeychain.removeForKey(password);
- };
- //remove these modals on state change
- $scope.$on('$stateChangeStart', function(){
- $scope.credentialModal.remove();
- $rootScope.modalActive = '';
- });
- };
- return touchIdController;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement