<commit_before>null

### @ngInject ###
global.cobudgetApp.factory 'AuthenticateUser', (Records, ipCookie, Toast, $location, $stateParams, $q, $auth, CurrentUser) ->
  () ->
    deferred = $q.defer()

    if ipCookie('currentUserId')
      Records.memberships.fetchMyMemberships()
        .then (data) ->
          if groupId = parseInt($stateParams.groupId)
            if !(_.find data.groups, (group) -> group.id == groupId) 
              Toast.show('The group you were trying to access is private')
              ipCookie.remove('initialRequestPath')
              $location.path('/')
              deferred.reject()
          if bucketId = parseInt($stateParams.bucketId)
            bucket = Records.buckets.findOrFetchById(bucketId).then (bucket) ->
              userIsMemberOfBucketGroup = _.find data.groups, (group) ->
                group.id == bucket.groupId
              if !userIsMemberOfBucketGroup
                Toast.show('The bucket you were trying to access is private')
                ipCookie.remove('initialRequestPath')
                $location.path('/')
                deferred.reject()
          deferred.resolve(CurrentUser())
        .catch (data) ->
          Toast.show('Please log in to continue')
          $location.path('/')
          deferred.reject()
    else
      ipCookie('initialRequestPath', $location.path())
      Toast.show('You must sign in to continue')<commit_msg>add text to Toast in AuthenticateUser service<commit_after>null

### @ngInject ###
global.cobudgetApp.factory 'AuthenticateUser', (Records, ipCookie, Toast, $location, $stateParams, $q, $auth, CurrentUser) ->
  () ->
    deferred = $q.defer()

    if ipCookie('currentUserId')
      Records.memberships.fetchMyMemberships()
        .then (data) ->
          if groupId = parseInt($stateParams.groupId)
            if !(_.find data.groups, (group) -> group.id == groupId) 
              Toast.show('The group you were trying to access is private, please sign in to continue')
              ipCookie.remove('initialRequestPath')
              $location.path('/')
              deferred.reject()
          if bucketId = parseInt($stateParams.bucketId)
            bucket = Records.buckets.findOrFetchById(bucketId).then (bucket) ->
              userIsMemberOfBucketGroup = _.find data.groups, (group) ->
                group.id == bucket.groupId
              if !userIsMemberOfBucketGroup
                Toast.show('The bucket you were trying to access is private, please sign in to continue')
                ipCookie.remove('initialRequestPath')
                $location.path('/')
                deferred.reject()
          deferred.resolve(CurrentUser())
        .catch (data) ->
          Toast.show('Please log in to continue')
          $location.path('/')
          deferred.reject()
    else
      ipCookie('initialRequestPath', $location.path())
      Toast.show('You must sign in to continue')
{'fraction_non_alphanumeric': 0.12175102599179206, 'fraction_numerical': 0.0, 'mean_word_length': 2.2392026578073088, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3088712', 'n_tokens_mistral': 791, 'n_tokens_neox': 775, 'n_words': 185}