Class: Aviate::ConfigurationController

Inherits:
EngineController
  • Object
show all
Defined in:
app/controllers/aviate/configuration_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



7
8
9
# File 'app/controllers/aviate/configuration_controller.rb', line 7

def index
  @available = Killbill::Aviate::AviateClient.aviate_plugin_available?(options_for_klient).first
end

#session_createObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/aviate/configuration_controller.rb', line 11

def session_create
  cached_options_for_klient = options_for_klient
  email = params[:aviate_email]
  password = params[:aviate_password]
  response = Killbill::Aviate::AviateClient.authenticate(email, password, cached_options_for_klient)

  if response.is_a?(Hash) && response['token']
    # Store JWT in encrypted cookie
    cookies[:jwt_token] = {
      value: response['token'],
      httponly: true,
      secure: request.ssl?,
      same_site: :strict,
      expires: 1.hour.from_now
    }
    flash[:notice] = t('aviate.configuration.authentication_success')
  else
    flash[:error] = t('aviate.configuration.authentication_failed')
  end

  redirect_to aviate_root_path
end

#session_destroyObject



34
35
36
37
38
39
40
# File 'app/controllers/aviate/configuration_controller.rb', line 34

def session_destroy
  # Delete JWT cookie
  cookies.delete(:jwt_token)

  flash[:notice] = t('aviate.configuration.logout_success')
  redirect_to aviate_root_path
end