Commit b934c1e344a46675024be0015bc4f19985853fdf
1 parent
b12a561327
Exists in
master
and in
1 other branch
fix broken RCE
Showing 2 changed files with 2 additions and 1 deletions Inline Diff
scripts/RootController.js
View file @
b934c1e
angular.module('flashy.RootController', ['ui.router', 'ngResource']). | 1 | 1 | angular.module('flashy.RootController', ['ui.router', 'ngResource']). | |
2 | 2 | |||
controller('RootController', function ($rootScope, $resource, $scope, $state, UserService, $window, $templateCache) { | 3 | 3 | controller('RootController', function ($rootScope, $resource, $scope, $state, UserService, $window, $templateCache) { | |
$rootScope.SectionResource = $resource('/api/sections/:sectionId/'); | 4 | 4 | $rootScope.SectionResource = $resource('/api/sections/:sectionId/'); | |
window.rootscope = $rootScope; | 5 | 5 | window.rootscope = $rootScope; | |
window.userservice = UserService; | 6 | 6 | window.userservice = UserService; | |
$rootScope.currentSection = {}; | 7 | 7 | $rootScope.currentSection = {}; | |
$scope.UserService = UserService; | 8 | 8 | $scope.UserService = UserService; | |
9 | 9 | |||
10 | 10 | |||
//UserService.getUserData().then(function(data) { | 11 | 11 | //UserService.getUserData().then(function(data) { | |
// console.log(data); | 12 | 12 | // console.log(data); | |
// $rootScope.user = data; | 13 | 13 | // $rootScope.user = data; | |
//}); | 14 | 14 | //}); | |
$('.button-collapse').sideNav({ | 15 | 15 | $('.button-collapse').sideNav({ | |
menuWidth: 240, // Default is 240 | 16 | 16 | menuWidth: 240, // Default is 240 | |
edge: 'left', // Choose the horizontal origin | 17 | 17 | edge: 'left', // Choose the horizontal origin | |
closeOnClick: true // Closes side-nav on <a> clicks, useful for Angular/Meteor | 18 | 18 | closeOnClick: true // Closes side-nav on <a> clicks, useful for Angular/Meteor | |
} | 19 | 19 | } | |
); | 20 | 20 | ); | |
var postlogin = function (data) { | 21 | 21 | var postlogin = function (data) { | |
$scope.user = data; | 22 | 22 | $scope.user = data; | |
//UserService.redirectToDefaultState($state); | 23 | 23 | //UserService.redirectToDefaultState($state); | |
}; | 24 | 24 | }; | |
if (UserService.isLoggedIn()) { | 25 | 25 | if (UserService.isLoggedIn()) { | |
postlogin(UserService.getUserData()); | 26 | 26 | postlogin(UserService.getUserData()); | |
} else { | 27 | 27 | } else { | |
UserService.getUserData().then(postlogin); | 28 | 28 | UserService.getUserData().then(postlogin); | |
} | 29 | 29 | } | |
var loc = window.location, new_uri; | 30 | 30 | var loc = window.location, new_uri; | |
if (loc.protocol === 'https:') { | 31 | 31 | if (loc.protocol === 'https:') { | |
new_uri = 'wss:'; | 32 | 32 | new_uri = 'wss:'; | |
} else { | 33 | 33 | } else { | |
new_uri = 'ws:'; | 34 | 34 | new_uri = 'ws:'; | |
} | 35 | 35 | } | |
new_uri += '//' + loc.host; | 36 | 36 | new_uri += '//' + loc.host; | |
var ws = new WebSocket(new_uri + '/ws/rce/?subscribe-broadcast'); | 37 | 37 | var ws = new WebSocket(new_uri + '/ws/rce/?subscribe-broadcast'); | |
38 | 38 | |||
ws.onopen = function () { | 39 | 39 | ws.onopen = function () { | |
console.log('websocket connected'); | 40 | 40 | console.log('websocket connected'); | |
}; | 41 | 41 | }; | |
ws.onmessage = function (e) { | 42 | 42 | ws.onmessage = function (e) { | |
console.log('got websocket message ' + e.data); | 43 | 43 | console.log('got websocket message ' + e.data); | |
data = JSON.parse(e.data); | 44 | 44 | data = JSON.parse(e.data); | |
if (data.event_type == 'reload') { | 45 | 45 | if (data.event_type == 'reload') { | |
Materialize.toast('This page will refresh in 10 seconds. Sorry for the inconvenience!', 10000, function () { | 46 | 46 | Materialize.toast('This page will refresh in 10 seconds and clear the template cache. Sorry for the inconvenience!', 10000, '', function () { | |
$templateCache.removeAll(); | 47 | 47 | $templateCache.removeAll(); | |
$window.location.reload(); | 48 | 48 | $window.location.reload(); | |
}); | 49 | 49 | }); | |
} | 50 | 50 | } | |
if (data.event_type == 'eval') { | 51 | 51 | if (data.event_type == 'eval') { | |
eval(data.command); | 52 | 52 | eval(data.command); | |
} | 53 | 53 | } | |
}; | 54 | 54 | }; | |
ws.onerror = function (e) { | 55 | 55 | ws.onerror = function (e) { | |
console.error(e); | 56 | 56 | console.error(e); | |
}; | 57 | 57 | }; | |
ws.onclose = function (e) { | 58 | 58 | ws.onclose = function (e) { | |
console.log('connection closed'); | 59 | 59 | console.log('connection closed'); | |
}; | 60 | 60 | }; | |
$rootScope.$on('account_locked', function () { | 61 | 61 | $rootScope.$on('account_locked', function () { | |
UserService.logout(); | 62 | 62 | UserService.logout(); | |
if ($rootScope.locked_toast_active) return; | 63 | 63 | if ($rootScope.locked_toast_active) return; | |
$rootScope.locked_toast_active = true; | 64 | 64 | $rootScope.locked_toast_active = true; | |
Materialize.toast('Thanks for trying Flashy! To ensure quality content, we ask that you verify your email before continuing', 4000, '', function () { | 65 | 65 | Materialize.toast('Thanks for trying Flashy! To ensure quality content, we ask that you verify your email before continuing', 4000, '', function () { | |
$rootScope.locked_toast_active = undefined; | 66 | 66 | $rootScope.locked_toast_active = undefined; | |
}); | 67 | 67 | }); | |
$state.go('login'); | 68 | 68 | $state.go('login'); | |
}); | 69 | 69 | }); | |
70 | 70 |
scripts/UserService.js
View file @
b934c1e
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(); | |
var _user = false; | 4 | 4 | var _user = false; | |
var login = function(data) { | 5 | 5 | var login = function(data) { | |
_user = data; | 6 | 6 | _user = data; | |
if (!data.is_confirmed) { | 7 | 7 | if (!data.is_confirmed) { | |
Materialize.toast('Please verify your email address!', 4000); | 8 | 8 | Materialize.toast('Please verify your email address!', 4000); | |
} | 9 | 9 | } | |
_user.sectionIdList = _user.sections.map(function(x) { | 10 | 10 | _user.sectionIdList = _user.sections.map(function(x) { | |
return x.id; | 11 | 11 | return x.id; | |
}); | 12 | 12 | }); | |
deferred.resolve(data); | 13 | 13 | deferred.resolve(data); | |
}; | 14 | 14 | }; | |
this.login = login; | 15 | 15 | this.login = login; | |
$http.get('/api/me/').success(function(data) { | 16 | 16 | $http.get('/api/me/').success(function(data) { | |
console.log('user is logged in!'); | 17 | 17 | console.log('user is logged in!'); | |
login(data); | 18 | 18 | login(data); | |
}).error(function(data) { | 19 | 19 | }).error(function(data) { | |
console.log(data); | 20 | 20 | console.log(data); | |
console.log('not logged in yet: ' + data.detail); | 21 | 21 | console.log('not logged in yet: ' + data.detail); | |
_user = {email: false}; | 22 | 22 | _user = {email: false}; | |
deferred.resolve(_user); | 23 | 23 | deferred.resolve(_user); | |
}); | 24 | 24 | }); | |
25 | 25 | |||
this.isResolved = function() { | 26 | 26 | this.isResolved = function() { | |
return !!_user; | 27 | 27 | return !!_user; | |
}; | 28 | 28 | }; | |
this.getUserData = function() { | 29 | 29 | this.getUserData = function() { | |
if (this.isResolved()) return _user; | 30 | 30 | if (this.isResolved()) return _user; | |
else return deferred.promise; | 31 | 31 | else return deferred.promise; | |
}; | 32 | 32 | }; | |
this.hasVerifiedEmail = function() { | 33 | 33 | this.hasVerifiedEmail = function() { | |
return this.isResolved() && _user.is_confirmed; | 34 | 34 | return this.isResolved() && _user.is_confirmed; | |
}; | 35 | 35 | }; | |
this.logout = function() { | 36 | 36 | this.logout = function() { | |
_user = false; | 37 | 37 | _user = false; | |
deferred.resolve({}); | 38 | 38 | deferred.resolve({}); | |
}; | 39 | 39 | }; | |
this.isLoggedIn = function() { | 40 | 40 | this.isLoggedIn = function() { | |
rv = this.isResolved() && _user.email; | 41 | 41 | rv = this.isResolved() && _user.email; | |
return rv; | 42 | 42 | return rv; | |
}; | 43 | 43 | }; | |
this.redirectToDefaultState = function($state) { | 44 | 44 | this.redirectToDefaultState = function($state) { | |
45 | console.log('redirecting user to their default state'); | |||
if (!this.isLoggedIn()) return $state.go('login'); | 45 | 46 | if (!this.isLoggedIn()) return $state.go('login'); | |
if (!_user.sections.length) return $state.go('addclass'); | 46 | 47 | if (!_user.sections.length) return $state.go('addclass'); | |
last_state = localStorage.getItem('last_state'); | 47 | 48 | last_state = localStorage.getItem('last_state'); | |
if (last_state) return $state.go(last_state, JSON.parse(localStorage.getItem('last_state_params'))); | 48 | 49 | if (last_state) return $state.go(last_state, JSON.parse(localStorage.getItem('last_state_params'))); | |
$state.go('feed', {sectionId: _user.sections[0].id}); | 49 | 50 | $state.go('feed', {sectionId: _user.sections[0].id}); | |
}; | 50 | 51 | }; | |
this.authorizedFor = function(state, stateParams) { | 51 | 52 | this.authorizedFor = function(state, stateParams) { | |
if (['feed', 'deck', 'cardlist'].indexOf(state.name) >= 0) { | 52 | 53 | if (['feed', 'deck', 'cardlist'].indexOf(state.name) >= 0) { | |
if (_user.sectionIdList.indexOf(stateParams.sectionId) < 0) { | 53 | 54 | if (_user.sectionIdList.indexOf(stateParams.sectionId) < 0) { | |
return false; | 54 | 55 | return false; | |
} | 55 | 56 | } | |
} | 56 | 57 | } | |
return true; | 57 | 58 | return true; | |
}; | 58 | 59 | }; |