| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- # frozen_string_literal: true
- class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
- # You should configure your model like this:
- # devise :omniauthable, omniauth_providers: [:twitter]
- def google_oauth2
- @user = User.from_omniauth(request.env['omniauth.auth'])
- if @user.persisted?
- # this will throw if @user is not activated
- sign_in_and_redirect @user, event: :authentication
- if is_navigational_format?
- set_flash_message(:notice, :success, kind: 'Google')
- end
- else
- session['devise.google_oauth2_data'] = request.env['omniauth.auth']
- redirect_to new_user_registration_url
- end
- end
- def reddit
- @user = User.from_omniauth(request.env['omniauth.auth'])
- if @user.persisted?
- # this will throw if @user is not activated
- sign_in_and_redirect @user, event: :authentication
- if is_navigational_format?
- set_flash_message(:notice, :success, kind: 'Reddit')
- end
- else
- session['devise.reddit_data'] = request.env['omniauth.auth']
- redirect_to new_user_registration_url
- end
- end
- def discord
- @user = User.from_omniauth(request.env['omniauth.auth'])
- if @user.persisted?
- # this will throw if @user is not activated
- sign_in_and_redirect @user, event: :authentication
- if is_navigational_format?
- set_flash_message(:notice, :success, kind: 'Discord')
- end
- else
- session['devise.discord_data'] = request.env['omniauth.auth']
- redirect_to new_user_registration_url
- end
- end
- # You should also create an action method in this controller like this:
- # def twitter
- # end
- # More info at:
- # https://github.com/plataformatec/devise#omniauth
- # GET|POST /resource/auth/twitter
- # def passthru
- # super
- # end
- # GET|POST /users/auth/twitter/callback
- # def failure
- # super
- # end
- # protected
- # The path used when OmniAuth fails
- # def after_omniauth_failure_path_for(scope)
- # super(scope)
- # end
- end
|