Prepare view & controller

This commit is contained in:
Alex Sherman 2020-09-23 13:01:33 +05:00
parent 8ff92548bf
commit ffeb1d4baa
6 changed files with 2612 additions and 388 deletions

View file

@ -1,5 +1,6 @@
require 'tampering_detected'
class Registrar
class TaraController < ApplicationController
rescue_from Errors::TamperingDetected do
redirect_to root_url, alert: t('auth.tara.tampering')
@ -7,7 +8,6 @@ class TaraController < ApplicationController
def callback
session[:omniauth_hash] = user_hash
@user = User.from_omniauth(user_hash)
return unless @user.persisted?
@ -18,6 +18,7 @@ class TaraController < ApplicationController
# rubocop:disable Metrics/MethodLength
def create
tara_logger.info create_params
@user = User.new(create_params)
check_for_tampering
create_password
@ -59,6 +60,12 @@ class TaraController < ApplicationController
end
def user_hash
tara_logger.info request.env
request.env['omniauth.auth']
end
def tara_logger
@tara_logger ||= Logger.new(Rails.root.join('log', 'tara_auth2.log'))
end
end
end

View file

@ -16,17 +16,18 @@ class User < ApplicationRecord
# rubocop:disable Metrics/AbcSize
def tampered_with?(omniauth_hash)
uid_from_hash = omniauth_hash['uid']
provider_from_hash = omniauth_hash['provider']
begin
uid != uid_from_hash ||
provider != provider_from_hash ||
country_code != uid_from_hash.slice(0..1) ||
identity_code != uid_from_hash.slice(2..-1) ||
given_names != omniauth_hash.dig('info', 'first_name') ||
surname != omniauth_hash.dig('info', 'last_name')
end
# uid_from_hash = omniauth_hash['uid']
# provider_from_hash = omniauth_hash['provider']
#
# begin
# uid != uid_from_hash ||
# provider != provider_from_hash ||
# country_code != uid_from_hash.slice(0..1) ||
# identity_code != uid_from_hash.slice(2..-1) ||
# given_names != omniauth_hash.dig('info', 'first_name') ||
# surname != omniauth_hash.dig('info', 'last_name')
# end
false
end
# rubocop:enable Metrics/AbcSize

View file

@ -19,11 +19,15 @@
<hr>
<%= link_to '/registrar/login/mid', id: 'login-with-mobile-id-btn' do %>
<%= image_tag 'mid.gif' %>
<% end %>
<%#= link_to '/registrar/login/mid', id: 'login-with-mobile-id-btn' do %>
<%#= image_tag 'mid.gif' %>
<%# end %>
<%= link_to registrar_id_card_sign_in_path, method: :post do %>
<%#= link_to registrar_id_card_sign_in_path, method: :post do %>
<%#= image_tag 'id_card.gif' %>
<%# end %>
<%= link_to "/auth/tara", method: :post, class: "ui button big primary" do %>
<%= image_tag 'id_card.gif' %>
<% end %>
</div>

View file

@ -7,3 +7,7 @@ en:
login_mid:
header: Log in with mobile-id
submit_btn: Login
tara:
callback:
header_html: "Eesti Interneti SA<br>Registrar Portal"
submit_btn: Login

File diff suppressed because it is too large Load diff