2020-05-11 17:37:22 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class SuperAdmin::Devise::SessionsController < Devise::SessionsController
|
|
|
|
def new
|
|
|
|
self.resource = resource_class.new(sign_in_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2020-05-14 17:21:51 +00:00
|
|
|
redirect_to(super_admin_session_path, flash: { error: @error_message }) && return unless valid_credentials?
|
2020-05-11 17:37:22 +00:00
|
|
|
|
2022-01-26 00:58:49 +00:00
|
|
|
sign_in(:super_admin, @super_admin)
|
2020-05-11 17:37:22 +00:00
|
|
|
flash.discard
|
|
|
|
redirect_to super_admin_users_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
sign_out
|
|
|
|
flash.discard
|
|
|
|
redirect_to '/'
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def valid_credentials?
|
|
|
|
@super_admin = SuperAdmin.find_by!(email: params[:super_admin][:email])
|
2020-05-14 17:21:51 +00:00
|
|
|
raise StandardError, 'Invalid Password' unless @super_admin.valid_password?(params[:super_admin][:password])
|
|
|
|
|
|
|
|
true
|
|
|
|
rescue StandardError => e
|
|
|
|
@error_message = e.message
|
|
|
|
false
|
2020-05-11 17:37:22 +00:00
|
|
|
end
|
|
|
|
end
|