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 defcon_login_path
end
end
|