Class: Ditty::AuthController
Instance Method Summary
collapse
#find_template, #view_folders
Instance Method Details
#failed_login ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/ditty/controllers/auth_controller.rb', line 34
def failed_login
details = params[:message] || 'None'
logger.warn "Invalid Login: #{details}"
broadcast(:user_failed_login, target: self, details: details)
flash[:warning] = 'Invalid credentials. Please try again'
'X-Authentication-Failure' => params[:message] if params[:message]
redirect "#{settings.map_path}/auth/login"
end
|
#omniauth_callback(provider) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/ditty/controllers/auth_controller.rb', line 22
def omniauth_callback(provider)
return failed_login unless env['omniauth.auth']
broadcast("before_#{provider}_login".to_sym, env['omniauth.auth'])
user = User.first(email: env['omniauth.auth']['info']['email'])
user = register_user if user.nil? && authorize(current_user, :register?)
return failed_login if user.nil?
broadcast("#{provider}_login".to_sym, user)
successful_login(user)
end
|
#omniauth_redirect_path ⇒ Object
18
19
20
|
# File 'lib/ditty/controllers/auth_controller.rb', line 18
def omniauth_redirect_path
env['omniauth.origin'] || request.session['omniauth.origin']
end
|
#redirect_path ⇒ Object
11
12
13
14
15
16
|
# File 'lib/ditty/controllers/auth_controller.rb', line 11
def redirect_path
return "#{settings.map_path}/" if omniauth_redirect_path.nil?
return "#{settings.map_path}/" if omniauth_redirect_path.match? %r{/#{settings.map_path}/auth/?}
omniauth_redirect_path
end
|
#register_user ⇒ Object
51
52
53
54
55
56
|
# File 'lib/ditty/controllers/auth_controller.rb', line 51
def register_user
user = User.create(email: env['omniauth.auth']['info']['email'])
broadcast(:user_register, target: self, values: { user: user })
flash[:info] = 'Successfully Registered.'
user
end
|
#successful_login(user) ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/ditty/controllers/auth_controller.rb', line 43
def successful_login(user)
halt 200 if request.xhr?
self.current_user = user
broadcast(:user_login, target: self)
flash[:success] = 'Logged In'
redirect redirect_path
end
|