<commit_before>(function() {  // IIFE
  'use strict';

  angular
    .module('brewKeeper')
    .controller('TopNavController', TopNavController);

  TopNavController.$inject = [
    '$rootScope',
    'dataService',
    'recipeService'
  ];

  function TopNavController($rootScope, dataService, recipeService) {
    $rootScope.maxStars = 5;

    var vm = this;
    vm.logout = logout;

    activate();

    ////////////////////////////////////////////////////////////////////////////
    // FUNCTIONS //////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////

    /**
     * Prepare the nav bar.
     */
    function activate() {
      var cookie = dataService.getCredentials();
      dataService.setCredentials(cookie, true);

      dataService.get('/api/whoami/')
        .then(function(response) {
          // If the user still has valid credentials, ensure rootScope has
          // their username
          $rootScope.username = response.data.username;
        })
        .catch(function(error) {
          $rootScope.username = null;
          dataService.clearCredentials();
          recipeService.clearAllCache();
        });

      // Show/hide hamburger
      $(".menu").on('click', function() {
        $('.menu').toggleClass("active");<commit_msg>Initial pass at modified redirect from TopNav if no logged in user<commit_after>(function() {  // IIFE
  'use strict';

  angular
    .module('brewKeeper')
    .controller('TopNavController', TopNavController);

  TopNavController.$inject = [
    '$rootScope',
    'dataService',
    'recipeService'
  ];

  function TopNavController($rootScope, dataService, recipeService) {
    $rootScope.maxStars = 5;

    var vm = this;
    vm.logout = logout;

    activate();

    ////////////////////////////////////////////////////////////////////////////
    // FUNCTIONS //////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////

    /**
     * Prepare the nav bar.
     */
    function activate() {
      var cookie = dataService.getCredentials();
      dataService.setCredentials(cookie, true);

      dataService.get('/api/whoami/')
        .then(function(response) {
          // If the user still has valid credentials, ensure rootScope has
          // their username
          $rootScope.username = response.data.username;
        })
        .catch(function(error) {
          $rootScope.username = null;
          dataService.clearCredentials();
          recipeService.clearAllCache();

          /**
           * TODO: Make this part of $rootScope, have each module register its
           *       public pages
           */
          // Should we redirect?
          var publicPages = [
            "/about",
            "/change-password",
            "/creator-detail",
            "/login",
            "/reset-pw",
            "/send-reset",
            "/signup",
          ];
          if (publicPages[$location.path()]) {
            return;
          }
          // If they are looking for a particular public recipe, the cache is
          // now empty; redirect to public recipe list
          if ($location.path().indexOf('/public') === 0) {
            $location.path('/public');
          }
          // All remaining pages require a logged-in user, so show them the
          // login. Add queryparams of current target to redirect them there
          // once they are logged in.
          $location.path('/login?target=' + $location.path());
        });

      // Show/hide hamburger
      $(".menu").on('click', function() {
        $('.menu').toggleClass("active");
{'fraction_non_alphanumeric': 0.22814097390368576, 'fraction_numerical': 0.0008071025020177562, 'mean_word_length': 1.4095917044718083, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5507811', 'n_tokens_mistral': 898, 'n_tokens_neox': 877, 'n_words': 213}