Class: SessionsController

Inherits:
ApplicationController show all
Defined in:
lib/generators/jinda/templates/app/controllers/sessions_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#prepare_meta_tags

Instance Method Details

#createObject

to refresh the page, must know BEFOREHAND that the action needs refresh then use attribute ‘data-ajax’=>‘false’ see app/views/sessions/new.html.erb for sample



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/generators/jinda/templates/app/controllers/sessions_controller.rb', line 10

def create
  auth = request.env["omniauth.auth"]
  user = User.from_omniauth(auth)
  session[:user_id] = user.id
  if params.permit[:remember_me]
    cookies.permanent[:auth_token] = user.auth_token
  else
    cookies[:auth_token] = user.auth_token
  end
  refresh_to root_path, :ma_notice => "Logged in"
rescue
  redirect_to root_path, :alert=> "Authentication failed, please try again."
end

#destroyObject



24
25
26
27
28
29
30
31
# File 'lib/generators/jinda/templates/app/controllers/sessions_controller.rb', line 24

def destroy
  #session[:user_id] = nil
  cookies.delete(:auth_token)
  # redirect_to '/jinda/help'
  refresh_to root_path, :ma_notice => "Logged Out"
  #  render not work!!
  #redirect_to 'jinda/index'
end

#failureObject



33
34
35
36
# File 'lib/generators/jinda/templates/app/controllers/sessions_controller.rb', line 33

def failure
  ma_log "Authentication failed, please try again."
  redirect_to root_path, :alert=> "Authentication failed, please try again."
end

#newObject



3
4
5
# File 'lib/generators/jinda/templates/app/controllers/sessions_controller.rb', line 3

def new
  @title= 'Sign In'
end