Sha256: ac9d68c5f90763d0f029f0a12317647f46428ef30e70eae596256bcf6bc0457d

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

module Boxroom
  class SessionsController < Boxroom::ApplicationController
    include Boxroom::BaseController

    skip_before_action :require_login

    def new
    end

    def create
      user = User.authenticate(params[:username], params[:password])

      unless user.nil?
        if params[:remember_me] == 'true'
          user.refresh_remember_token
          cookies[:auth_token] = {:value => user.remember_token, :expires => 2.weeks.from_now}
        end

        session[:boxroom_user_id] = user.id
        redirect_url = session.delete(:return_to) || folders_url
        redirect_to redirect_url, :only_path => true
      else
        log_failed_sign_in_attempt(Time.now, params[:username], request.remote_ip)
        redirect_to new_session_url, :alert => t(:credentials_incorrect)
      end
    end

    def destroy
      boxroom_current_user.forget_me
      cookies.delete :auth_token
      reset_session
      session[:boxroom_user_id] = nil
      redirect_to Boxroom.configuration.sign_out_path ? Boxroom.configuration.sign_out_path : new_session_url
    end

    private

    def log_failed_sign_in_attempt(date, username, ip)
      Rails.logger.error(
          "\nFAILED SIGN IN ATTEMPT:\n" +
              "=======================\n" +
              " Date: #{date}\n" +
              " Username: #{username}\n" +
              " IP address: #{ip}\n\n"
      )
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
boxroom-0.0.5 app/controllers/boxroom/sessions_controller.rb
boxroom-0.0.4 app/controllers/boxroom/sessions_controller.rb
boxroom-0.0.3 app/controllers/boxroom/sessions_controller.rb
boxroom-0.0.2 app/controllers/boxroom/sessions_controller.rb