<commit_before>angular.module('starter.controllers', ['ng-token-auth'])

.config(function($authProvider) {
  $authProvider.configure({
    apiUrl: 'http://localhost:3000' //your api's url
  });
})

.controller('AppCtrl', function($scope, $ionicModal, $auth, $state) {
  // OAUTH SIGN OUT
  $scope.logout = function() {
    $auth.signOut()
    .then(function(resp) {
      window.localStorage.clear();
      console.log("WUNDABAR!!!");
      $state.go('login');
    })
    .catch(function(resp) {
      console.log("SOMETHING TERRIBLE HAS HAPPENED in the AppCtrl")
    });
  }

      // if (resp.phone_number) {
        // has phonenumber
      // } else {
        // display the page/modal where they enter their phonenumber
        // on that modal, have a button that hits the send_verification_code route
        // then next modal, have a button that hits the verify_code route
        // then the backend needs to save the phone number as valid, ELSE this modal redisplays with errors
      // }
  // };
})


.controller('EnterUserPhoneCtrl', function($scope, $http, $state) {
  $scope.message = {};

  $scope.sendVerificationCode = function(message){
    console.log(message);
    var data = {
      number: message.contact
    };
    var userId = window.localStorage['user_id']
    // post route to backend
    var req = {
      method: 'POST',
      url: 'http://localhost:3000/users/'+userId+'/send_verification_code',
      data: data
    }

    $http(req)
    .success(function(response){
      console.log(response)
      $state.go('app.verify_code')
    })
    .error(function(response){console.log(response)});
  }
})

.controller('VerifyCodeCtrl', function($scope, $http, $state) {
  $scope.verifyCode = function(verificationCode){
    console.log(verificationCode);
    var data = {
      number: verificationCode
    };
    var userId = window.localStorage['user_id']
    var req = {
      method: 'POST',
      url: 'http://localhost:3000/users/'+userId+'/verify_code',
      data: data
    }
    // make sure backend returns a JSON with verification state
    // handle state from there.
    $http(req)
      .success(function(response){
          window.localStorage['phone_verified'] = response.phone_verified;
        $state.go('app.new_message');
      })
      .error(function(response){console.log(response)});
  }
})



// post new message
.controller('NewMessageCtrl', function($scope, $http, $state) {

  if (window.localStorage['activeSession'] !== "true"){
    $state.go('login');
  }
  $scope.message = {};

  $scope.scheduleMessage = function(message){
    console.log(message);
    var data = {
      number: message.contact,
      body: message.content,
      send_at_datetime: message.date
    };
    var userId = localStorage.user_id
  debugger
    // post route to backend
    var req = {
      method: 'POST',
      // url: 'http://localhost:3000/users/1/send_verification_code',
      url: 'http://localhost:3000/users/'+userId+'/messages',
      data: data
    }

    $http(req)
      .success(function(response){console.log(response)})
      .error(function(response){console.log(response)});
  }
})

.controller('LoginCtrl', function($scope, $auth, $state) {<commit_msg>remove unnecessary comments; set .message = {} to clear form after submission<commit_after>angular.module('starter.controllers', ['ng-token-auth'])

.config(function($authProvider) {
  $authProvider.configure({
    apiUrl: 'http://localhost:3000' //your api's url
  });
})

.controller('AppCtrl', function($scope, $ionicModal, $auth, $state) {
  // OAUTH SIGN OUT
  $scope.logout = function() {
    $auth.signOut()
    .then(function(resp) {
      window.localStorage.clear();
      console.log("WUNDABAR!!!");
      $state.go('login');
    })
    .catch(function(resp) {
      console.log("SOMETHING TERRIBLE HAS HAPPENED in the AppCtrl")
    });
  }
})


.controller('EnterUserPhoneCtrl', function($scope, $http, $state) {
  $scope.message = {};

  $scope.sendVerificationCode = function(message){
    console.log(message);
    var data = {
      number: message.contact
    };
    var userId = window.localStorage['user_id']
    // post route to backend
    var req = {
      method: 'POST',
      url: 'http://localhost:3000/users/'+userId+'/send_verification_code',
      data: data
    }

    $http(req)
    .success(function(response){
      console.log(response)
      $state.go('app.verify_code')
    })
    .error(function(response){console.log(response)});
  }
})

.controller('VerifyCodeCtrl', function($scope, $http, $state) {
  $scope.verifyCode = function(verificationCode){
    console.log(verificationCode);
    var data = {
      number: verificationCode
    };
    var userId = window.localStorage['user_id']
    var req = {
      method: 'POST',
      url: 'http://localhost:3000/users/'+userId+'/verify_code',
      data: data
    }
    // make sure backend returns a JSON with verification state
    // handle state from there.
    $http(req)
      .success(function(response){
          window.localStorage['phone_verified'] = response.phone_verified;
        $state.go('app.new_message');
      })
      .error(function(response){console.log(response)});
  }
})



// post new message
.controller('NewMessageCtrl', function($scope, $http, $state) {

  if (window.localStorage['activeSession'] !== "true"){
    $state.go('login');
  }
  $scope.message = {};

  $scope.scheduleMessage = function(message){
    console.log(message);
    var data = {
      number: message.contact,
      body: message.content,
      send_at_datetime: message.date
    };
    var userId = localStorage.user_id
    // post route to backend
    var req = {
      method: 'POST',
      url: 'http://localhost:3000/users/'+userId+'/messages',
      data: data
    }


    $http(req)
      .success(function(response){
        console.log(response)
        $scope.message = {};
      })
      .error(function(response){console.log(response)});
  }
})

.controller('LoginCtrl', function($scope, $auth, $state) {
{'fraction_non_alphanumeric': 0.1569767441860465, 'fraction_numerical': 0.006146179401993355, 'mean_word_length': 3.0033244680851063, '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': '7353276', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1853, 'n_words': 366}