Sha256: 2720d6e1c6de31da19fd3292ecc5cb88ea05874b028f098eb9037b0dcf95384b

Contents?: true

Size: 1.43 KB

Versions: 5

Compression:

Stored size: 1.43 KB

Contents

module LatoCore

  # This module contains a list of functions used to authenticate a superuser.
  module Interface::Authentication

    # This function set a cookie to create the superuser session.
    def core__create_superuser_session(superuser, lifetime)
      token = core__encode_token(lifetime, superuser_id: superuser.id)
      session[:lato_core__superuser_session_token] = token
    end

    # This function delete a cookie to destroy the superuser session.
    def core__destroy_superuser_session
      session[:lato_core__superuser_session_token] = nil
    end

    # This function tells if the current session is valid.
    def core__check_superuser_session_valid
      decoded_token = core__decode_token(session[:lato_core__superuser_session_token])
      return false unless decoded_token
      true
    end

    # This function check the session for a superuser and set the variable @core__current_superuser.
    # If session is not valid the user should be redirect to login path.
    def core__manage_superuser_session
      decoded_token = core__decode_token(session[:lato_core__superuser_session_token])

      if decoded_token
        @core__current_superuser = LatoCore::Superuser.find_by(id: decoded_token[:superuser_id])
        unless @core__current_superuser
          core__destroy_superuser_session
          redirect_to lato_core.login_path
        end
      else
        redirect_to lato_core.login_path
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lato_core-2.1.4 lib/lato_core/interfaces/authentication.rb
lato_core-2.1.3 lib/lato_core/interfaces/authentication.rb
lato_core-2.1.2 lib/lato_core/interfaces/authentication.rb
lato_core-2.1.1 lib/lato_core/interfaces/authentication.rb
lato_core-2.1 lib/lato_core/interfaces/authentication.rb