Class: QuoVadis::SessionsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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
# File 'app/controllers/quo_vadis/sessions_controller.rb', line 20

def create
   = QuoVadis. params

  unless 
    qv.log nil, Log::LOGIN_UNKNOWN, identifier: QuoVadis.identifier_value_in_params(params)
    flash.now[:alert] = QuoVadis.translate 'flash.login.failed'
    render :new, status: :unprocessable_entity
    return
  end

  unless .password.authenticate params[:password]
    qv.log , Log::LOGIN_FAILURE
    flash.now[:alert] = QuoVadis.translate 'flash.login.failed'
    render :new, status: :unprocessable_entity
    return
  end

  # no params[:remember]      => use QuoVadis.session_lifetime
  #    params[:remember] == 0 => use :session
  #    params[:remember] == 1 => use QuoVadis.session_lifetime
  browser_session = params[:remember] == '0'

   .model, browser_session

  flash[:notice] = QuoVadis.translate 'flash.login.success'

  redirect_to qv.path_after_authentication
end

#destroyObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/quo_vadis/sessions_controller.rb', line 50

def destroy
  if params[:id]  # other session
    current_qv_session = qv.session
    current_qv_session..sessions.destroy params[:id]
    qv.log current_qv_session., Log::LOGOUT_OTHER
    flash[:notice] = QuoVadis.translate 'flash.logout.other'
    redirect_to action: :index, status: :see_other
  else  # this session
    qv.log authenticated_model., Log::LOGOUT
    qv.logout
    flash[:notice] = QuoVadis.translate 'flash.logout.self'
    redirect_to main_app.root_path, status: :see_other
  end
end

#indexObject



10
11
12
13
# File 'app/controllers/quo_vadis/sessions_controller.rb', line 10

def index
  @qv_session = qv.session
  @qv_sessions = @qv_session..sessions.new_to_old
end

#newObject



16
17
# File 'app/controllers/quo_vadis/sessions_controller.rb', line 16

def new
end