class Ditty::AuthController

Public Instance Methods

failed_login() click to toggle source
# 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'
  headers 'X-Authentication-Failure' => params[:message] if params[:message]
  redirect "#{settings.map_path}/auth/login"
end
omniauth_callback(provider) click to toggle source
# 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(::Ditty::User, :register?)
  return failed_login if user.nil?

  broadcast("#{provider}_login".to_sym, user)
  successful_login(user)
end
omniauth_redirect_path() click to toggle source
# File lib/ditty/controllers/auth_controller.rb, line 18
def omniauth_redirect_path
  env['omniauth.origin'] || request.session['omniauth.origin']
end
redirect_path() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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