<commit_before>'use strict';

/**
 * @ngdoc function
 * @name projectVApp.controller:RegisterdialogcontrollerCtrl
 * @description
 * # RegisterdialogcontrollerCtrl
 * Controller of the projectVApp
 */
angular.module('projectVApp')
.controller('registerDialogController',
  ['$scope', '$timeout', '$modalInstance', 'Facebook', 'voteInfoService', 'data', 
  function($scope, $timeout, $modalInstance, Facebook, voteInfoService, data) {
    
  $scope.regscope = {};

  //var ref = new Firebase("https://torid-fire-6233.firebaseio.com/participants");

  //$scope.auth =  $firebaseSimpleLogin(ref,
  //  function(error, user) { 
  //    console.log('error',error);
  //    console.log('user',user);
  //});
  //var sync = $firebase(ref);

  //$scope.myfirebase = null; 

    
  /********************************facebook*****************************/
      
  // Define user empty data :/
  $scope.user = {};
  // Defining user logged status
  $scope.logged = false;
  $scope.fbname = '';
  $scope.unregster = 0;
  $scope.editState = 0;
  
  //$scope.unregsterLoad = false;
  // And some fancy flags to display messages upon user status change
  
  $scope.facebookReady = false;
  /**
   * Watch for Facebook to be ready.
   * There's also the event that could be used
   */
  $scope.$watch(
    function() {
      return Facebook.isReady();
    },
    function(newVal) {
      if (newVal)
        $scope.facebookReady = true;
    }
  );
  
  var userIsConnected = false;
  
  
  /**
   * intentLogin
   */

  $scope.intentLogin = function() {
    //console.log('click login',userIsConnected);
    if(!userIsConnected) {
      $scope.login();
    }
  };
  
  /**
   * Login
   */
   $scope.login = function() {
     Facebook.login(function(response) {
      fbStatusUpdate(response);
      //if (response.status == 'connected') {
      //  fbSetLogin();
      //}
    
    }, {scope: 'publish_stream,publish_actions'});
   };
   
   /**
    * me 
    */

    $scope.me = function() {
      Facebook.api('/me', function(response) {
        /**
         * Using $scope.$apply since this happens outside angular framework.
         */
        $scope.$apply(function() {
          $scope.user = response;


          //console.log('scope.user',$scope.user);
        });
        
      });
    };
  
  /**
   * Logout
   */

  $scope.logout = function() {
    Facebook.logout(function() {
      $scope.$apply(function() {
        $scope.user   = {};
        $scope.logged = false;  
        $scope.fbname = '';
        $scope.unregster = 0;
        $scope.editState = 0;
        //$scope.content = {};
        $scope.regscope.errors = '';
        userIsConnected = false;
      });
    });
  }
  
  /**
   * Taking approach of Events :D
   */

  function fbStatusUpdate(fbdata){
    if (fbdata.status == 'connected') {
      //console.log('response',fbdata);
      $scope.$apply(function() {
        $scope.logged = true;  
        $scope.me();
        //console.log('access_token',fbdata.authResponse.accessToken);
        //$scope.auth.$login('facebook', {access_token: fbdata.authResponse.accessToken});
        //$scope.auth.$login('facebook');
      });
    } else {
      $scope.$apply(function() {
        $scope.logged = false;  
        $scope.fbname = '';
        $scope.editState = 0;
        //$scope.content = {};
        $scope.unregster = 0;
        $scope.user   = {};
      });
    }
  }

  $scope.$on('Facebook:statusChange', function(ev, fbdata) {
    //console.log('Status: ', data);
    fbStatusUpdate(fbdata);
  });


  Facebook.getLoginStatus(function(response) {
    //console.log('fbGetLoginStatus');
    fbStatusUpdate(response);
    if (response.status == 'connected') {
      userIsConnected = true;
    }
  });


  /**
   * intentLogin
   */
  /********************************form*****************************/
  $scope.regscope.selectItems = voteInfoService.supplementItem;
  var selectItems = $scope.regscope.selectItems;

  $scope.regscope.nonAreaSelect = [
    '台北市',
    '新北市',
    '台中市',
    '台南市',
    '高雄市',
  ];
<commit_msg>solve fb login bug 1<commit_after>'use strict';

/**
 * @ngdoc function
 * @name projectVApp.controller:RegisterdialogcontrollerCtrl
 * @description
 * # RegisterdialogcontrollerCtrl
 * Controller of the projectVApp
 */
angular.module('projectVApp')
.controller('registerDialogController',
  ['$scope', '$timeout', '$modalInstance', 'Facebook', 'voteInfoService', 'data', 
  function($scope, $timeout, $modalInstance, Facebook, voteInfoService, data) {
    
  $scope.regscope = {};

  //var ref = new Firebase("https://torid-fire-6233.firebaseio.com/participants");

  //$scope.auth =  $firebaseSimpleLogin(ref,
  //  function(error, user) { 
  //    console.log('error',error);
  //    console.log('user',user);
  //});
  //var sync = $firebase(ref);

  //$scope.myfirebase = null; 

    
  /********************************facebook*****************************/
      
  // Define user empty data :/
  $scope.user = {};
  // Defining user logged status
  $scope.logged = false;
  $scope.fbname = '';
  $scope.unregster = 0;
  $scope.editState = 0;
  
  //$scope.unregsterLoad = false;
  // And some fancy flags to display messages upon user status change
  
  $scope.facebookReady = false;
  /**
   * Watch for Facebook to be ready.
   * There's also the event that could be used
   */
  $scope.$watch(
    function() {
      return Facebook.isReady();
    },
    function(newVal) {
      if (newVal)
        $scope.facebookReady = true;
    }
  );
  
  var userIsConnected = false;
  
  
  /**
   * intentLogin
   */

  $scope.intentLogin = function() {
    //console.log('click login',userIsConnected);
    //if(!userIsConnected) {
      $scope.login();
    //}
  };
  
  /**
   * Login
   */
   $scope.login = function() {
     Facebook.login(function(response) {
      fbStatusUpdate(response);
      //if (response.status == 'connected') {
      //  fbSetLogin();
      //}
    
    }, {scope: 'publish_stream,publish_actions'});
   };
   
   /**
    * me 
    */

    $scope.me = function() {
      Facebook.api('/me', function(response) {
        /**
         * Using $scope.$apply since this happens outside angular framework.
         */
        $scope.$apply(function() {
          $scope.user = response;
          $scope.logged = true;  
          userIsConnected = true;
          //console.log('scope.user',$scope.user);
        });
        
      });
    };
  
  /**
   * Logout
   */

  $scope.logout = function() {
    Facebook.logout(function() {
      $scope.$apply(function() {
        $scope.user   = {};
        $scope.logged = false;  
        userIsConnected = false;
        $scope.fbname = '';
        $scope.unregster = 0;
        $scope.editState = 0;
        //$scope.content = {};
        $scope.regscope.errors = '';
      });
    });
  }
  
  /**
   * Taking approach of Events :D
   */

  function fbStatusUpdate(fbdata){
    if (fbdata.status == 'connected') {
      //console.log('response',fbdata);
      $scope.$apply(function() {
        //$scope.logged = true;  
        $scope.me();
        //console.log('access_token',fbdata.authResponse.accessToken);
        //$scope.auth.$login('facebook', {access_token: fbdata.authResponse.accessToken});
        //$scope.auth.$login('facebook');
      });
    } else {
      $scope.$apply(function() {
        $scope.logged = false;  
        userIsConnected = false;
        $scope.fbname = '';
        $scope.editState = 0;
        //$scope.content = {};
        $scope.unregster = 0;
        $scope.user   = {};
      });
    }
  }

  $scope.$on('Facebook:statusChange', function(ev, fbdata) {
    //console.log('Status: ', data);
    fbStatusUpdate(fbdata);
  });


  Facebook.getLoginStatus(function(response) {
    //console.log('fbGetLoginStatus');
    fbStatusUpdate(response);
  });


  /**
   * intentLogin
   */
  /********************************form*****************************/
  $scope.regscope.selectItems = voteInfoService.supplementItem;
  var selectItems = $scope.regscope.selectItems;

  $scope.regscope.nonAreaSelect = [
    '台北市',
    '新北市',
    '台中市',
    '台南市',
    '高雄市',
  ];

{'fraction_non_alphanumeric': 0.19353649545342835, 'fraction_numerical': 0.0025804866060457113, 'mean_word_length': 2.370186335403727, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2221824', 'n_tokens_mistral': 2632, 'n_tokens_neox': 2563, 'n_words': 425}