Class: RailsI18nOnair::SessionsController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/rails_i18n_onair/sessions_controller.rb

Constant Summary collapse

MAX_LOGIN_ATTEMPTS =
10
LOCKOUT_DURATION =
15.minutes

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  if 
    flash.now[:alert] = "Too many failed attempts — try again in a few minutes"
    render :new, status: :too_many_requests
    return
  end

  translator = RailsI18nOnair::Translator.find_by(username: params[:username])

  if translator&.authenticate(params[:password])
    clear_failed_logins
    # Rotate the session id on sign-in (prevents session fixation) while
    # keeping the host app's session data intact
    request.session_options[:renew] = true
    session[:translator_id] = translator.id
    redirect_to main_app.rails_i18n_onair_path, notice: "Signed in successfully"
  else
    
    flash.now[:alert] = "Invalid username or password"
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



39
40
41
42
# File 'app/controllers/rails_i18n_onair/sessions_controller.rb', line 39

def destroy
  session[:translator_id] = nil
  redirect_to , notice: "Signed out successfully"
end

#newObject



12
13
14
# File 'app/controllers/rails_i18n_onair/sessions_controller.rb', line 12

def new
  # Render login form
end