Class: Defcon::SessionsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/defcon/sessions_controller.rb', line 11

def create
	username = params[:username]
	if !username.nil?
		username = params[:username].downcase
	end
  admin = ::Defcon::AdminUser.find_by(username: username)
  if admin && admin.authenticate(params[:password]) && !admin.locked_out?
  	admin.attempts = 0
  	admin.save
    session[:admin_id] = admin.id
    session[:admin_username] = admin.username
    flash[:notice] = "Welcome back!"
    send_away
  else
  	if !admin.nil?
  		admin.attempts = admin.attempts + 1
  		admin.save
  	end
  	message = "Are you sure you belong here?"
  	if !admin.nil? && admin.locked_out?
  		message = "Locked out!"
  	end
  	flash[:alert] = message
  	redirect_to 
  end
end

#destroyObject



38
39
40
41
42
43
# File 'app/controllers/defcon/sessions_controller.rb', line 38

def destroy
  session[:admin_id] = nil
  session[:admin_username] = nil
  flash[:notice] = "Until next time!"
  redirect_to 
end

#newObject



8
9
# File 'app/controllers/defcon/sessions_controller.rb', line 8

def new
end