Chatwoot/app/controllers/super_admin/devise/sessions_controller.rb
Sojan Jose e6aa851987
Chore: Add Account Users to Admin Panel (#859)
- Show errors on login page
- Dashboard for admin panel
2020-05-14 22:51:51 +05:30

33 lines
800 B
Ruby

# frozen_string_literal: true
class SuperAdmin::Devise::SessionsController < Devise::SessionsController
def new
self.resource = resource_class.new(sign_in_params)
end
def create
redirect_to(super_admin_session_path, flash: { error: @error_message }) && return unless valid_credentials?
sign_in(@super_admin, scope: :super_admin)
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])
raise StandardError, 'Invalid Password' unless @super_admin.valid_password?(params[:super_admin][:password])
true
rescue StandardError => e
@error_message = e.message
false
end
end