<NME> signin.js.erb
<BEF> angular.module('app').controller('SigninController', function ($scope, $routeParams, $api, $location, $window, $analytics) {
  // Redirect user to homepage if already logged in.
  // Need to wait to see if current_person is explicitly set to false.
  // TODO: This isn't settings teams. Show the sub-menu isn't showing up.
  $scope.$watch('current_person', function(current_person) {
    if (current_person) {
      $api.person_teams(current_person.id).then(function(teams) {
        $scope.teams = teams;
      });
    }
    if ($location.path() === '/signin' && current_person !== false) {
      $location.url("/").replace();
    }
  });

  // probably doesn't belong here... this is how navbar's "Sign Out" is wired
  $scope.signout = $api.signout;

  // these are global... used both on signin page and also in navbar dropdown
  $scope.providers = [
    { id: 'github', name: 'GitHub', image_url: '<%= asset_path("icons/icon_github.svg") %>' },
    { id: 'twitter', name: 'Twitter', image_url: '<%= asset_path("icons/icon_twitter.svg") %>' },
    { id: 'facebook', name: 'Facebook', image_url: '<%= asset_path("icons/icon_facebook.svg") %>' }
  ];
  $scope.signin_url_for = $api.signin_url_for;

  // passed in with a linked account
  $scope.provider = $routeParams.provider;
  $scope.form_data = {
    email: $routeParams.email,
    account_link_id: $routeParams.account_link_id,
    first_name: $routeParams.first_name,
    last_name: $routeParams.last_name,
    display_name: $routeParams.display_name,
    image_url: $routeParams.image_url,
    terms: true
  };

  // If the email changes in the model (this can happen from autofill or query params),
  // kick off the change right away.
  $scope.$watch('form_data.email', $scope.email_changed);

  // this tracks form state
  //   null == don't show errors yet
  //   'pending' == user typed email and blurred it
  //   'signin' == email checked and exists
  //   'signup' == email checked and available
  $scope.signin_or_signup = null;

  // don't show initial validations until form has been submitted
  $scope.show_validations = false;


  $scope.email_changing = function() {
    if ($scope.signin_or_signup!='not_verify') $scope.signin_or_signup = null;
  };

  $scope.email_changed = function() {
    if ($scope.email_previous !== $scope.form_data.email) {
      $scope.email_previous = $scope.form_data.email;
      $scope.signin_or_signup = 'pending';
      $api.check_email_address($scope.form_data.email).then(function(response) {
        if (response.not_verify) {
          $scope.signin_or_signup = "not_verify"
          $scope.error = response.error;
          $scope.message = '';      
        } else if (response.email_is_registered) {
          $scope.signin_or_signup = 'signin';
          $scope.message = '';
        } else {
          $scope.signin_or_signup = 'signup';
          $scope.message = '';
        }
      });
    }
  };

  $scope.follow_trackers_from_route_params = function() {
    if ($routeParams.follow_tracker_ids) {
      var tracker_ids = $routeParams.follow_tracker_ids.split(',');
      for (var i=0; i<tracker_ids.length; i++) {
        $api.tracker_follow(tracker_ids[i]);
      }
    }
  };

  // form submit
  $scope.signin = function() {
    if ($scope.signin_or_signup !== 'pending') {
      $scope.show_validations = true;
      $scope.error = null;

      var payload = angular.copy($scope.form_data);
      payload.mixpanel_id = $analytics.mixpanel_distinct_id();

      $api.signin(payload).then(function(response) {
        if (response.error) {
          $scope.error = response.error;
          $scope.message ='';
        } else {
          // Hack: Follow Trackers whose IDs are appended to the redirect URL.
          $scope.follow_trackers_from_route_params();

          $analytics.signIn({ provider: 'email' });
        }
      });
    }
  };

  $scope.signup = function() {
    if ($scope.signin_or_signup !== 'pending') {
      $scope.show_validations = true;
      $scope.error = null;

      var payload = angular.copy($scope.form_data);
      payload.mixpanel_id = $analytics.mixpanel_distinct_id();

      $api.signup(payload).then(function(response) {
        if (response.error) {
          $scope.error = response.error;
        } else if (response.verify_email_send) {
          $scope.signin_or_signup = "not_verify"
          $scope.verify_email_send = true;
          $scope.error = '';
          $scope.message = "Please check your email to activate your account";
        } else {
          // Hack: Follow Trackers whose IDs are appended to the redirect URL.
          $scope.follow_trackers_from_route_params();

          $analytics.signUp({ provider: $routeParams.provider || 'email' });
        }
      });
    }
  };

  $scope.forgot_password = function() {
    $api.request_password_reset({ email: $scope.form_data.email }).then(function(response) {
      $scope.error = response.message;
      $scope.message = '';
    });
  };

  $scope.resend_verification = function() {
    $api.resend_verification({ email: $scope.form_data.email }).then(function(response) {
      $scope.error = response.message;
      $scope.message = '';
    });
  };
});

<MSG> redirect to signin if user not present and first bounty

<DFF> @@ -94,6 +94,7 @@ angular.module('app').controller('SigninController', function ($scope, $routePar
       payload.mixpanel_id = $analytics.mixpanel_distinct_id();
 
       $api.signin(payload).then(function(response) {
+        console.log('running');
         if (response.error) {
           $scope.error = response.error;
           $scope.message ='';

{'commit': 'diff --git a/app/assets/javascripts/app/issues/show.html.haml b/app/assets/javascripts/app/issues/show.html.haml\nindex dd3c2ad..9cb22f9 100644\n--- a/app/assets/javascripts/app/issues/show.html.haml\n+++ b/app/assets/javascripts/app/issues/show.html.haml\n@@ -69,7 +69,10 @@\n                 %p\n                   Be the first to post a bounty for this issue!\n               .panel-body\n-                %div.text-center\n+                %div.text-center{"ng-if" => "!current_person"}\n+                  %button.btn.btn-light-blue.btn-responsive{"ng-click" => "goToSignInPage()"}\n+                    Sign In\n+                %div.text-center{"ng-if" => "current_person"}\n                   %div There are several ways to post this bounty\n                   %div{"ng-include" => "\'app/issues/templates/contribute_accordian.html\'"}\n           %div.text-center{"ng-if" => "issue.category === \'fiat\'"}\ndiff --git a/app/assets/javascripts/app/issues/show.js b/app/assets/javascripts/app/issues/show.js\nindex d02fe3d..69c145e 100644\n--- a/app/assets/javascripts/app/issues/show.js\n+++ b/app/assets/javascripts/app/issues/show.js\n@@ -78,6 +78,11 @@ angular.module(\'app\').controller(\'IssueShowController\', function ($scope, $api,\n     });\n   }\n \n+  $scope.goToSignInPage = function(){\n+    $api.set_post_auth_url($location.url());\n+    $location.url("/signin");    \n+  }\n+\n   $scope.setUsdAmount = function(amount){\n     $scope.usdCart.amount = amount;\n   }\ndiff --git a/app/assets/javascripts/app/signin/signin.js.erb b/app/assets/javascripts/app/signin/signin.js.erb\nindex 47a0ceb..6f34eb5 100644\n--- a/app/assets/javascripts/app/signin/signin.js.erb\n+++ b/app/assets/javascripts/app/signin/signin.js.erb\n@@ -94,6 +94,7 @@ angular.module(\'app\').controller(\'SigninController\', function ($scope, $routePar\n       payload.mixpanel_id = $analytics.mixpanel_distinct_id();\n \n       $api.signin(payload).then(function(response) {\n+        console.log(\'running\');\n         if (response.error) {\n           $scope.error = response.error;\n           $scope.message =\'\';\n', 'commit_subject': 'redirect to signin if user not present and first bounty', 'repo_name': 'bountysource/core', 'committer': {'name': 'You Jing Wong', 'email': '0b42e9d84b791896767125afd849cd81bd477e0d@gmail.com', 'time_sec': '1527030176', 'tz_offset': '480', 'date': {'seconds': '1527030176'}}, 'commit_tree': 'e460437dde1a74c7121f04517f2bcc2a1f9ca926', 'commit_message': 'redirect to signin if user not present and first bounty\n', 'language_name': 'HTML', 'license': 'mit', 'hunks': "@@ -94,6 +94,7 @@ angular.module('app').controller('SigninController', function ($scope, $routePar\n       payload.mixpanel_id = $analytics.mixpanel_distinct_id();\n \n       $api.signin(payload).then(function(response) {\n+        console.log('running');\n         if (response.error) {\n           $scope.error = response.error;\n           $scope.message ='';\n", 'addition_count': 1, 'deletion_count': 0, 'src_file': 'a/app/assets/javascripts/app/signin/signin.js.erb', 'tgt_file': 'b/app/assets/javascripts/app/signin/signin.js.erb', 'file_extension': '.erb', 'before_file': 'angular.module(\'app\').controller(\'SigninController\', function ($scope, $routeParams, $api, $location, $window, $analytics) {\n  // Redirect user to homepage if already logged in.\n  // Need to wait to see if current_person is explicitly set to false.\n  // TODO: This isn\'t settings teams. Show the sub-menu isn\'t showing up.\n  $scope.$watch(\'current_person\', function(current_person) {\n    if (current_person) {\n      $api.person_teams(current_person.id).then(function(teams) {\n        $scope.teams = teams;\n      });\n    }\n    if ($location.path() === \'/signin\' && current_person !== false) {\n      $location.url("/").replace();\n    }\n  });\n\n  // probably doesn\'t belong here... this is how navbar\'s "Sign Out" is wired\n  $scope.signout = $api.signout;\n\n  // these are global... used both on signin page and also in navbar dropdown\n  $scope.providers = [\n    { id: \'github\', name: \'GitHub\', image_url: \'<%= asset_path("icons/icon_github.svg") %>\' },\n    { id: \'twitter\', name: \'Twitter\', image_url: \'<%= asset_path("icons/icon_twitter.svg") %>\' },\n    { id: \'facebook\', name: \'Facebook\', image_url: \'<%= asset_path("icons/icon_facebook.svg") %>\' }\n  ];\n  $scope.signin_url_for = $api.signin_url_for;\n\n  // passed in with a linked account\n  $scope.provider = $routeParams.provider;\n  $scope.form_data = {\n    email: $routeParams.email,\n    account_link_id: $routeParams.account_link_id,\n    first_name: $routeParams.first_name,\n    last_name: $routeParams.last_name,\n    display_name: $routeParams.display_name,\n    image_url: $routeParams.image_url,\n    terms: true\n  };\n\n  // If the email changes in the model (this can happen from autofill or query params),\n  // kick off the change right away.\n  $scope.$watch(\'form_data.email\', $scope.email_changed);\n\n  // this tracks form state\n  //   null == don\'t show errors yet\n  //   \'pending\' == user typed email and blurred it\n  //   \'signin\' == email checked and exists\n  //   \'signup\' == email checked and available\n  $scope.signin_or_signup = null;\n\n  // don\'t show initial validations until form has been submitted\n  $scope.show_validations = false;\n\n\n  $scope.email_changing = function() {\n    if ($scope.signin_or_signup!=\'not_verify\') $scope.signin_or_signup = null;\n  };\n\n  $scope.email_changed = function() {\n    if ($scope.email_previous !== $scope.form_data.email) {\n      $scope.email_previous = $scope.form_data.email;\n      $scope.signin_or_signup = \'pending\';\n      $api.check_email_address($scope.form_data.email).then(function(response) {\n        if (response.not_verify) {\n          $scope.signin_or_signup = "not_verify"\n          $scope.error = response.error;\n          $scope.message = \'\';      \n        } else if (response.email_is_registered) {\n          $scope.signin_or_signup = \'signin\';\n          $scope.message = \'\';\n        } else {\n          $scope.signin_or_signup = \'signup\';\n          $scope.message = \'\';\n        }\n      });\n    }\n  };\n\n  $scope.follow_trackers_from_route_params = function() {\n    if ($routeParams.follow_tracker_ids) {\n      var tracker_ids = $routeParams.follow_tracker_ids.split(\',\');\n      for (var i=0; i<tracker_ids.length; i++) {\n        $api.tracker_follow(tracker_ids[i]);\n      }\n    }\n  };\n\n  // form submit\n  $scope.signin = function() {\n    if ($scope.signin_or_signup !== \'pending\') {\n      $scope.show_validations = true;\n      $scope.error = null;\n\n      var payload = angular.copy($scope.form_data);\n      payload.mixpanel_id = $analytics.mixpanel_distinct_id();\n\n      $api.signin(payload).then(function(response) {\n        if (response.error) {\n          $scope.error = response.error;\n          $scope.message =\'\';\n        } else {\n          // Hack: Follow Trackers whose IDs are appended to the redirect URL.\n          $scope.follow_trackers_from_route_params();\n\n          $analytics.signIn({ provider: \'email\' });\n        }\n      });\n    }\n  };\n\n  $scope.signup = function() {\n    if ($scope.signin_or_signup !== \'pending\') {\n      $scope.show_validations = true;\n      $scope.error = null;\n\n      var payload = angular.copy($scope.form_data);\n      payload.mixpanel_id = $analytics.mixpanel_distinct_id();\n\n      $api.signup(payload).then(function(response) {\n        if (response.error) {\n          $scope.error = response.error;\n        } else if (response.verify_email_send) {\n          $scope.signin_or_signup = "not_verify"\n          $scope.verify_email_send = true;\n          $scope.error = \'\';\n          $scope.message = "Please check your email to activate your account";\n        } else {\n          // Hack: Follow Trackers whose IDs are appended to the redirect URL.\n          $scope.follow_trackers_from_route_params();\n\n          $analytics.signUp({ provider: $routeParams.provider || \'email\' });\n        }\n      });\n    }\n  };\n\n  $scope.forgot_password = function() {\n    $api.request_password_reset({ email: $scope.form_data.email }).then(function(response) {\n      $scope.error = response.message;\n      $scope.message = \'\';\n    });\n  };\n\n  $scope.resend_verification = function() {\n    $api.resend_verification({ email: $scope.form_data.email }).then(function(response) {\n      $scope.error = response.message;\n      $scope.message = \'\';\n    });\n  };\n});\n', 'message': 'redirect to signin if user not present and first bounty\n', 'author_name': 'You Jing Wong', 'lang': 'js'}