'use strict';

/* Controllers */
  // signin controller
app.controller('SigninFormController', ['$rootScope','$scope', '$http', '$state','$localStorage', function($rootScope,$scope, $http, $state,$localStorage) {

    $scope.user = {};
    $scope.login = function() {
        var json = JSON.stringify($scope.user);
        $scope.authError = null;
        // Try to login
        $http({method: 'post', url: "../user/login", data: json}).then(function (resp) {
          if(resp.data.status==200){
              $rootScope.loginData = resp.data.user
              $rootScope.loginData.login =true;
              $localStorage.loginData = $rootScope.loginData;
              $state.go("layout.welcome")
          }else{
              $scope.authError = resp.data.message;
          }
      })
    };
  }])
;