-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathauth_controller.rb
49 lines (36 loc) · 1.14 KB
/
auth_controller.rb
1
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true
class AuthController < ApplicationController
# def index
# end
def callback
Rails.logger.debug { "callback: #{omniauth_params}" }
# Prevent session fixation. If the session has been initialized before
# this, and we need to keep the data, then we should copy values over.
reset_session
self.current_user = User.from_omniauth request.env['omniauth.auth']
return redirect_to admin_root_path if current_user.admin?
redirect_to root_path
end
def destroy
reset_session
# Prevent redirect loops etc.
if Rails.configuration.bypass_oauth
redirect_to root_path
return
end
redirect_to "#{Rails.configuration.identity_url}/logout?returnTo=#{ENV.fetch('HOST_URL', nil)}",
allow_other_host: true
end
def failure
flash[:alert] = if request.env['omniauth.error.type'] == :not_verified
'Login error - account not verified'
else
'Login error message'
end
redirect_to root_path
end
private
def omniauth_params
request.env['omniauth.params']
end
end