Class: Users::OmniauthCallbacksController

Inherits:
Devise::OmniauthCallbacksController
  • Object
show all
Defined in:
app/controllers/users/omniauth_callbacks_controller.rb

Instance Method Summary collapse

Instance Method Details

#facebookObject


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/users/omniauth_callbacks_controller.rb', line 2

def facebook
  @user = User.from_facebook(request.env["omniauth.auth"])

  if @user.present? && @user.valid?
    SignonStatusTokenService.write_to_cookie(cookies, @user)
    SiteIdentityTokenService.create(cookies, @user)

    # if an invitation_code exists, activate the email for that user
    if session[:invitation_code].present?
      InvitationCodeService.invite(resource, session[:invitation_code])
      @redirect_url = session[:invitation_redirect_url] || root_path
      session[:invitation_code] = nil
      session[:invitation_redirect_url] = nil
       @user
      redirect_to @redirect_url and return if @redirect_url
    end

    # redirect new users to verify their email
    if @user.primary_identity_id.blank? && @user.created_at > 2.hours.ago
       @user
      redirect_to 
    else
       @user, event: :authentication
    end
  else
    flash[:alert] = "錯誤:請確認您的 Facebook 資料是有效的,或嘗試其他登入方式!"
    redirect_to new_user_session_path
  end
end