<commit_before>import Ember from 'ember';

export default Ember.Controller.extend({
  isAuthenticated: false,
  remember: false,
  currentTransition: null,
  errorMessage: '',
  errorFields:{},
  validator: Ember.inject.controller('validator'),
  whiteList: ['index', 'scoreboard', 'about', 'home'],
  user: {},
  inwhiteList: function(string){
    if ( this.get('whiteList').indexOf(string)>=0 ) {
      return true;
    }
    else {
      return false;
    }
  },
  checkLoggedIn: function(callback){
    if(this.get('isAuthenticated')){
      callback(true);
    } else {
      var t = this;
      var namespace = t.store.adapterFor('application').namespace;
      Ember.$.get(namespace+'/session', function(data){
        if(data.success){
          if(data.team){
            var user = {
              'team_id': data.team,
              'team': t.store.findRecord('team', data.team),
            };
            t.set('user', user);
          }
          t.set('isAuthenticated', true);
          callback(true);
        } else {
          callback(false);
        }
      });
    }
  },
  isRemembered: function(){
    //if (localStorage.getItem('isAuthenticated') === 'true') {
    //  this.set('isAuthenticated', true);
    //}
    return this.get('isAuthenticated');
  },
  login: function(credentials, callback){
    var t = this;
    var currentTransition = t.get('currentTransition');
    var validator = this.get('validator');

    // Make sure the form is valid
    if (!validator.isvalidLogin(credentials)) {
      t.set('errorMessage', validator.get('error'));
      t.set('errorFields', validator.get('errorFields'));
      callback(false);
    }
    // Form is valid clear the error message field and authenticate the team
    else {
      var data = {
        'username': credentials.teamName,
        'password': <PASSWORD>,
      };
      
      // Server communication
      var namespace = this.store.adapterFor('application').namespace;
      Ember.$.post(namespace+'/session', data, function(data){
        if(data.success){
          var user = {
            'team_id': data.team,
            'team': null,
          };
          t.set('user', user);
          
          // Set is authenticated to true
          t.set('isAuthenticated', true);

          // If the user clicked the remember me check box set is auth in local storage
          if (credentials.rememberMe === true) {
            localStorage.setItem("isAuthenticated", true); 
          }

          // If the the user was redirected to authenticate send them to the page they originally requested
          if ( currentTransition ) {
            t.set('currentTransition', null);
            currentTransition.retry();
          }
          t.set('errorMessage', '');
          t.set('errorFields', {});
          callback(true);
        } else {
          validator.invalidLogin();
          t.set('errorMessage', validator.get('error'));
          t.set('errorFields', validator.get('errorFields'));
          callback(false);
        }
      }).error(function() {
        validator.invalidLogin();
        t.set('errorMessage', validator.get('error'));
        t.set('errorFields', validator.get('errorFields'));
        callback(false);
      });
    }
  },
  register: function(registrationData){
    var t = this;
    var validator = this.get('validator');
    var authenticationData = {};

    // Make sure the form is valid
    if (!validator.isvalidRegister(registrationData)) {
      t.set('errorMessage', validator.get('error'));
      t.set('errorFields', validator.get('errorFields'));
    }
    // Form is valid clear the error message field and register and login the team 
    else {
      t.set('errorMessage', '');
      t.set('errorFields', {});
      authenticationData = {'teamName': registrationData.teamName, 'password': <PASSWORD> };
      registrationData = null;
      this.login(authenticationData);
    }
  },
  logout: function(){
    // Send logout request to server
    var namespace = this.store.adapterFor('application').namespace;
    Ember.$.ajax({url: namespace+'/session',type: 'DELETE'});

    // Do the deauthentication stuff here
    this.set('user', {});
    this.set('isAuthenticated', false);
    localStorage.removeItem('isAuthenticated');
    

    // Redirect to the home page
    this.transitionToRoute('application');
  },
});<commit_msg>Changed logout to transition to home<commit_after>import Ember from 'ember';

export default Ember.Controller.extend({
  isAuthenticated: false,
  remember: false,
  currentTransition: null,
  errorMessage: '',
  errorFields:{},
  validator: Ember.inject.controller('validator'),
  whiteList: ['index', 'scoreboard', 'about', 'home'],
  user: {},
  inwhiteList: function(string){
    if ( this.get('whiteList').indexOf(string)>=0 ) {
      return true;
    }
    else {
      return false;
    }
  },
  checkLoggedIn: function(callback){
    if(this.get('isAuthenticated')){
      callback(true);
    } else {
      var t = this;
      var namespace = t.store.adapterFor('application').namespace;
      Ember.$.get(namespace+'/session', function(data){
        if(data.success){
          if(data.team){
            var user = {
              'team_id': data.team,
              'team': t.store.findRecord('team', data.team),
            };
            t.set('user', user);
          }
          t.set('isAuthenticated', true);
          callback(true);
        } else {
          callback(false);
        }
      });
    }
  },
  isRemembered: function(){
    //if (localStorage.getItem('isAuthenticated') === 'true') {
    //  this.set('isAuthenticated', true);
    //}
    return this.get('isAuthenticated');
  },
  login: function(credentials, callback){
    var t = this;
    var currentTransition = t.get('currentTransition');
    var validator = this.get('validator');

    // Make sure the form is valid
    if (!validator.isvalidLogin(credentials)) {
      t.set('errorMessage', validator.get('error'));
      t.set('errorFields', validator.get('errorFields'));
      callback(false);
    }
    // Form is valid clear the error message field and authenticate the team
    else {
      var data = {
        'username': credentials.teamName,
        'password': <PASSWORD>,
      };
      
      // Server communication
      var namespace = this.store.adapterFor('application').namespace;
      Ember.$.post(namespace+'/session', data, function(data){
        if(data.success){
          var user = {
            'team_id': data.team,
            'team': null,
          };
          t.set('user', user);
          
          // Set is authenticated to true
          t.set('isAuthenticated', true);

          // If the user clicked the remember me check box set is auth in local storage
          if (credentials.rememberMe === true) {
            localStorage.setItem("isAuthenticated", true); 
          }

          // If the the user was redirected to authenticate send them to the page they originally requested
          if ( currentTransition ) {
            t.set('currentTransition', null);
            currentTransition.retry();
          }
          t.set('errorMessage', '');
          t.set('errorFields', {});
          callback(true);
        } else {
          validator.invalidLogin();
          t.set('errorMessage', validator.get('error'));
          t.set('errorFields', validator.get('errorFields'));
          callback(false);
        }
      }).error(function() {
        validator.invalidLogin();
        t.set('errorMessage', validator.get('error'));
        t.set('errorFields', validator.get('errorFields'));
        callback(false);
      });
    }
  },
  register: function(registrationData){
    var t = this;
    var validator = this.get('validator');
    var authenticationData = {};

    // Make sure the form is valid
    if (!validator.isvalidRegister(registrationData)) {
      t.set('errorMessage', validator.get('error'));
      t.set('errorFields', validator.get('errorFields'));
    }
    // Form is valid clear the error message field and register and login the team 
    else {
      t.set('errorMessage', '');
      t.set('errorFields', {});
      authenticationData = {'teamName': registrationData.teamName, 'password': <PASSWORD> };
      registrationData = null;
      this.login(authenticationData);
    }
  },
  logout: function(){
    // Send logout request to server
    var namespace = this.store.adapterFor('application').namespace;
    Ember.$.ajax({url: namespace+'/session',type: 'DELETE'});

    // Do the deauthentication stuff here
    this.set('user', {});
    this.set('isAuthenticated', false);
    localStorage.removeItem('isAuthenticated');
    

    // Redirect to the home page
    this.transitionToRoute('home');
  },
});
{'fraction_non_alphanumeric': 0.14650262018683072, 'fraction_numerical': 0.000227842333105491, 'mean_word_length': 2.415953307392996, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '335126', 'n_tokens_mistral': 2471, 'n_tokens_neox': 2466, 'n_words': 547}