@@ -13,29 +13,30 @@ function getUser(callback) {
1313 callback ( _currentUser ) ;
1414 return ;
1515 }
16- buildfire . auth . getCurrentUser ( function ( err , user ) {
17- if ( err ) {
16+ buildfire . auth . getCurrentUser ( function ( err , user ) {
17+ if ( err || ! user ) {
1818 callback ( null ) ;
1919 return console . error ( err ) ;
2020 }
21- if ( ! user ) {
22- return buildfire . auth . login ( { } , function ( err , user ) {
23- if ( err ) {
24- callback ( ) ;
25- return console . error ( err ) ;
26- }
27- _currentUser = user ;
28- callback ( user ) ;
29- buildfire . notifications . pushNotification . subscribe ( { groupName : 'suggestions' } ) ;
30- } ) ;
21+ if ( user ) {
22+ _currentUser = user ;
23+ callback ( user )
3124 }
25+ } ) ;
26+ }
3227
28+ function enforceLogin ( ) {
29+ buildfire . auth . login ( { } , function ( err , user ) {
30+ if ( err ) {
31+ callback ( ) ;
32+ return console . error ( err ) ;
33+ }
3334 _currentUser = user ;
34- callback ( user ) ;
35- buildfire . notifications . pushNotification . subscribe ( { groupName : 'suggestions' } ) ;
35+ if ( user ) {
36+ buildfire . notifications . pushNotification . subscribe ( { groupName : 'suggestions' } ) ;
37+ }
3638 } ) ;
3739}
38- getUser ( function ( ) { } ) ;
3940
4041var config = { } ;
4142
@@ -231,8 +232,9 @@ function listCtrl($scope) {
231232 } ) ;
232233 } ;
233234
234- $scope . upVote = function ( suggestionObj ) {
235- getUser ( function ( user ) {
235+ $scope . upVote = function ( suggestionObj ) {
236+ getUser ( function ( user ) {
237+ if ( ! user ) enforceLogin ( )
236238 if ( ! suggestionObj . data . upVotedBy ) suggestionObj . data . upVotedBy = { } ;
237239 if ( ! suggestionObj . data . upVoteCount ) suggestionObj . data . upVoteCount = 1 ;
238240
@@ -295,9 +297,13 @@ function suggestionBoxCtrl($scope, $sce, $rootScope) {
295297 $scope . popupOn = false ;
296298 $scope . text = $sce . trustAsHtml ( config . text ) ;
297299
298- window . openPopup = function ( ) {
299- $scope . popupOn = true ;
300- if ( ! $scope . $$phase ) $scope . $apply ( ) ;
300+ window . openPopup = function ( ) {
301+ if ( _currentUser ) {
302+ $scope . popupOn = true ;
303+ if ( ! $scope . $$phase ) $scope . $apply ( ) ;
304+ } else {
305+ enforceLogin ( ) ;
306+ }
301307 } ;
302308
303309 buildfire . datastore . get ( function ( err , obj ) {
0 commit comments