Sha256: b49412bd03f8e738d05440cd77b529cc8a65ab34226e7ef47a4f138e1ea0bb0d

Contents?: true

Size: 1.05 KB

Versions: 18

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module ClWiki
  class SessionsController < ApplicationController
    before_action :skip_all_if_not_using_authentication
    skip_before_action :authorized, only: %i[new create]
    skip_before_action :initialize_index, only: %i[new create]

    def new
    end

    def create
      auth_user_and_setup_session ?
        redirect_to(root_url) :
        redirect_to(login_url)
    end

    def destroy
      reset_session
      redirect_to login_url
    end

    private

    def auth_user_and_setup_session
      @user = User.find(params[:username])
      password = params[:password]
      authenticated = @user&.username == $wiki_conf.owner && @user&.authenticate(password)
      if authenticated
        session[:username] = @user.username
        session[:expire_at] = 48.hours.from_now
        session[:encryption_key] = Base64.encode64(@user.derive_encryption_key(password))
      end
      authenticated
    end

    def skip_all_if_not_using_authentication
      redirect_to root_url unless $wiki_conf.use_authentication
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
clwiki-3.3.2 app/controllers/cl_wiki/sessions_controller.rb
clwiki-3.3.0 app/controllers/cl_wiki/sessions_controller.rb
clwiki-3.2.6 app/controllers/cl_wiki/sessions_controller.rb
clwiki-3.2.5 app/controllers/cl_wiki/sessions_controller.rb
clwiki-3.2.4 app/controllers/cl_wiki/sessions_controller.rb
clwiki-3.2.3 app/controllers/cl_wiki/sessions_controller.rb
clwiki-3.2.2 app/controllers/cl_wiki/sessions_controller.rb
clwiki-3.2.1 app/controllers/cl_wiki/sessions_controller.rb
clwiki-3.2.0 app/controllers/cl_wiki/sessions_controller.rb
clwiki-3.1.6 app/controllers/cl_wiki/sessions_controller.rb
clwiki-3.1.5 app/controllers/cl_wiki/sessions_controller.rb
clwiki-3.1.4 app/controllers/cl_wiki/sessions_controller.rb
clwiki-3.1.3 app/controllers/cl_wiki/sessions_controller.rb
clwiki-3.1.2 app/controllers/cl_wiki/sessions_controller.rb
clwiki-3.1.1 app/controllers/cl_wiki/sessions_controller.rb
clwiki-3.1.0 app/controllers/cl_wiki/sessions_controller.rb
clwiki-3.0.4 app/controllers/cl_wiki/sessions_controller.rb
clwiki-3.0.3 app/controllers/cl_wiki/sessions_controller.rb