-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd027b5
commit 431fc9c
Showing
45 changed files
with
473 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# rubocop:disable Metrics | ||
|
||
module Auth | ||
class TaraController < ParentController | ||
allow_unauthenticated | ||
|
||
def callback | ||
expires_now | ||
|
||
unless in_white_list? | ||
flash[:alert] = I18n.t('.access_denied') | ||
redirect_to sign_in_path, status: :see_other and return | ||
end | ||
|
||
session[:omniauth_hash] = user_hash.delete_if { |key, _| key == 'credentials' } | ||
@user = User.from_omniauth(user_hash) | ||
@user.save! && @user.reload | ||
|
||
@app_session = create_app_session | ||
|
||
if @app_session | ||
log_in @app_session | ||
set_current_session | ||
|
||
redirect_to root_path, status: :see_other | ||
else | ||
flash[:alert] = I18n.t('.incorrect_details') | ||
render 'dashboard/index', status: :unprocessable_entity | ||
end | ||
end | ||
|
||
private | ||
|
||
def in_white_list? | ||
WhiteCode.find_by(code: user_hash['uid'].slice(2..-1)).present? | ||
end | ||
|
||
def set_current_session | ||
Current.user = @user | ||
flash[:notice] = I18n.t('.success') | ||
end | ||
|
||
def user_hash | ||
request.env['omniauth.auth'] | ||
end | ||
|
||
def create_app_session | ||
@user.app_sessions.create | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
module Authenticate | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
before_action :authenticate | ||
before_action :need_to_login, unless: :logged_in? | ||
|
||
helper_method :logged_in? | ||
helper_method :current_user | ||
end | ||
|
||
class_methods do | ||
def skip_authentication(**options) | ||
skip_before_action :authenticate, options | ||
skip_before_action :need_to_login, options | ||
end | ||
|
||
def allow_unauthenticated(**options) | ||
skip_before_action :need_to_login, options | ||
end | ||
end | ||
|
||
protected | ||
|
||
def log_in(app_session, remember_me: false) | ||
if remember_me | ||
cookies.encrypted.permanent[:app_session] = { | ||
value: app_session.to_h | ||
} | ||
else | ||
cookies.signed[:app_session] = { | ||
value: app_session.to_h, | ||
expires: 1.day | ||
} | ||
end | ||
end | ||
|
||
def logout | ||
Current&.app_session&.destroy | ||
end | ||
|
||
def logged_in? | ||
Current.user.present? | ||
end | ||
|
||
def current_user | ||
Current.user | ||
end | ||
|
||
private | ||
|
||
def need_to_login | ||
flash[:notice] = t('login_required') | ||
render 'sessions/new', status: :unauthorized | ||
end | ||
|
||
def authenticate | ||
cookie = cookies.encrypted[:app_session]&.with_indifferent_access | ||
cookie = cookies.signed[:app_session]&.with_indifferent_access if cookie.nil? | ||
|
||
return nil if cookie.nil? | ||
|
||
user = User.find(cookie[:user_id]) | ||
app_session = user&.authenticate_session_token(cookie[:app_session], cookie[:token]) | ||
|
||
Current.user = app_session&.user | ||
Current.app_session = app_session | ||
rescue NoMatchingPatternError, ActiveRecord::RecordNotFound | ||
Current.user = nil | ||
Current.app_session = nil | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
app/controllers/invoice_details/everypay_response_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
app/controllers/invoice_details/payment_references_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
class SessionsController < ParentController | ||
allow_unauthenticated | ||
|
||
def new; end | ||
|
||
def create | ||
user = User.find_by(email: params[:email]) | ||
if user.present? && user.authenticate(params[:password]) | ||
session[:user_id] = user.id | ||
redirect_to root_path, status: :see_other, flash: { notice: 'Logged in successfully' } | ||
else | ||
flash.now[:alert] = 'Wrong username/password' | ||
render :new, status: :unprocessable_entity | ||
end | ||
end | ||
# def create | ||
# user = User.find_by(email: params[:email]) | ||
# if user.present? && user.authenticate(params[:password]) | ||
# session[:user_id] = user.id | ||
# redirect_to root_path, status: :see_other, flash: { notice: 'Logged in successfully' } | ||
# else | ||
# flash.now[:alert] = 'Wrong username/password' | ||
# render :new, status: :unprocessable_entity | ||
# end | ||
# end | ||
|
||
def destroy | ||
session[:user_id] = nil | ||
redirect_to sign_in_path, flash: { notice: 'Logged out' } | ||
logout | ||
|
||
flash[:success] = t('.success') | ||
redirect_to root_path, status: :see_other | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.