diff --git a/scripts/controller.js b/scripts/controller.js new file mode 100644 index 0000000..94c44dc --- /dev/null +++ b/scripts/controller.js @@ -0,0 +1,68 @@ +var app = angular.module('flashy.controller', ['ui.router']).config(['$stateProvider', '$urlRouterProvider', '$httpProvider', '$locationProvider', + function ($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) { + $httpProvider.defaults.withCredentials = true; + $httpProvider.defaults.xsrfCookieName = 'csrftoken'; + $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; + }]); + + +app.controller('LoginController', ['$scope', '$state', '$http', function ($scope, $state, $http) { + $.ajaxPrefilter(function (options, originalOptions, jqXHR) { + options.crossDomain = { + crossDomain: true + }; + options.xhrFields = { + withCredentials: true + }; + }); + + $scope.signUp = function (email, password) { + $http.post('https://flashy.cards/api/users/me', JSON.stringify({ + "email": email, + "password": password + })).success(function (data) { + $state.go('dashboard'); + console.log(data); + }); + + }; + + $scope.login = function (email, password) { + $http.post('https://flashy.cards/api/login', JSON.stringify({ + "email": email, + "password": password + })).success(function (data) { + $state.go('dashboard'); + console.log(data); + }); + }; + + +}]); + + +app.controller("HomeController", ['$scope', '$state', function ($scope, $state) { + $state.go('login'); +}]); + +app.controller("FeedController", ['$scope', '$state', function ($scope, $state) { + console.log("Hello from feed"); +}]); + +app.controller("LogoutController", ['$scope', '$state', '$http', function ($scope, $state, $http) { + $http.post('https://flashy.cards/api/logout').success(function () { + $state.go('home'); + }); +}]); + + +app.controller("SidebarController", function ($scope, $state) { + // This gets really annoying every time I refresh the page :( + //alert("HEYYYYYY"); + + +}); + + + +