Class: KStor::Controller::Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/kstor/controller/authentication.rb

Overview

Specialized controller for user authentication and sessions.

Instance Method Summary collapse

Constructor Details

#initialize(store, session_store) ⇒ KStor::Controller::Authentication

Create new auth controller.

Parameters:



18
19
20
21
# File 'lib/kstor/controller/authentication.rb', line 18

def initialize(store, session_store)
  @store = store
  @sessions = session_store
end

Instance Method Details

#allowed?(user) ⇒ Boolean

Check if user is allowed to access the application.

Parameters:

Returns:

  • (Boolean)

    true if login is allowed to access application data.



45
46
47
# File 'lib/kstor/controller/authentication.rb', line 45

def allowed?(user)
  user.status == 'new' || user.status == 'active'
end

#authenticate(req) ⇒ KStor::Model::User

Authenticate request user.

Request may either contain a login/password, or a session ID.

Parameters:

Returns:

Raises:



33
34
35
36
37
38
39
# File 'lib/kstor/controller/authentication.rb', line 33

def authenticate(req)
  if @store.users?
    unlock_user(req)
  else
    create_first_user(req)
  end
end