From e086f832fbc08c42c5988f6c72da7224691edd9c Mon Sep 17 00:00:00 2001 From: Andrew Buss Date: Tue, 5 May 2015 05:07:23 -0700 Subject: [PATCH] Added a few views. Logout still broken --- config.js | 46 ++++++++++++++++++++++------------ controller.js | 59 +++++++++++++++++++++++++++++++------------- flashy.css | 17 ++++++++++--- home.html | 63 +++-------------------------------------------- templates/dashboard.html | 10 ++++++-- templates/feed.html | 18 +------------- templates/login_form.html | 17 +++++++++++++ 7 files changed, 114 insertions(+), 116 deletions(-) create mode 100644 templates/login_form.html diff --git a/config.js b/config.js index baa5bfe..d040279 100644 --- a/config.js +++ b/config.js @@ -1,21 +1,35 @@ angular.module('flashy', ['flashy.controller']) -.config(['$stateProvider', '$urlRouterProvider', - function ($stateProvider, $urlRouterProvider) { + .config(['$stateProvider', '$urlRouterProvider', + function ($stateProvider, $urlRouterProvider) { - $urlRouterProvider.otherwise('/home'); + $urlRouterProvider.otherwise('/home'); - $stateProvider. - state('home', { - url: '/home', - templateUrl: 'home.html', - controller: 'HomeController' - }). + $stateProvider. + state('home', { + url: '/home', + templateUrl: 'home.html', + controller: 'HomeController' + }). + state('login', { + url: '/login', + templateUrl: 'templates/login_form.html', + controller: 'LoginController' + }). + state('logout', { + url: '/logout', + templateUrl: 'templates/logout.html', + controller: 'LogoutController' + }). + state('dashboard', { + url: '/dashboard', + templateUrl: 'templates/dashboard.html', + controller: 'DashboardController' + }). + state('dashboard.feed', { + url: '/feed', + templateUrl: 'templates/feed.html', + controller: 'FeedController' + }) - state('dashboard', { - url: '/dashboard', - templateUrl: 'templates/dashboard.html', - controller: 'DashboardController' - }) - -}]); + }]); diff --git a/controller.js b/controller.js index 260d553..113b252 100644 --- a/controller.js +++ b/controller.js @@ -3,45 +3,70 @@ var app = angular.module('flashy.controller', ['ui.router']).config(function ($l }); -app.controller('HomeController', ['$scope', '$state', function ($scope, $state) { - - // SIGN UP - $scope.signUp = function (email, username, password) { +app.controller('LoginController', ['$scope', '$state', function ($scope, $state) { + $.ajaxPrefilter(function (options, originalOptions, jqXHR) { + options.crossDomain = { + crossDomain: true + }; + options.xhrFields = { + withCredentials: true + }; + }); + $.postJSON = function (url, data, success, args) { + args = $.extend({ + url: url, + type: 'POST', + data: JSON.stringify(data), + contentType: 'application/json; charset=utf-8', + dataType: 'json', + async: true, + success: success + }, args); + return $.ajax(args); + }; - // make server call - console.log('go to dashboard'); - $.post('https://flashy.cards/api/users/me', + $scope.signUp = function (email, password) { + $.postJSON('https://flashy.cards/api/users/me', {"email": email, "password": password}, function (data, textStatus, jqXHR) { console.log(data); + $scope.$parent.user = data; + $state.go('dashboard'); } ); - // if successful, go to dashboard - $state.go('dashboard'); - }; - - // LOGIN $scope.login = function (email, password) { - - console.log('go to dashboard'); - $.post('https://flashy.cards/api/login', + $.postJSON('https://flashy.cards/api/login', {"email": email, "password": password}, function (data, textStatus, jqXHR) { console.log(data); + $scope.$parent.user = data; + $state.go('dashboard'); } ); + }; - $state.go('dashboard'); +}]); - }; +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', function ($scope, $state) { + $.post('https://flashy.cards/api/logout', function () { + $state.go('home') + }); }]); + app.controller("DashboardController", function () { // This gets really annoying every time I refresh the page :( //alert("HEYYYYYY"); diff --git a/flashy.css b/flashy.css index 155cd41..9f397c2 100644 --- a/flashy.css +++ b/flashy.css @@ -1,5 +1,14 @@ -.myform { - max-width: 400px; - margin-top: 30px; - margin-bottom: 30px; +#loginform input { + margin: 10px; } + +#loginform { + max-width: 400px; + margin: 30px auto; +} + +#sidebar{ + position:absolute; + top:100px; + left:0px; +} \ No newline at end of file diff --git a/home.html b/home.html index fe689e3..9f697fe 100644 --- a/home.html +++ b/home.html @@ -11,68 +11,11 @@ - -
-

Create and share flashcards in real time!

-
-

The System shall enlighten you.

- SWAG -
-
- -
- -
- -
- - -
- -
-
-
- -
- -
- -
- -
-
- - -
-
-
- -
-
- -
- -
-
-
-
-
+
diff --git a/templates/dashboard.html b/templates/dashboard.html index 70d9971..7eeb3af 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -1,5 +1,11 @@ -