Class: Remotty::Users::OmniauthCallbacksController

Inherits:
Devise::OmniauthCallbacksController
  • Object
show all
Includes:
ActionController::Flash, BaseController
Defined in:
app/controllers/remotty/users/omniauth_callbacks_controller.rb

Instance Method Summary collapse

Instance Method Details

#allObject Also known as: facebook, twitter

omniauth callback 처리 정보에 따라 유저를 만들던가 연결하던가 추가 정보를 입력받도록 에러를 리턴함



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/remotty/users/omniauth_callbacks_controller.rb', line 8

def all
  # omniauth에서 생성한 session 제거
  session.options[:skip] = true
  response.headers['Set-Cookie'] = 'rack.session=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT'

  auth = request.env['omniauth.auth']
  user = from_omniauth(auth)
  @ret = {}

  if user && user.persisted?
    (:user, user, store: false)
    token = user.generate_auth_token!(auth_source)
    @ret = user.with_token(token)
  elsif user && user.errors.size > 0
    @ret = {
      error: {
        code: 'OAUTH_LOGIN_ERROR_EMAIL_INVALID',
        message: user.errors.full_messages.first,
        data: {
          oauth: {
            credentials: auth[:credentials],
            provider: auth[:provider],
            uid: auth[:uid],
            info: {
              name: auth[:info][:name],
              image: auth[:info][:image]
            }
          }
        }
      }
    }
  else
    @ret = {
      error: {
        code: 'OAUTH_LOGIN_ERROR',
        message: 'require provider & uid!!'
      }
    }
    @ret[:error][:data] = user if user
  end

  render :inline => "<script>(window.opener || window).oauthCallback(#{@ret.to_json}); if(window.opener) { window.close(); }</script>",
         :content_type => 'text/html'
end

#failureObject



53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/remotty/users/omniauth_callbacks_controller.rb', line 53

def failure
  @ret = {
    error: {
      code: OmniAuth::Utils.camelize(failed_strategy.name),
      message: failure_message
    }
  }

  render :inline => "<script>(window.opener || window).oauthCallback(#{@ret.to_json}); if(window.opener) { window.close(); }</script>",
         :content_type => 'text/html'
end