Commit dcb80784d5e0b945306e1f272cc1decc4913f722
Exists in
master
and in
1 other branch
Merge branch 'master' of https://git.ucsd.edu/110swag/flashy-frontend
Showing 1 changed file Side-by-side Diff
scripts/controller.js
View file @
dcb8078
1 | +var app = angular.module('flashy.controller', ['ui.router']).config(['$stateProvider', '$urlRouterProvider', '$httpProvider', '$locationProvider', | |
2 | + function ($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) { | |
3 | + $httpProvider.defaults.withCredentials = true; | |
4 | + $httpProvider.defaults.xsrfCookieName = 'csrftoken'; | |
5 | + $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; | |
6 | + }]); | |
7 | + | |
8 | + | |
9 | +app.controller('LoginController', ['$scope', '$state', '$http', function ($scope, $state, $http) { | |
10 | + $.ajaxPrefilter(function (options, originalOptions, jqXHR) { | |
11 | + options.crossDomain = { | |
12 | + crossDomain: true | |
13 | + }; | |
14 | + options.xhrFields = { | |
15 | + withCredentials: true | |
16 | + }; | |
17 | + }); | |
18 | + | |
19 | + $scope.signUp = function (email, password) { | |
20 | + $http.post('https://flashy.cards/api/users/me', JSON.stringify({ | |
21 | + "email": email, | |
22 | + "password": password | |
23 | + })).success(function (data) { | |
24 | + $state.go('dashboard'); | |
25 | + console.log(data); | |
26 | + }); | |
27 | + | |
28 | + }; | |
29 | + | |
30 | + $scope.login = function (email, password) { | |
31 | + $http.post('https://flashy.cards/api/login', JSON.stringify({ | |
32 | + "email": email, | |
33 | + "password": password | |
34 | + })).success(function (data) { | |
35 | + $state.go('dashboard'); | |
36 | + console.log(data); | |
37 | + }); | |
38 | + }; | |
39 | + | |
40 | + | |
41 | +}]); | |
42 | + | |
43 | + | |
44 | +app.controller("HomeController", ['$scope', '$state', function ($scope, $state) { | |
45 | + $state.go('login'); | |
46 | +}]); | |
47 | + | |
48 | +app.controller("FeedController", ['$scope', '$state', function ($scope, $state) { | |
49 | + console.log("Hello from feed"); | |
50 | +}]); | |
51 | + | |
52 | +app.controller("LogoutController", ['$scope', '$state', '$http', function ($scope, $state, $http) { | |
53 | + $http.post('https://flashy.cards/api/logout').success(function () { | |
54 | + $state.go('home'); | |
55 | + }); | |
56 | +}]); | |
57 | + | |
58 | + | |
59 | +app.controller("SidebarController", function ($scope, $state) { | |
60 | + // This gets really annoying every time I refresh the page :( | |
61 | + //alert("HEYYYYYY"); | |
62 | + | |
63 | + | |
64 | +}); |