Class: Recruiter::OmniauthCallbacksController
- Inherits:
-
Devise::OmniauthCallbacksController
- Object
- Devise::OmniauthCallbacksController
- Recruiter::OmniauthCallbacksController
- Defined in:
- app/controllers/recruiter/omniauth_callbacks_controller.rb
Instance Method Summary collapse
- #facebook ⇒ Object
- #github ⇒ Object
- #google_oauth2 ⇒ Object
- #login_message(user) ⇒ Object
- #login_with(klass) ⇒ Object
-
#new_session_path(scope) ⇒ Object
For handling errors.
- #redirect_url_for(user, origin = nil) ⇒ Object
- #relative_path(url) ⇒ Object
Instance Method Details
#facebook ⇒ Object
8 9 10 |
# File 'app/controllers/recruiter/omniauth_callbacks_controller.rb', line 8 def facebook login_with(Oauth::Facebook) end |
#github ⇒ Object
16 17 18 |
# File 'app/controllers/recruiter/omniauth_callbacks_controller.rb', line 16 def github login_with(Oauth::Github) end |
#google_oauth2 ⇒ Object
12 13 14 |
# File 'app/controllers/recruiter/omniauth_callbacks_controller.rb', line 12 def google_oauth2 login_with(Oauth::Google) end |
#login_message(user) ⇒ Object
31 32 33 34 |
# File 'app/controllers/recruiter/omniauth_callbacks_controller.rb', line 31 def (user) key = user.new_record? ? 'account_created' : 'login_succeed' I18n.t("recruiter.messages.#{key}") end |
#login_with(klass) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/recruiter/omniauth_callbacks_controller.rb', line 20 def login_with(klass) env = request.env["omniauth.auth"] origin = request.env["omniauth.origin"] user = klass.find_or_build_user(env) redirect_url = redirect_url_for(user, origin) = (user) user.save!(validate: false) sign_in(user, event: :authentication) redirect_to redirect_url, notice: , only_path: true end |
#new_session_path(scope) ⇒ Object
For handling errors
4 5 6 |
# File 'app/controllers/recruiter/omniauth_callbacks_controller.rb', line 4 def new_session_path(scope) new_user_session_path end |
#redirect_url_for(user, origin = nil) ⇒ Object
36 37 38 |
# File 'app/controllers/recruiter/omniauth_callbacks_controller.rb', line 36 def redirect_url_for(user, origin = nil) origin || root_url end |
#relative_path(url) ⇒ Object
40 41 42 43 |
# File 'app/controllers/recruiter/omniauth_callbacks_controller.rb', line 40 def relative_path(url) matches = url.match(/^http(s)?:\/\/[^\/]+(.*)/) matches ? matches[2] : url end |