Class: RailsI18nOnair::SessionsController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- RailsI18nOnair::SessionsController
- 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
#create ⇒ Object
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 login_throttled? 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.[:renew] = true session[:translator_id] = translator.id redirect_to main_app.rails_i18n_onair_path, notice: "Signed in successfully" else register_failed_login flash.now[:alert] = "Invalid username or password" render :new, status: :unprocessable_entity end end |
#destroy ⇒ Object
39 40 41 42 |
# File 'app/controllers/rails_i18n_onair/sessions_controller.rb', line 39 def destroy session[:translator_id] = nil redirect_to login_path, notice: "Signed out successfully" end |
#new ⇒ Object
12 13 14 |
# File 'app/controllers/rails_i18n_onair/sessions_controller.rb', line 12 def new # Render login form end |