<commit_before>@Travis.Auth = Ember.Object.extend
  iframe: $('<iframe id="auth-frame" />').hide()
  timeout: 5000
  state: 'signed-out'
  receivingEnd: "#{location.protocol}//#{location.host}"

  init: ->
    @iframe.appendTo('body')
    window.addEventListener('message', (e) => @receiveMessage(e))
    Ember.run.next(this, @loadUser)

  # if the user is in the session storage, we're using it. if we have a flag
  # for auto signin then we're trying to sign in.
  loadUser: ->
    if user = sessionStorage?.getItem('travis.user')
      @setUser(user)
    else if localStorage?.getItem('travis.auto_signin')
      @trySignIn()

  # try signing in, but check later in case we have a timeout
  signIn: ->
    @set('state', 'signing-in')
    @trySignIn()
    Ember.run.later(this, @checkSignIn.bind(this), @timeout)

  trySignIn: ->
    @iframe.attr('src', "#{@endpoint}/auth/post_message?origin=#{@receivingEnd}")

  checkSignIn: ->
    @forceSignIn() if @get('state') == 'signing-in'

  forceSignIn: ->
    localStorage?.setItem('travis.auto_signin', 'true')
    window.location = "#{@endpoint}/auth/handshake?redirect_uri=#{location}"

  signOut: ->
    localStorage?.clear()
    sessionStorage?.clear()
    @setUser()


  setUser: (data) ->
    data = JSON.parse(data) if typeof data == 'string'
    user = @storeUser(data) if data
    @set('state', if user then 'signed-in' else 'signed-out')
    @set('user',  if user then user else undefined)

  storeUser: (data) ->
    localStorage?.setItem('travis.auto_signin', 'true')
    sessionStorage?.setItem('travis.user', JSON.stringify(data))<commit_msg>remove empty line<commit_after>@Travis.Auth = Ember.Object.extend
  iframe: $('<iframe id="auth-frame" />').hide()
  timeout: 5000
  state: 'signed-out'
  receivingEnd: "#{location.protocol}//#{location.host}"

  init: ->
    @iframe.appendTo('body')
    window.addEventListener('message', (e) => @receiveMessage(e))
    Ember.run.next(this, @loadUser)

  # if the user is in the session storage, we're using it. if we have a flag
  # for auto signin then we're trying to sign in.
  loadUser: ->
    if user = sessionStorage?.getItem('travis.user')
      @setUser(user)
    else if localStorage?.getItem('travis.auto_signin')
      @trySignIn()

  # try signing in, but check later in case we have a timeout
  signIn: ->
    @set('state', 'signing-in')
    @trySignIn()
    Ember.run.later(this, @checkSignIn.bind(this), @timeout)

  trySignIn: ->
    @iframe.attr('src', "#{@endpoint}/auth/post_message?origin=#{@receivingEnd}")

  checkSignIn: ->
    @forceSignIn() if @get('state') == 'signing-in'

  forceSignIn: ->
    localStorage?.setItem('travis.auto_signin', 'true')
    window.location = "#{@endpoint}/auth/handshake?redirect_uri=#{location}"

  signOut: ->
    localStorage?.clear()
    sessionStorage?.clear()
    @setUser()

  setUser: (data) ->
    data = JSON.parse(data) if typeof data == 'string'
    user = @storeUser(data) if data
    @set('state', if user then 'signed-in' else 'signed-out')
    @set('user',  if user then user else undefined)

  storeUser: (data) ->
    localStorage?.setItem('travis.auto_signin', 'true')
    sessionStorage?.setItem('travis.user', JSON.stringify(data))
{'fraction_non_alphanumeric': 0.1693121693121693, 'fraction_numerical': 0.0024898848428260194, 'mean_word_length': 3.825825825825826, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '5266754', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1082, 'n_words': 243}