       @session = {}
       @user = {}
       @logged_in = false
-      
+
       @applySessionData(_plunker.session) if _plunker?.session
 
       $.cookie "plnk_session", @session.id,

        path: "/"

      self = @
      
      $rootScope.$watch ( -> self.user?.id ), (user) ->
        self.logged_in = !!user
      
      _handleOAuthSuccess = (auth) -> $rootScope.$apply ->
        console.log "AUTH", auth
        self.request = $http.post(self.session.user_url, { service: auth.service, token: auth.token })

      top = 0
      if (screenHeight > height)
          top = Math.round((screenHeight / 2) - (height / 2))

      authHost = 'https:' + url.www.replace(/^https?:/, '')

      @loginWindow = window.open "#{authHost}/auth/github", "Sign in with Github", """
        left=#{left},top=#{top},width=#{width},height=#{height},personalbar=0,toolbar=0,scrollbars=1,resizable=1
      """

      if @loginWindow then @loginWindow.focus()

    logout: ->
      self = @

      request = $http
        url: @session.user_url
        method: "DELETE"

      request.then (response) ->
        self.applySessionData(response.data)
      , (error) ->
        notifier.error "Error logging out", arguments...
]
