Class: SessionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/sessions_controller.rb

Instance Method Summary collapse

Instance Method Details

#authObject


30
31
32
33
# File 'app/controllers/sessions_controller.rb', line 30

def auth
  session[:omniauth_keys] = Usergroup.omniauth_keys(params[:provider], request)
  redirect_to "/auth/#{params[:provider]}"
end

#createObject


7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/sessions_controller.rb', line 7

def create
  begin
    authorization = Authorization.handle_authorization request.env['omniauth.auth']
    self.current_user = authorization.user
    options = {notice: t("flash.logged_in", name: current_user.name)}
    cookies.permanent.signed[:remember_me] = [current_user.id, current_user.salt]
  rescue User::DuplicateNickname => error
    options = {alert: t("flash.duplicate_nick", name: error.nickname)}
  end
  redirect_to request.env['omniauth.origin'] || root_path, options
end

#destroyObject


19
20
21
22
23
24
# File 'app/controllers/sessions_controller.rb', line 19

def destroy
  session[:user_id] = nil
  cookies.permanent.signed[:remember_me] = ['', '']
  message = flash[:notice] || t("flash.logged_out")
  redirect_to root_path, notice: message
end

#failureObject


26
27
28
# File 'app/controllers/sessions_controller.rb', line 26

def failure
  redirect_to root_path, alert: t("flash.login_error")
end

#offline_loginObject


2
3
4
5
# File 'app/controllers/sessions_controller.rb', line 2

def 
  self.current_user = User.find_by_nickname(params[:nickname])
  redirect_to root_path, notice: "Offline Login!"
end