<commit_before>'use strict';

/**
 * @ngdoc function
 * @name dockstore.ui.controller:OnboardingCtrl
 * @description
 * # OnboardingCtrl
 * Controller of the dockstore.ui
 */
angular.module('dockstore.ui')
  .controller('OnboardingCtrl', [
    '$scope',
    '$q',
    '$auth',
    '$location',
    '$window',
    'UserService',
    'TokenService',
    'ContainerService',
    'NotificationService',
    'WebService',
    function ($scope, $q, $auth, $location, $window,
        UserService, TokenService, ContainerService, NtfnService, WebService) {

      $scope.user = UserService.getUserObj();

      $scope.owStep = 1;
      $scope.advanceStep = function() {
        switch ($scope.owStep) {
          case 1:
            /* Check that both GitHub and Quay.io Accounts are linked */
            $scope.owStep++;
            break;
          case 2:
            $scope.owStep++;
            break;
          case 3:
            $location.path('#/search');
            /* Remove User from new-users Group */
            break;
          default:
            $scope.owStep = 1;
        }
      };

      $scope.linkGitHubAccount = function() {
        $auth.logout()
          .then(function() {
            UserService.setUserObj(null);
            NtfnService.popSuccess('Logout', 'Logout successful.');
            NtfnService.popInfo('Link GitHub Account',
              'Please select the option, "Sign in with GitHub" to continue.');
            $location.path('#/login');
          });
      };

      $scope.linkQuayioAccount = function() {
        $window.location.href = WebService.QUAYIO_AUTH_URL +
          '?client_id=' + WebService.QUAYIO_CLIENT_ID +
          '&redirect_uri=' + WebService.QUAYIO_REDIRECT_URI +
          '&response_type=token' +
          '&realm=realm' +
          '&scope=' + WebService.QUAYIO_SCOPE;
      };

      $scope.loadExternalAccounts = function() {
        NtfnService.popInfo('User External Accounts',
          'Retrieving list of external accounts...');
        return TokenService.getUserTokens($scope.user.id)
          .then(function(tokens) {
            $scope.githubAccount = false;
            $scope.quayioAccount = false;
            for (var i = 0; i < tokens.length; i++){
              switch (tokens[i].tokenSource) {
                case 'github.com':
                  $scope.githubAccount = true;
                  break;
                case 'quay.io':
                  $scope.quayioAccount = true;
                  break;
              }
            }
          }, function(response) {
            var message = (typeof response.statusText !== 'undefined') ?
              response.statusText : 'Unknown Error.';
            NtfnService.popError('User External Accounts', message);
            return $q.reject(response);
          });
      };

      $scope.registerQuayioToken = function(userId, accessToken) {
        NtfnService.popInfo('User External Accounts',
          'Registering Quay.io access token...');
        return TokenService.registerQuayioAccessToken(userId, accessToken)
          .then(function(token) {
            NtfnService.popSuccess('User External Accounts',
              'Quay.io token registered successfully.');
          }, function(response) {
            var message = (typeof response.statusText !== 'undefined') ?
              response.statusText : 'Unknown Error.';
            NtfnService.popError('User External Accounts', message);
            return $q.reject(response);
          });
      };

      $scope.loadExternalAccounts()
        .then(function() { NtfnService.clearAll(); });

      $scope.quaioAccTknRegexp = /access_token=([a-zA-Z0-9]*)/;
      if ($scope.quaioAccTknRegexp.test($location.url())) {
        var quayioAccTkn = $location.url().match($scope.quaioAccTknRegexp)[1];
        $scope.registerQuayioToken(UserService.getUserObj().id, quayioAccTkn)
          .then(function() {
            ContainerService.refreshContainers($scope.user.id)
              .then(function(containers) {
                console.log('success!', containers);
                $window.location.href = '#/onboarding';
              }, function(response) {
                console.log('failure:', response);
              });
          });
      }

  }]);<commit_msg>Update Quay.io linking UI.<commit_after>'use strict';

/**
 * @ngdoc function
 * @name dockstore.ui.controller:OnboardingCtrl
 * @description
 * # OnboardingCtrl
 * Controller of the dockstore.ui
 */
angular.module('dockstore.ui')
  .controller('OnboardingCtrl', [
    '$scope',
    '$q',
    '$auth',
    '$location',
    '$window',
    'UserService',
    'TokenService',
    'ContainerService',
    'NotificationService',
    'WebService',
    function ($scope, $q, $auth, $location, $window,
        UserService, TokenService, ContainerService, NtfnService, WebService) {

      $scope.user = UserService.getUserObj();

      $scope.owStep = 1;
      $scope.advanceStep = function() {
        switch ($scope.owStep) {
          case 1:
            /* Check that both GitHub and Quay.io Accounts are linked */
            $scope.owStep++;
            break;
          case 2:
            $scope.owStep++;
            break;
          case 3:
            $location.path('#/search');
            /* Remove User from new-users Group */
            break;
          default:
            $scope.owStep = 1;
        }
      };

      $scope.linkGitHubAccount = function() {
        $auth.logout()
          .then(function() {
            UserService.setUserObj(null);
            NtfnService.popSuccess('Logout', 'Logout successful.');
            NtfnService.popInfo('Link GitHub Account',
              'Please select the option, "Sign in with GitHub" to continue.');
            $location.path('#/login');
          });
      };

      $scope.linkQuayioAccount = function() {
        $window.location.href = WebService.QUAYIO_AUTH_URL +
          '?client_id=' + WebService.QUAYIO_CLIENT_ID +
          '&redirect_uri=' + WebService.QUAYIO_REDIRECT_URI +
          '&response_type=token' +
          '&realm=realm' +
          '&scope=' + WebService.QUAYIO_SCOPE;
      };

      $scope.loadExternalAccounts = function() {
        NtfnService.popInfo('User External Accounts',
          'Retrieving list of external accounts...');
        return TokenService.getUserTokens($scope.user.id)
          .then(function(tokens) {
            $scope.githubAccount = false;
            $scope.quayioAccount = false;
            for (var i = 0; i < tokens.length; i++){
              switch (tokens[i].tokenSource) {
                case 'github.com':
                  $scope.githubAccount = true;
                  break;
                case 'quay.io':
                  $scope.quayioAccount = true;
                  break;
              }
            }
          }, function(response) {
            var message = (typeof response.statusText !== 'undefined') ?
              response.statusText : 'Unknown Error.';
            NtfnService.popError('User External Accounts', message);
            return $q.reject(response);
          });
      };

      $scope.registerQuayioToken = function(userId, accessToken) {
        NtfnService.popInfo('User External Accounts',
          'Registering Quay.io access token...');
        return TokenService.registerQuayioAccessToken(userId, accessToken)
          .then(function(token) {
            NtfnService.popSuccess('User External Accounts',
              'Quay.io token registered successfully.');
          }, function(response) {
            var message = (typeof response.statusText !== 'undefined') ?
              response.statusText : 'Unknown Error.';
            NtfnService.popError('User External Accounts', message);
            return $q.reject(response);
          });
      };

      $scope.refreshUserContainers = function(userId) {
        NtfnService.popInfo('Docker Containers',
          'Refreshing Docker container cache...');
        ContainerService.refreshContainers(userId)
          .then(function(containers) {
            NtfnService.popInfo('Docker Containers',
              'Docker container cache refresh successful...');
            $window.location.href = '#/onboarding';
          }, function(response) {
            var message = (typeof response.statusText !== 'undefined') ?
              response.statusText : 'Unknown Error.';
            NtfnService.popError('User External Accounts', message);
            return $q.reject(response);
          });
      };

      $scope.loadExternalAccounts()
        .then(function() { NtfnService.clearAll(); });

      $scope.quaioAccTknRegexp = /access_token=([a-zA-Z0-9]*)/;
      if ($scope.quaioAccTknRegexp.test($location.url())) {
        var quayioAccTkn = $location.url().match($scope.quaioAccTknRegexp)[1];
        $scope.registerQuayioToken(UserService.getUserObj().id, quayioAccTkn)
          .then(function() {
            $scope.refreshUserContainers($scope.user.id);
          });
      }

  }]);
{'fraction_non_alphanumeric': 0.1311493614658523, 'fraction_numerical': 0.001998889505830094, 'mean_word_length': 1.9850845210473982, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5091780', 'n_tokens_mistral': 2553, 'n_tokens_neox': 2458, 'n_words': 459}