Commit 35387f3081af4278d6a9566867b4ec7170285b30
1 parent
5132f0e87c
Exists in
master
and in
1 other branch
cleaned up userservice stuff
Showing 5 changed files with 48 additions and 41 deletions Inline Diff
config.js
View file @
35387f3
angular.module('flashy', [ | 1 | 1 | angular.module('flashy', [ | |
'flashy.LogoutController', | 2 | 2 | 'flashy.LogoutController', | |
'flashy.LoginController', | 3 | 3 | 'flashy.LoginController', | |
'flashy.RootController', | 4 | 4 | 'flashy.RootController', | |
'flashy.FeedController', | 5 | 5 | 'flashy.FeedController', | |
'flashy.DeckController', | 6 | 6 | 'flashy.DeckController', | |
'flashy.ClassAddController', | 7 | 7 | 'flashy.ClassAddController', | |
'flashy.RequestResetController', | 8 | 8 | 'flashy.RequestResetController', | |
'flashy.StudyController', | 9 | 9 | 'flashy.StudyController', | |
'flashy.UserService', | 10 | 10 | 'flashy.UserService', | |
'flashy.FlashcardDirective', | 11 | 11 | 'flashy.FlashcardDirective', | |
'flashy.ResetPasswordController', | 12 | 12 | 'flashy.ResetPasswordController', | |
'flashy.VerifyEmailController', | 13 | 13 | 'flashy.VerifyEmailController', | |
'flashy.CardListController', | 14 | 14 | 'flashy.CardListController', | |
'ngCookies']). | 15 | 15 | 'ngCookies']). | |
config(function($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) { | 16 | 16 | config(function($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) { | |
'use strict'; | 17 | 17 | 'use strict'; | |
$httpProvider.defaults.withCredentials = true; | 18 | 18 | $httpProvider.defaults.withCredentials = true; | |
$httpProvider.defaults.xsrfCookieName = 'csrftoken'; | 19 | 19 | $httpProvider.defaults.xsrfCookieName = 'csrftoken'; | |
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; | 20 | 20 | $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; | |
21 | 21 | |||
var arrayMethods = Object.getOwnPropertyNames(Array.prototype); | 22 | 22 | var arrayMethods = Object.getOwnPropertyNames(Array.prototype); | |
arrayMethods.forEach(attachArrayMethodsToNodeList); | 23 | 23 | arrayMethods.forEach(attachArrayMethodsToNodeList); | |
function attachArrayMethodsToNodeList(methodName) { | 24 | 24 | function attachArrayMethodsToNodeList(methodName) { | |
if (methodName !== 'length') { | 25 | 25 | if (methodName !== 'length') { | |
NodeList.prototype[methodName] = Array.prototype[methodName]; | 26 | 26 | NodeList.prototype[methodName] = Array.prototype[methodName]; | |
} | 27 | 27 | } | |
}; | 28 | 28 | }; | |
29 | 29 | |||
$httpProvider.interceptors.push(function($q) { | 30 | 30 | $httpProvider.interceptors.push(function($q) { | |
return { | 31 | 31 | return { | |
'responseError': function(rejection) { | 32 | 32 | 'responseError': function(rejection) { | |
if (rejection.status >= 500) { | 33 | 33 | if (rejection.status >= 500) { | |
console.log('got error'); | 34 | 34 | console.log('got error'); | |
console.log(rejection); | 35 | 35 | console.log(rejection); | |
$('body').html('<div class="card">Sorry, the server is not serving requests properly. Try again later</div>'); | 36 | 36 | $('body').html('<div class="card">Sorry, the server is not serving requests properly. Try again later</div>'); | |
} | 37 | 37 | } | |
return $q.reject(rejection); | 38 | 38 | return $q.reject(rejection); | |
} | 39 | 39 | } | |
}; | 40 | 40 | }; | |
}); | 41 | 41 | }); | |
$locationProvider.html5Mode(true); | 42 | 42 | $locationProvider.html5Mode(true); | |
$urlRouterProvider.otherwise('/login'); | 43 | 43 | $urlRouterProvider.otherwise('/404'); | |
var auth_resolve = { | 44 | 44 | var auth_resolve = { | |
authorize: function($q, UserService) { | 45 | 45 | authorize: function($q, $state, UserService) { | |
console.log('resolving user before continuing'); | 46 | 46 | console.log('resolving user before continuing'); | |
return UserService.getUserData(); | 47 | 47 | var redirectAsNeeded = function() { | |
48 | if (!UserService.isLoggedIn()) { | |||
49 | console.log(UserService.getUserData()); | |||
50 | console.log('making the user log in'); | |||
51 | $state.go('login'); | |||
52 | } | |||
53 | }; | |||
54 | if (UserService.isResolved()) return redirectAsNeeded(); | |||
55 | return UserService.getUserData().then(redirectAsNeeded); | |||
} | 48 | 56 | } | |
}; | 49 | 57 | }; | |
$stateProvider. | 50 | 58 | $stateProvider. | |
state('login', { | 51 | 59 | state('login', { | |
url: '/login', | 52 | 60 | url: '/login', | |
templateUrl: 'templates/login.html', | 53 | 61 | templateUrl: 'templates/login.html', | |
controller: 'LoginController' | 54 | 62 | controller: 'LoginController' | |
}). | 55 | 63 | }). | |
state('logout', { | 56 | 64 | state('logout', { | |
resolve: auth_resolve, | 57 | 65 | resolve: auth_resolve, | |
url: '/logout', | 58 | 66 | url: '/logout', | |
templateUrl: 'templates/logout.html', | 59 | 67 | templateUrl: 'templates/logout.html', | |
controller: 'LogoutController' | 60 | 68 | controller: 'LogoutController' | |
}). | 61 | 69 | }). | |
state('root', { | 62 | 70 | state('root', { | |
resolve: auth_resolve, | 63 | 71 | resolve: auth_resolve, | |
url: '', | 64 | 72 | url: '', | |
templateUrl: 'templates/root.html', | 65 | 73 | templateUrl: 'templates/root.html', | |
controller: 'RootController' | 66 | 74 | controller: 'RootController' | |
}). | 67 | 75 | }). | |
state('feed', { | 68 | 76 | state('feed', { | |
resolve: auth_resolve, | 69 | 77 | resolve: auth_resolve, | |
url: '/feed/{sectionId}', | 70 | 78 | url: '/feed/{sectionId}', | |
templateUrl: 'templates/feed.html', | 71 | 79 | templateUrl: 'templates/feed.html', | |
controller: 'FeedController' | 72 | 80 | controller: 'FeedController' | |
}). | 73 | 81 | }). | |
state('cardlist', { | 74 | 82 | state('cardlist', { | |
resolve: auth_resolve, | 75 | 83 | resolve: auth_resolve, | |
url: '/cards/{sectionId}', | 76 | 84 | url: '/cards/{sectionId}', | |
templateUrl: 'templates/cardlist.html', | 77 | 85 | templateUrl: 'templates/cardlist.html', | |
controller: 'CardListController' | 78 | 86 | controller: 'CardListController' | |
}). | 79 | 87 | }). | |
state('addclass', { | 80 | 88 | state('addclass', { | |
resolve: auth_resolve, | 81 | 89 | resolve: auth_resolve, | |
url: '/addclass', | 82 | 90 | url: '/addclass', | |
templateUrl: 'templates/addclass.html', | 83 | 91 | templateUrl: 'templates/addclass.html', | |
controller: 'ClassAddController' | 84 | 92 | controller: 'ClassAddController' | |
}). | 85 | 93 | }). | |
state('deck', { | 86 | 94 | state('deck', { | |
resolve: auth_resolve, | 87 | 95 | resolve: auth_resolve, | |
url: '/deck/{sectionId}', | 88 | 96 | url: '/deck/{sectionId}', | |
templateUrl: 'templates/deck.html', | 89 | 97 | templateUrl: 'templates/deck.html', | |
controller: 'DeckController' | 90 | 98 | controller: 'DeckController' | |
}). | 91 | 99 | }). | |
state('study', { | 92 | 100 | state('study', { | |
resolve: auth_resolve, | 93 | 101 | resolve: auth_resolve, | |
url: '/study', | 94 | 102 | url: '/study', | |
templateUrl: 'templates/study.html', | 95 | 103 | templateUrl: 'templates/study.html', | |
controller: 'StudyController' | 96 | 104 | controller: 'StudyController' | |
}). | 97 | 105 | }). | |
state('flashcard', { | 98 | 106 | state('flashcard', { | |
resolve: auth_resolve, | 99 | 107 | resolve: auth_resolve, | |
url: '/flashcard', | 100 | 108 | url: '/flashcard', | |
templateUrl: 'templates/flashcard.html', | 101 | 109 | templateUrl: 'templates/flashcard.html', | |
controller: 'FlashcardController' | 102 | 110 | controller: 'FlashcardController' | |
}). | 103 | 111 | }). | |
state('requestpasswordreset', { | 104 | 112 | state('requestpasswordreset', { | |
url: '/requestpasswordreset', | 105 | 113 | url: '/requestpasswordreset', | |
templateUrl: 'templates/requestpasswordreset.html', | 106 | 114 | templateUrl: 'templates/requestpasswordreset.html', | |
controller: 'RequestResetController' | 107 | 115 | controller: 'RequestResetController' | |
}). | 108 | 116 | }). | |
state('resetpassword', { | 109 | 117 | state('resetpassword', { | |
url: '/resetpassword/{uid}/{token}', | 110 | 118 | url: '/resetpassword/{uid}/{token}', | |
templateUrl: 'templates/resetpassword.html', | 111 | 119 | templateUrl: 'templates/resetpassword.html', | |
controller: 'ResetPasswordController' | 112 | 120 | controller: 'ResetPasswordController' | |
}). | 113 | 121 | }). | |
state('verifyemail', { | 114 | 122 | state('verifyemail', { | |
resolve: auth_resolve, | 115 | 123 | resolve: auth_resolve, | |
url: '/verifyemail/{key}', | 116 | 124 | url: '/verifyemail/{key}', | |
templateUrl: 'templates/verifyemail.html', | 117 | 125 | templateUrl: 'templates/verifyemail.html', | |
controller: 'VerifyEmailController' | 118 | 126 | controller: 'VerifyEmailController' | |
127 | }). | |||
128 | state('404', { | |||
129 | url: '/404', | |||
130 | template: "<h1>This page doesn't exist!</h1>" | |||
}); | 119 | 131 | }); | |
}). | 120 | 132 | }). | |
run(function($rootScope, $state, $stateParams, $location, UserService) { | 121 | 133 | run(function($rootScope, $state, $stateParams, $location, UserService) { | |
$rootScope.$on('$stateChangeStart', function(event, toState, toStateParams) { | 122 | |||
if (toState.name == 'login') { | 123 | |||
if (UserService.isLoggedIn()) return console.log('already logged in') + $state.go('addclass'); | 124 | |||
else return console.log('we are going to login anyway'); | 125 | |||
} | 126 | |||
if (UserService.isLoggedIn()) return console.log('no login required; going straight to ' + toState.name); | 127 | |||
$rootScope.returnToState = toState; | 128 | |||
$rootScope.returnToStateParams = toStateParams; | 129 | |||
console.log('going to ' + toState.name + ' after login'); | 130 | |||
event.preventDefault(); | 131 | |||
$state.go('login'); | 132 | |||
133 | ||||
}); | 134 | |||
$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { | 135 | 134 | $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { | |
console.log('failed to change state: ' + error); | 136 | 135 | console.log('failed to change state: ' + error); | |
$state.go('login'); | 137 | 136 | $state.go('login'); | |
}); | 138 | 137 | }); | |
}); | 139 | 138 | }); |
home.html
View file @
35387f3
<!DOCTYPE html> | 1 | 1 | <!DOCTYPE html> | |
<html ng-app="flashy"> | 2 | 2 | <html ng-app="flashy"> | |
<base href="/app/"> | 3 | 3 | <base href="/app/"> | |
<head> | 4 | 4 | <head> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/> | 5 | 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/> | |
<link rel="stylesheet" | 6 | 6 | <link rel="stylesheet" | |
href="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.0/angular-material.min.css"> | 7 | 7 | href="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.0/angular-material.min.css"> | |
8 | 8 | |||
<link rel="stylesheet" href="styles/flashier.css"/> | 9 | 9 | <link rel="stylesheet" href="styles/flashier.css"/> | |
<link rel="stylesheet" href="styles/flashy.css"/> | 10 | 10 | <link rel="stylesheet" href="styles/flashy.css"/> | |
<link href='https://fonts.googleapis.com/css?family=Titillium+Web:200,200italic,300,600,400,900,700,400italic,700italic,300italic,600italic' | 11 | 11 | <link href='https://fonts.googleapis.com/css?family=Titillium+Web:200,200italic,300,600,400,900,700,400italic,700italic,300italic,600italic' | |
rel='stylesheet' type='text/css'> | 12 | 12 | rel='stylesheet' type='text/css'> | |
<title>Flashy</title> | 13 | 13 | <title>Flashy</title> | |
</head> | 14 | 14 | </head> | |
<body ng-controller="RootController"> | 15 | 15 | <body ng-controller="RootController"> | |
<header> | 16 | 16 | <header> | |
<nav> | 17 | 17 | <nav> | |
<div class="nav-wrapper"> | 18 | 18 | <div class="nav-wrapper"> | |
<a ng-show="user" href="#" data-activates="mobile-demo" class="left button-collapse hide-on-med-and-up"><i | 19 | 19 | <a ng-show="user" href="#" data-activates="mobile-demo" class="left button-collapse hide-on-med-and-up"><i | |
class="mdi-navigation-menu"></i></a> | 20 | 20 | class="mdi-navigation-menu"></i></a> | |
<ul ng-show="currentSection.id && UserService.isLoggedIn()" class="left hide-on-small-and-down"> | 21 | 21 | <ul ng-show="currentSection.id && UserService.isLoggedIn()" class="left hide-on-small-and-down"> | |
<li ui-sref-active="active"><a ui-sref="feed({sectionId:currentSection.id})" class="tooltipped" | 22 | 22 | <li ui-sref-active="active"><a ui-sref="feed({sectionId:currentSection.id})" class="tooltipped" | |
data-position="bottom" | 23 | 23 | data-position="bottom" | |
data-delay="50" data-tooltip="Feed"><i | 24 | 24 | data-delay="50" data-tooltip="Feed"><i | |
class="mdi-action-view-module"></i></a></li> | 25 | 25 | class="mdi-action-view-module"></i></a></li> | |
<li ui-sref-active="active"><a ui-sref="deck({sectionId:currentSection.id})" class="tooltipped" | 26 | 26 | <li ui-sref-active="active"><a ui-sref="deck({sectionId:currentSection.id})" class="tooltipped" | |
data-position="bottom" | 27 | 27 | data-position="bottom" | |
data-delay="50" data-tooltip="Deck"><i | 28 | 28 | data-delay="50" data-tooltip="Deck"><i | |
class="mdi-action-view-carousel"></i></a></li> | 29 | 29 | class="mdi-action-view-carousel"></i></a></li> | |
<li ui-sref-active="active"><a ui-sref="cardlist({sectionId:currentSection.id})" class="tooltipped" | 30 | 30 | <li ui-sref-active="active"><a ui-sref="cardlist({sectionId:currentSection.id})" class="tooltipped" | |
data-position="bottom" | 31 | 31 | data-position="bottom" | |
data-delay="50" data-tooltip="Card List"><i | 32 | 32 | data-delay="50" data-tooltip="Card List"><i | |
class="mdi-action-view-list"></i></a></li> | 33 | 33 | class="mdi-action-view-list"></i></a></li> | |
</ul> | 34 | 34 | </ul> | |
<a href="#" class="brand-logo center">Flashy</a> | 35 | 35 | <a href="#" class="brand-logo center">Flashy</a> | |
36 | 36 | |||
<ul ng-show="UserService.isLoggedIn()" id="nav-mobile" class="right hide-on-small-and-down"> | 37 | 37 | <ul ng-show="UserService.isLoggedIn()" id="nav-mobile" class="right hide-on-small-and-down"> | |
<!-- User's classes dropdown --> | 38 | 38 | <!-- User's classes dropdown --> | |
<ul id="dropdown1" class="dropdown-content"> | 39 | 39 | <ul id="dropdown1" class="dropdown-content"> | |
<li ui-sref-active="active" ng-repeat="section in UserService.getUserData().sections"> | 40 | 40 | <li ui-sref-active="active" ng-repeat="section in UserService.getUserData().sections"> | |
<a class="class bold" ui-sref="feed({sectionId:section.id})">{{section.short_name}}</a> | 41 | 41 | <a class="class bold" ui-sref="feed({sectionId:section.id})">{{section.short_name}}</a> | |
</li> | 42 | 42 | </li> | |
<li class="divider"></li> | 43 | 43 | <li class="divider"></li> | |
<li><a ui-sref="addclass">Add Class</a></li> | 44 | 44 | <li><a ui-sref="addclass">Add Class</a></li> | |
</ul> | 45 | 45 | </ul> | |
<li><a class="dropdown-button ng-cloak" href="#!" data-activates="dropdown1">{{currentSection.id?currentSection.short_name:"Classes"}}<i | 46 | 46 | <li><a class="dropdown-button ng-cloak" href="#!" data-activates="dropdown1">{{currentSection.id?currentSection.short_name:"Classes"}}<i | |
class="mdi-navigation-arrow-drop-down right"></i></a></li> | 47 | 47 | class="mdi-navigation-arrow-drop-down right"></i></a></li> | |
<li><a ui-sref="study">Study</a></li> | 48 | 48 | <li><a ui-sref="study">Study</a></li> | |
<li><a ui-sref="logout">Logout</a></li> | 49 | 49 | <li><a ui-sref="logout">Logout</a></li> | |
</ul> | 50 | 50 | </ul> | |
51 | 51 | |||
<!-- Slide-in side-nav for small screens --> | 52 | 52 | <!-- Slide-in side-nav for small screens --> | |
<ul ng-show="currentSection.id && UserService.isLoggedIn()" class="side-nav" id="mobile-demo"> | 53 | 53 | <ul class="side-nav" id="mobile-demo"> | |
<li ui-sref-active="active"><a ui-sref="feed({sectionId:currentSection.id})" class="tooltipped" | 54 | 54 | <span ng-show="currentSection.id && UserService.isLoggedIn()"> | |
><i | 55 | 55 | <li ui-sref-active="active"><a ui-sref="feed({sectionId:currentSection.id})" class="tooltipped" | |
class="mdi-action-view-module left"></i>Feed</a></li> | 56 | 56 | ><i | |
<li ui-sref-active="active"><a ui-sref="deck({sectionId:currentSection.id})" class="tooltipped" | 57 | 57 | class="mdi-action-view-module left"></i>Feed</a></li> | |
><i | 58 | 58 | <li ui-sref-active="active"><a ui-sref="deck({sectionId:currentSection.id})" class="tooltipped" | |
class="mdi-action-view-carousel left"></i>Deck</a></li> | 59 | 59 | ><i | |
<li ui-sref-active="active"><a ui-sref="cardlist({sectionId:currentSection.id})" class="tooltipped" | 60 | 60 | class="mdi-action-view-carousel left"></i>Deck</a></li> | |
><i | 61 | 61 | <li ui-sref-active="active"><a ui-sref="cardlist({sectionId:currentSection.id})" class="tooltipped" | |
class="mdi-action-view-list left"></i>Card List</a> | 62 | 62 | ><i | |
</li> | 63 | 63 | class="mdi-action-view-list left"></i>Card List</a> | |
<hr> | 64 | 64 | </li> | |
65 | 65 | <hr> | ||
66 | </span> | |||
<!-- Collapsible menu for all the User's classes --> | 66 | 67 | <!-- Collapsible menu for all the User's classes --> | |
<ul class="collapsible" data-collapsible="accordion"> | 67 | 68 | <ul class="collapsible" data-collapsible="accordion"> | |
<li class="bold"> | 68 | 69 | <li class="bold"> | |
<a class="collapsible-header black-text"> | 69 | 70 | <a class="collapsible-header black-text"> | |
Classes<i | 70 | 71 | Classes<i | |
class="mdi-navigation-arrow-drop-down right"></i> | 71 | 72 | class="mdi-navigation-arrow-drop-down right"></i> | |
</a> | 72 | 73 | </a> | |
</li> | 73 | 74 | </li> | |
<div class="collapsible-body" style="display: block"> | 74 | 75 | <div class="collapsible-body" style="display: block"> | |
<ul> | 75 | 76 | <ul> | |
<li ui-sref-active="active" ng-repeat="section in sections"> | 76 | 77 | <li ui-sref-active="active" ng-repeat="section in sections"> | |
<a class="class bold" ui-sref="feed({sectionId:section.id})">{{section.short_name}}</a> | 77 | 78 | <a class="class bold" ui-sref="feed({sectionId:section.id})">{{section.short_name}}</a> | |
</li> | 78 | 79 | </li> | |
<hr> | 79 | 80 | <hr> | |
<li><a ui-sref="addclass"><i class="tiny mdi-content-add"> Add Class</i></a></li> | 80 | 81 | <li><a ui-sref="addclass"><i class="tiny mdi-content-add"> Add Class</i></a></li> | |
</ul> | 81 | 82 | </ul> | |
</div> | 82 | 83 | </div> | |
</ul> | 83 | 84 | </ul> | |
<li><a ui-sref="study">Study</a></li> | 84 | 85 | <li><a ui-sref="study">Study</a></li> | |
<li><a ui-sref="logout">Logout</a></li> | 85 | 86 | <li><a ui-sref="logout">Logout</a></li> | |
</ul> | 86 | 87 | </ul> | |
</div> | 87 | 88 | </div> | |
</nav> | 88 | 89 | </nav> | |
89 | 90 | |||
</header> | 90 | 91 | </header> | |
91 | 92 | |||
92 | 93 | |||
<!-- Menu Bar --> | 93 | 94 | <!-- Menu Bar --> | |
<main ui-view></main> | 94 | 95 | <main ui-view></main> | |
<footer class="page-footer"> | 95 | 96 | <footer class="page-footer"> | |
<div class="footer-copyright"> | 96 | 97 | <div class="footer-copyright"> | |
<div class="container"> | 97 | 98 | <div class="container"> | |
Concerns? Contact us by <a class="grey-text text-lighten-4" href="mailto:halp@flashy.cards">email</a>! | 98 | 99 | Concerns? Contact us by <a class="grey-text text-lighten-4" href="mailto:halp@flashy.cards">email</a>! | |
</div> | 99 | 100 | </div> | |
</div> | 100 | 101 | </div> | |
</footer> | 101 | 102 | </footer> | |
</body> | 102 | 103 | </body> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.js"></script> | 103 | 104 | <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.14/angular-ui-router.js"></script> | 104 | 105 | <script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.14/angular-ui-router.js"></script> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-cookies.js"></script> | 105 | 106 | <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-cookies.js"></script> | |
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script> | 106 | 107 | <script src="//code.jquery.com/jquery-2.1.4.min.js"></script> | |
<script type="text/javascript" src="scripts/materialize.js"></script> | 107 | 108 | <script type="text/javascript" src="scripts/materialize.js"></script> | |
<script type="text/javascript" src="scripts/jquery.collapsible.js"></script> | 108 | 109 | <script type="text/javascript" src="scripts/jquery.collapsible.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.0/angular-material.min.js"></script> | 109 | 110 | <script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.0/angular-material.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-animate.min.js"></script> | 110 | 111 | <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-animate.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-aria.min.js"></script> | 111 | 112 | <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-aria.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-resource.min.js"></script> | 112 | 113 | <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-resource.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-filter/0.5.4/angular-filter.js"></script> | 113 | 114 | <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-filter/0.5.4/angular-filter.js"></script> | |
114 | 115 | |||
115 | 116 | |||
<script src="config.js"></script> | 116 | 117 | <script src="config.js"></script> | |
117 | 118 | |||
<!-- Controllers --> | 118 | 119 | <!-- Controllers --> | |
<script src="scripts/FeedController.js"></script> | 119 | 120 | <script src="scripts/FeedController.js"></script> | |
<script src="scripts/RootController.js"></script> | 120 | 121 | <script src="scripts/RootController.js"></script> | |
<script src="scripts/LoginController.js"></script> | 121 | 122 | <script src="scripts/LoginController.js"></script> | |
<script src="scripts/LogoutController.js"></script> | 122 | 123 | <script src="scripts/LogoutController.js"></script> | |
<script src="scripts/DeckController.js"></script> | 123 | 124 | <script src="scripts/DeckController.js"></script> | |
<script src="scripts/RequestResetController.js"></script> | 124 | 125 | <script src="scripts/RequestResetController.js"></script> | |
<script src="scripts/ClassAddController.js"></script> | 125 | 126 | <script src="scripts/ClassAddController.js"></script> | |
<script src="scripts/StudyController.js"></script> | 126 | 127 | <script src="scripts/StudyController.js"></script> | |
<script src="scripts/ResetPasswordController.js"></script> | 127 | 128 | <script src="scripts/ResetPasswordController.js"></script> | |
<script src="scripts/CardListController.js"></script> | 128 | 129 | <script src="scripts/CardListController.js"></script> | |
<script src="scripts/VerifyEmailController.js"></script> | 129 | 130 | <script src="scripts/VerifyEmailController.js"></script> | |
<!--<script src="scripts/SidebarController.js"></script>--> | 130 | 131 | <!--<script src="scripts/SidebarController.js"></script>--> | |
131 | 132 | |||
<!-- Services --> | 132 | 133 | <!-- Services --> | |
<script src="scripts/UserService.js"></script> | 133 | 134 | <script src="scripts/UserService.js"></script> | |
134 | 135 | |||
<!-- Directives --> | 135 | 136 | <!-- Directives --> | |
<script src="scripts/FlashcardDirective.js"></script> | 136 | 137 | <script src="scripts/FlashcardDirective.js"></script> | |
137 | 138 | |||
<!-- Other --> | 138 | 139 | <!-- Other --> | |
<!--<script src="scripts/StudyController.js"></script>--> | 139 | 140 | <!--<script src="scripts/StudyController.js"></script>--> | |
140 | 141 |
scripts/UserService.js
View file @
35387f3
angular.module('flashy.UserService', ['ui.router']). | 1 | 1 | angular.module('flashy.UserService', ['ui.router']). | |
service('UserService', function($rootScope, $http, $q) { | 2 | 2 | service('UserService', function($rootScope, $http, $q) { | |
var deferred = $q.defer(); | 3 | 3 | var deferred = $q.defer(); | |
4 | 4 | var _user = false; | ||
$http.get('/api/me/').success(function(data) { | 5 | 5 | $http.get('/api/me/').success(function(data) { | |
console.log('user is logged in!'); | 6 | 6 | console.log('user is logged in!'); | |
_user = data; | 7 | 7 | _user = data; | |
deferred.resolve(data); | 8 | 8 | deferred.resolve(data); | |
}).error(function(data) { | 9 | 9 | }).error(function(data) { | |
console.log(data); | 10 | 10 | console.log(data); | |
console.log('not logged in yet: ' + data.detail); | 11 | 11 | console.log('not logged in yet: ' + data.detail); | |
deferred.resolve({}); | 12 | 12 | deferred.resolve({email: false}); | |
}); | 13 | 13 | }); | |
14 | 14 | |||
var _user = deferred.promise; | 15 | 15 | this.isResolved = function() { | |
16 | 16 | return !!_user; | ||
17 | }; | |||
this.getUserData = function() { | 17 | 18 | this.getUserData = function() { | |
return _user; | 18 | 19 | if (this.isResolved()) return _user; | |
20 | else return deferred.promise; | |||
}; | 19 | 21 | }; | |
this.setUserData = function(data) { | 20 | 22 | this.setUserData = function(data) { | |
_user = data; | 21 | 23 | _user = data; | |
24 | deferred.resolve(data); | |||
}; | 22 | 25 | }; | |
this.logout = function() { | 23 | 26 | this.logout = function() { | |
_user = {}; | 24 | 27 | _user = false; | |
28 | deferred.resolve({}); | |||
}; | 25 | 29 | }; | |
this.isLoggedIn = function() { | 26 | 30 | this.isLoggedIn = function() { | |
rv = angular.isDefined(_user.email); | 27 | 31 | rv = this.isResolved() && _user.email; | |
return rv; | 28 | 32 | return rv; | |
}; | 29 | 33 | }; | |
}); | 30 | 34 | }); | |
31 | 35 | |||
templates/flashcard.html
View file @
35387f3
<div class="card flashy smallify" ng-init="startShrink = false" | 1 | 1 | <div class="card flashy smallify" ng-init="startShrink = false" | |
ng-class="{'shrinky': startShrink}"> | 2 | 2 | ng-class="{'shrinky': startShrink}"> | |
<div class="card-content"> | 3 | 3 | <div class="valign-wrapper"> | |
<p>{{flashcard.text}}</p> | 4 | 4 | <div class="card-content valign"> | |
5 | <p>{{flashcard.text}}</p> | |||
6 | </div> | |||
</div> | 5 | 7 | </div> | |
<div class="card-overlay"> | 6 | 8 | <div class="card-overlay"> | |
<div class="top-box no-user-select" | 7 | 9 | <div class="top-box no-user-select" | |
ng-click="pullCard(flashcard)"> | 8 | 10 | ng-click="pullCard(flashcard)"> | |
<div class="center-me"><i class="mdi-content-add-circle-outline medium"></i></div> | 9 | 11 | <div class="center-me"><i class="mdi-content-add-circle-outline medium"></i></div> | |
</div> | 10 | 12 | </div> | |
11 | 13 | |||
<div class="bottom-box no-user-select"> | 12 | 14 | <div class="bottom-box no-user-select"> | |
<div class="left-box"> | 13 | 15 | <div class="left-box"> | |
<div class="center-me"><i class="mdi-action-info-outline small"></i></div> | 14 | 16 | <div class="center-me"><i class="mdi-action-info-outline small"></i></div> | |
</div> | 15 | 17 | </div> | |
<div class="right-box" ng-click="unpullCard(flashcard); | 16 | 18 | <div class="right-box" ng-click="unpullCard(flashcard); | |
hideCard(flashcard)"> | 17 | 19 | hideCard(flashcard)"> | |
<div class="center-me"><i class="mdi-action-delete small"></i></div> | 18 | 20 | <div class="center-me"><i class="mdi-action-delete small"></i></div> | |
</div> | 19 | 21 | </div> | |
20 | 22 | |||
</div> | 21 | 23 | </div> | |
</div> | 22 | 24 | </div> | |
</div> | 23 | 25 | </div> |
templates/login.html
View file @
35387f3
<div class="row" style="margin-top:64px;"> | 1 | 1 | <div class="" style="margin-top:32px;"> | |
<div class="offset-m4 col m4"> | 2 | 2 | <div class="row" style="max-width:500px; width:50%;margin: 0 auto"> | |
<ul class="tabs"> | 3 | 3 | <ul class="tabs"> | |
<li class="tab col s6"><a href="#register-tab">Sign Up</a></li> | 4 | 4 | <li class="tab col s6"><a href="#register-tab">Sign Up</a></li> | |
<li class="tab col s6"><a class="active" href="#login-tab">Login</a></li> | 5 | 5 | <li class="tab col s6"><a class="active" href="#login-tab">Login</a></li> | |
</ul> | 6 | 6 | </ul> | |
<div class="card"> | 7 | 7 | <div class="card"> | |
<!--LOGIN TAB--> | 8 | 8 | <!--LOGIN TAB--> | |
<div id="login-tab" class="row col s12"> | 9 | 9 | <div id="login-tab" class="row col s12"> | |
<form id="login-form"> | 10 | 10 | <form id="login-form"> | |
<div class="card-content"> | 11 | 11 | <div class="card-content"> | |
<div class="check-element animate-show" role="alert" ng-show="loginError"> | 12 | 12 | <div class="check-element animate-show" role="alert" ng-show="loginError"> | |
<span style="color:#8E2323">Invalid username or password!!</span> | 13 | 13 | <span style="color:#8E2323">Invalid username or password!!</span> | |
</div> | 14 | 14 | </div> | |
15 | 15 | |||
<div class="input-field"> | 16 | 16 | <div class="input-field"> | |
<input id="email" type="email" name="login" class="validate" ng-model="loginEmail" required autofocus autocomplete/> | 17 | 17 | <input id="email" type="email" name="login" class="validate" ng-model="loginEmail" required autofocus | |
18 | autocomplete/> | |||
<label for="email">Email</label> | 18 | 19 | <label for="email">Email</label> | |
</div> | 19 | 20 | </div> | |
<div class="input-field"> | 20 | 21 | <div class="input-field"> | |
<input id="password" type="password" name="password" class="validate" ng-model="loginPassword" required/> | 21 | 22 | <input id="password" type="password" name="password" class="validate" ng-model="loginPassword" required/> | |
<label for="password">Password</label> | 22 | 23 | <label for="password">Password</label> | |
</div> | 23 | 24 | </div> | |
</div> | 24 | 25 | </div> | |
<div class="card-action"> | 25 | 26 | <div class="card-action"> | |
<button class="btn waves-effect waves-light col s12" type="submit" name="action" | 26 | 27 | <button class="btn waves-effect waves-light col s12" type="submit" name="action" | |
ng-click="login(loginEmail, loginPassword)">Login | 27 | 28 | ng-click="login(loginEmail, loginPassword)">Login | |
</button> | 28 | 29 | </button> | |
</div> | 29 | 30 | </div> | |
</form> | 30 | 31 | </form> | |
</div> | 31 | 32 | </div> | |
<!--REGISTER TAB--> | 32 | 33 | <!--REGISTER TAB--> | |
<div id="register-tab" class="row col s12"> | 33 | 34 | <div id="register-tab" class="row col s12"> | |
<form> | 34 | 35 | <form> | |
<div class="card-content"> | 35 | 36 | <div class="card-content"> | |
<div class="check-element animate-show" role="alert" ng-show="uniqueError"> | 36 | 37 | <div class="check-element animate-show" role="alert" ng-show="uniqueError"> | |
<span style="color:#8E2323">Invalid username or password!</span> | 37 | 38 | <span style="color:#8E2323">Invalid username or password!</span> | |
</div> | 38 | 39 | </div> | |
<div class="input-field"> | 39 | 40 | <div class="input-field"> | |
<input id="email" type="email" class="validate" ng-model="registerEmail" required/> | 40 | 41 | <input id="email" type="email" class="validate" ng-model="registerEmail" required/> | |
<label for="email">Email</label> | 41 | 42 | <label for="email">Email</label> | |
</div> | 42 | 43 | </div> | |
<div class="input-field"> | 43 | 44 | <div class="input-field"> | |
<input type="password" class="validate" ng-model="registerPassword" required/> | 44 | 45 | <input type="password" class="validate" ng-model="registerPassword" required/> | |
<label for="password">Password</label> | 45 | 46 | <label for="password">Password</label> | |
</div> | 46 | 47 | </div> | |
</div> | 47 | 48 | </div> | |
<div class="card-action"> | 48 | 49 | <div class="card-action"> | |
<button class="btn waves-effect waves-light col s12" type="submit" name="action" | 49 | 50 | <button class="btn waves-effect waves-light col s12" type="submit" name="action" | |
ng-click="signUp(registerEmail, registerPassword)">Register | 50 | 51 | ng-click="signUp(registerEmail, registerPassword)">Register | |
</button> | 51 | 52 | </button> | |
</div> | 52 | 53 | </div> | |
</form> | 53 | 54 | </form> | |
</div> | 54 | 55 | </div> | |
<div class="row offset-s1 col s12"> | 55 | 56 | <div class="row offset-s1 col s12"> | |
<a class="trigger-password-reset" ng-click="triggerPasswordReset()" href="#">Forgot Password?</a> | 56 | 57 | <a class="trigger-password-reset" ng-click="triggerPasswordReset()" href="#">Forgot Password?</a> | |
</div> | 57 | 58 | </div> | |
</div> | 58 | 59 | </div> | |
</div> | 59 | 60 | </div> | |
</div> | 60 | 61 | </div> | |
61 | 62 | |||