From 0f6df9e3f8d8d5c328582dfd05e59fb3012ad20d Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 20:00:40 +0300 Subject: [PATCH 01/59] Regenerate Devise translation --- config/locales/devise.en.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml index 9524e860ce..3a853fe31e 100644 --- a/config/locales/devise.en.yml +++ b/config/locales/devise.en.yml @@ -9,12 +9,12 @@ en: failure: already_authenticated: "You are already signed in." inactive: "Your account is not activated yet." - invalid: "Invalid email or password." + invalid: "Invalid %{authentication_keys} or password." locked: "Your account is locked." last_attempt: "You have one more attempt before your account is locked." - not_found_in_database: "Invalid email address or password." + not_found_in_database: "Invalid %{authentication_keys} or password." timeout: "Your session expired. Please sign in again to continue." - unauthenticated: "You need to sign in." + unauthenticated: "You need to sign in before continuing." unconfirmed: "You have to confirm your email address before continuing." mailer: confirmation_instructions: @@ -23,6 +23,10 @@ en: subject: "Reset password instructions" unlock_instructions: subject: "Unlock instructions" + email_changed: + subject: "Email Changed" + password_change: + subject: "Password Changed" omniauth_callbacks: failure: "Could not authenticate you from %{kind} because \"%{reason}\"." success: "Successfully authenticated from %{kind} account." From ebe831e78247bde3eb50347969b46622ee24db21 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 20:23:54 +0300 Subject: [PATCH 02/59] Regenerate and tune Devise config --- config/initializers/devise.rb | 82 +++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 33 deletions(-) diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index eceb6d5f22..c2f89e691c 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -1,26 +1,31 @@ -require 'devise_custom_failure' +# frozen_string_literal: true # Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration options can be set straight in your model. Devise.setup do |config| - config.warden do |manager| - manager.failure_app = DeviseCustomFailure - end - # The secret key used by Devise. Devise uses this key to generate # random tokens. Changing this key will render invalid all existing # confirmation, reset password and unlock tokens in the database. + # Devise will use the `secret_key_base` as its `secret_key` + # by default. You can change it below and use your own secret key. config.secret_key = ENV['devise_secret'] + # ==> Controller configuration + # Configure the parent class to the devise controllers. + # config.parent_controller = 'DeviseController' + # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use your own mailer class # with default "from" parameter. - config.mailer_sender = 'noreply@example.com' + config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' # Configure the class responsible to send e-mails. # config.mailer = 'Devise::Mailer' + # Configure the parent class responsible to send e-mails. + # config.parent_mailer = 'ActionMailer::Base' + # ==> ORM configuration # Load and configure the ORM. Supports :active_record (default) and # :mongoid (bson_ext recommended) by default. Other ORMs may be @@ -35,7 +40,7 @@ # session. If you need permissions, you should implement that in a before filter. # You can also supply a hash where the value is a boolean determining whether # or not authentication should be aborted when the value is not present. - # config.authentication_keys = [ :email ] + # config.authentication_keys = [:email] # Configure parameters from the request object used for authentication. Each entry # given should be a request method and it will automatically be passed to the @@ -67,7 +72,7 @@ # :database = Support basic authentication with authentication key + password # config.http_authenticatable = false - # If http headers should be returned for AJAX requests. True by default. + # If 401 status code should be returned for AJAX requests. True by default. # config.http_authenticatable_on_xhr = true # The realm used in Http Basic Authentication. 'Application' by default. @@ -91,20 +96,31 @@ # from the server. You can disable this option at your own risk. # config.clean_up_csrf_token_on_authentication = true + # When false, Devise will not attempt to reload routes on eager load. + # This can reduce the time taken to boot the app but if your application + # requires the Devise mappings to be loaded during boot time the application + # won't boot properly. + # config.reload_routes = true + # ==> Configuration for :database_authenticatable - # For bcrypt, this is the cost for hashing the password and defaults to 10. If - # using other encryptors, it sets how many times you want the password re-encrypted. + # For bcrypt, this is the cost for hashing the password and defaults to 11. If + # using other algorithms, it sets how many times you want the password to be hashed. # # Limiting the stretches to just one in testing will increase the performance of # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use # a value less than 10 in other environments. Note that, for bcrypt (the default - # encryptor), the cost increases exponentially with the number of stretches (e.g. + # algorithm), the cost increases exponentially with the number of stretches (e.g. # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). - config.stretches = Rails.env.test? ? 1 : 10 + config.stretches = Rails.env.test? ? 1 : 11 + + # Set up a pepper to generate the hashed password. + # config.pepper = '1fc02c7f3a9d5d0dc6c3e49828eb45d29e5fdb3136f78ee0063a2cdf774b7ed53ea40176d5823703554b7f015dd23c0e491fb488bb705a0768db32d02b1d088d' - # Setup a pepper to generate the encrypted password. - # config.pepper = '4d1b39f778c3ea5b415476ce410f337a27895181a8ccd586c60e50e0f7284' \ - # '3d5d6ded80558ed7a4637de6b3a1504379270af6eee995fd9a329e4f4c5daa33882' + # Send a notification to the original email when the user's email is changed. + # config.send_email_changed_notification = false + + # Send a notification email when the user's password is changed. + # config.send_password_change_notification = false # ==> Configuration for :confirmable # A period that the user is allowed to access the website even without @@ -129,11 +145,11 @@ config.reconfirmable = true # Defines which key will be used when confirming an account - # config.confirmation_keys = [ :email ] + # config.confirmation_keys = [:email] # ==> Configuration for :rememberable # The time the user will be remembered without asking for credentials again. - config.remember_for = 2.weeks + # config.remember_for = 2.weeks # Invalidates all the remember me tokens when the user signs out. config.expire_all_remember_me_on_sign_out = true @@ -152,15 +168,12 @@ # Email regex used to validate email formats. It simply asserts that # one (and only one) @ exists in the given string. This is mainly # to give user feedback and not to assert the e-mail validity. - # config.email_regexp = /\A[^@]+@[^@]+\z/ + config.email_regexp = /\A[^@\s]+@[^@\s]+\z/ # ==> Configuration for :timeoutable # The time you want to timeout the user session without activity. After this # time the user will be asked for credentials again. Default is 30 minutes. - config.timeout_in = ENV['user_session_timeout'].to_i.seconds if ENV['user_session_timeout'] - - # If true, expires auth token on session timeout. - # config.expire_auth_token_on_timeout = false + # config.timeout_in = 30.minutes # ==> Configuration for :lockable # Defines which strategy will be used to lock an account. @@ -169,7 +182,7 @@ # config.lock_strategy = :failed_attempts # Defines which key will be used when locking and unlocking an account - # config.unlock_keys = [ :email ] + # config.unlock_keys = [:email] # Defines which strategy will be used to unlock an account. # :email = Sends an unlock link to the user email @@ -186,24 +199,28 @@ # config.unlock_in = 1.hour # Warn on the last attempt before the account is locked. - # config.last_attempt_warning = false + # config.last_attempt_warning = true # ==> Configuration for :recoverable # # Defines which key will be used when recovering the password for an account - # config.reset_password_keys = [ :email ] + # config.reset_password_keys = [:email] # Time interval you can reset your password with a reset password key. # Don't put a too small interval or your users won't have the time to # change their passwords. config.reset_password_within = 6.hours + # When set to false, does not sign a user in automatically after their password is + # reset. Defaults to true, so a user is signed in automatically after a reset. + # config.sign_in_after_reset_password = true + # ==> Configuration for :encryptable - # Allow you to use another encryption algorithm besides bcrypt (default). You can use - # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1, - # :authlogic_sha512 (then you should set stretches above to 20 for default behavior) - # and :restful_authentication_sha1 (then you should set stretches to 10, and copy - # REST_AUTH_SITE_KEY to pepper). + # Allow you to use another hashing or encryption algorithm besides bcrypt (default). + # You can use :sha1, :sha512 or algorithms from others authentication tools as + # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20 + # for default behavior) and :restful_authentication_sha1 (then you should set + # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper). # # Require the `devise-encryptable` gem when using anything other than bcrypt # config.encryptor = :sha512 @@ -220,7 +237,7 @@ # Set this configuration to false if you want /users/sign_out to sign out # only the current scope. By default, Devise signs out all scopes. - # config.sign_out_all_scopes = true + config.sign_out_all_scopes = false # ==> Navigation configuration # Lists the formats that should be treated as navigational. Formats like @@ -260,8 +277,7 @@ # The router that invoked `devise_for`, in the example above, would be: # config.router_name = :my_engine # - # When using omniauth, Devise cannot automatically set Omniauth path, + # When using OmniAuth, Devise cannot automatically set OmniAuth path, # so you need to do it manually. For the users scope, it would be: # config.omniauth_path_prefix = '/my_engine/users/auth' end - From bb39d0340e6eeaf441c34aa4d76cedf484ccda72 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 20:24:52 +0300 Subject: [PATCH 03/59] Remove routing specs --- app/models/user.rb | 2 +- spec/routing/registrar/domains_routing_spec.rb | 9 --------- spec/routing/registrar/sessions_routing_spec.rb | 9 --------- 3 files changed, 1 insertion(+), 19 deletions(-) delete mode 100644 spec/routing/registrar/domains_routing_spec.rb delete mode 100644 spec/routing/registrar/sessions_routing_spec.rb diff --git a/app/models/user.rb b/app/models/user.rb index b69e0250c7..150311e907 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,6 @@ class User < ActiveRecord::Base include Versions # version/user_version.rb - devise :trackable, :timeoutable + devise :database_authenticatable, :trackable, :timeoutable attr_accessor :phone diff --git a/spec/routing/registrar/domains_routing_spec.rb b/spec/routing/registrar/domains_routing_spec.rb deleted file mode 100644 index e30d1dd24d..0000000000 --- a/spec/routing/registrar/domains_routing_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'rails_helper' - -RSpec.describe Registrar::DomainsController do - describe 'routing' do - it 'routes to #index' do - expect(get: '/registrar/domains').to route_to('registrar/domains#index') - end - end -end diff --git a/spec/routing/registrar/sessions_routing_spec.rb b/spec/routing/registrar/sessions_routing_spec.rb deleted file mode 100644 index 24e075e58c..0000000000 --- a/spec/routing/registrar/sessions_routing_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'rails_helper' - -RSpec.describe Registrar::SessionsController do - describe 'routing' do - it 'routes to #login' do - expect(get: '/registrar/login').to route_to('registrar/sessions#login') - end - end -end From c538579d5b2a451f5b522b06b7ba6fb1f9eafd33 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 20:36:06 +0300 Subject: [PATCH 04/59] Remove `rememberable` and `lockable` modules from `AdminUser` --- app/models/admin_user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/admin_user.rb b/app/models/admin_user.rb index d76c42dec5..c2c2132262 100644 --- a/app/models/admin_user.rb +++ b/app/models/admin_user.rb @@ -9,7 +9,7 @@ class AdminUser < User ROLES = %w(user customer_service admin) # should not match to api_users roles - devise :database_authenticatable, :rememberable, :trackable, :validatable, :lockable + devise :database_authenticatable, :trackable, :validatable def self.min_password_length Devise.password_length.min From 756836001c9179c00575a9dbdd5e0fc3f2e4db35 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 20:39:52 +0300 Subject: [PATCH 05/59] Remove unused routes --- config/routes.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index ecb0544090..6fe587caa7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,7 +20,6 @@ # REGISTRAR ROUTES namespace :registrar do - resource :dashboard root 'dashboard#show' resources :invoices do @@ -247,9 +246,6 @@ end resources :delayed_jobs - - resource :dashboard - resources :epp_logs resources :repp_logs From 28416a3375580d604a278f2c400b49b7247eddae Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 20:43:23 +0300 Subject: [PATCH 06/59] Use singular controller --- app/controllers/admin/dashboard_controller.rb | 8 ++++++++ app/controllers/admin/dashboards_controller.rb | 9 --------- .../{dashboards/show.haml => dashboard/show.html.erb} | 0 config/routes.rb | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) create mode 100644 app/controllers/admin/dashboard_controller.rb delete mode 100644 app/controllers/admin/dashboards_controller.rb rename app/views/admin/{dashboards/show.haml => dashboard/show.html.erb} (100%) diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb new file mode 100644 index 0000000000..35efab5993 --- /dev/null +++ b/app/controllers/admin/dashboard_controller.rb @@ -0,0 +1,8 @@ +module Admin + class DashboardController < BaseController + authorize_resource class: false + + def show + end + end +end \ No newline at end of file diff --git a/app/controllers/admin/dashboards_controller.rb b/app/controllers/admin/dashboards_controller.rb deleted file mode 100644 index 52d82ea0af..0000000000 --- a/app/controllers/admin/dashboards_controller.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Admin - class DashboardsController < BaseController - authorize_resource class: false - - def show - redirect_to [:admin, :domains] if can? :show, Domain - end - end -end diff --git a/app/views/admin/dashboards/show.haml b/app/views/admin/dashboard/show.html.erb similarity index 100% rename from app/views/admin/dashboards/show.haml rename to app/views/admin/dashboard/show.html.erb diff --git a/config/routes.rb b/config/routes.rb index 6fe587caa7..7e0e998151 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -149,6 +149,8 @@ # ADMIN ROUTES namespace :admin do + root 'dashboard#show' + resources :keyrelays resources :zonefiles resources :zones, controller: 'dns/zones', except: %i[show destroy] @@ -258,8 +260,6 @@ authenticate :user do mount Que::Web, at: 'que' end - - root 'dashboards#show' end devise_for :users From 724d421f4410297cedad8d2c2d2c1f94ef9e46b9 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 20:50:02 +0300 Subject: [PATCH 07/59] Remove Devise FailureApp --- lib/devise_custom_failure.rb | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 lib/devise_custom_failure.rb diff --git a/lib/devise_custom_failure.rb b/lib/devise_custom_failure.rb deleted file mode 100644 index a8a9471734..0000000000 --- a/lib/devise_custom_failure.rb +++ /dev/null @@ -1,18 +0,0 @@ -class DeviseCustomFailure < Devise::FailureApp - def redirect_url - return registrant_login_url if request.original_fullpath.to_s.match(%r{^\/registrant}) - return registrar_login_url if request.original_fullpath.to_s.match(%r{^\/registrar}) - return '/admin' if request.original_fullpath.to_s.match(%r{^\/admin\/que}) - return admin_login_url if request.original_fullpath.to_s.match(%r{^\/admin}) - root_url - end - - # You need to override respond to eliminate recall - def respond - if http_auth? - http_auth - else - redirect - end - end -end From febbe1282d94f39530f7cc2f66e6b9fdc9770774 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 21:02:56 +0300 Subject: [PATCH 08/59] Fix links --- app/views/layouts/admin/base.haml | 2 +- app/views/layouts/devise.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/admin/base.haml b/app/views/layouts/admin/base.haml index 717c5015ca..8ec55c4249 100644 --- a/app/views/layouts/admin/base.haml +++ b/app/views/layouts/admin/base.haml @@ -19,7 +19,7 @@ %span.icon-bar %span.icon-bar %span.icon-bar - = link_to admin_dashboard_path, class: 'navbar-brand' do + = link_to admin_root_path, class: 'navbar-brand' do = ENV['app_name'] - if unstable_env.present? .text-center diff --git a/app/views/layouts/devise.haml b/app/views/layouts/devise.haml index 81248b86d6..aaa1c8e31e 100644 --- a/app/views/layouts/devise.haml +++ b/app/views/layouts/devise.haml @@ -18,7 +18,7 @@ %span.icon-bar %span.icon-bar %span.icon-bar - = link_to admin_dashboard_path, class: 'navbar-brand' do + = link_to admin_login_path, class: 'navbar-brand' do = ENV['app_name'] - if unstable_env.present? .text-center From 450a95f628676d7ca07c775f28d6c71fd36558ab Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 21:08:44 +0300 Subject: [PATCH 09/59] Revert "Remove routing specs" This reverts commit bb39d0340e6eeaf441c34aa4d76cedf484ccda72. --- app/models/user.rb | 2 +- spec/routing/registrar/domains_routing_spec.rb | 9 +++++++++ spec/routing/registrar/sessions_routing_spec.rb | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 spec/routing/registrar/domains_routing_spec.rb create mode 100644 spec/routing/registrar/sessions_routing_spec.rb diff --git a/app/models/user.rb b/app/models/user.rb index 150311e907..b69e0250c7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,6 @@ class User < ActiveRecord::Base include Versions # version/user_version.rb - devise :database_authenticatable, :trackable, :timeoutable + devise :trackable, :timeoutable attr_accessor :phone diff --git a/spec/routing/registrar/domains_routing_spec.rb b/spec/routing/registrar/domains_routing_spec.rb new file mode 100644 index 0000000000..e30d1dd24d --- /dev/null +++ b/spec/routing/registrar/domains_routing_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +RSpec.describe Registrar::DomainsController do + describe 'routing' do + it 'routes to #index' do + expect(get: '/registrar/domains').to route_to('registrar/domains#index') + end + end +end diff --git a/spec/routing/registrar/sessions_routing_spec.rb b/spec/routing/registrar/sessions_routing_spec.rb new file mode 100644 index 0000000000..24e075e58c --- /dev/null +++ b/spec/routing/registrar/sessions_routing_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +RSpec.describe Registrar::SessionsController do + describe 'routing' do + it 'routes to #login' do + expect(get: '/registrar/login').to route_to('registrar/sessions#login') + end + end +end From 02137b620ed2bff753162fb9c64cf85a4956f0f9 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 21:10:53 +0300 Subject: [PATCH 10/59] Remove routing specs --- spec/routing/registrar/domains_routing_spec.rb | 9 --------- spec/routing/registrar/sessions_routing_spec.rb | 9 --------- 2 files changed, 18 deletions(-) delete mode 100644 spec/routing/registrar/domains_routing_spec.rb delete mode 100644 spec/routing/registrar/sessions_routing_spec.rb diff --git a/spec/routing/registrar/domains_routing_spec.rb b/spec/routing/registrar/domains_routing_spec.rb deleted file mode 100644 index e30d1dd24d..0000000000 --- a/spec/routing/registrar/domains_routing_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'rails_helper' - -RSpec.describe Registrar::DomainsController do - describe 'routing' do - it 'routes to #index' do - expect(get: '/registrar/domains').to route_to('registrar/domains#index') - end - end -end diff --git a/spec/routing/registrar/sessions_routing_spec.rb b/spec/routing/registrar/sessions_routing_spec.rb deleted file mode 100644 index 24e075e58c..0000000000 --- a/spec/routing/registrar/sessions_routing_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'rails_helper' - -RSpec.describe Registrar::SessionsController do - describe 'routing' do - it 'routes to #login' do - expect(get: '/registrar/login').to route_to('registrar/sessions#login') - end - end -end From c31f507c254195094997fb6727195839afe6ca60 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 22:20:52 +0300 Subject: [PATCH 11/59] Specify Devise modules for each type of user --- app/models/admin_user.rb | 2 +- app/models/api_user.rb | 1 + app/models/registrant_user.rb | 2 ++ app/models/user.rb | 1 - 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/admin_user.rb b/app/models/admin_user.rb index c2c2132262..b53d6531a9 100644 --- a/app/models/admin_user.rb +++ b/app/models/admin_user.rb @@ -9,7 +9,7 @@ class AdminUser < User ROLES = %w(user customer_service admin) # should not match to api_users roles - devise :database_authenticatable, :trackable, :validatable + devise :database_authenticatable, :trackable, :validatable, :timeoutable def self.min_password_length Devise.password_length.min diff --git a/app/models/api_user.rb b/app/models/api_user.rb index ce32c4045b..3782920763 100644 --- a/app/models/api_user.rb +++ b/app/models/api_user.rb @@ -2,6 +2,7 @@ class ApiUser < User include EppErrors + devise :database_authenticatable, :trackable, :timeoutable def epp_code_map { diff --git a/app/models/registrant_user.rb b/app/models/registrant_user.rb index 12cae0d82a..1e1eb452f8 100644 --- a/app/models/registrant_user.rb +++ b/app/models/registrant_user.rb @@ -2,6 +2,8 @@ class RegistrantUser < User ACCEPTED_ISSUER = 'AS Sertifitseerimiskeskus' attr_accessor :idc_data + devise :database_authenticatable, :trackable, :timeoutable + def ability @ability ||= Ability.new(self) end diff --git a/app/models/user.rb b/app/models/user.rb index b69e0250c7..8968e27369 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,5 @@ class User < ActiveRecord::Base include Versions # version/user_version.rb - devise :trackable, :timeoutable attr_accessor :phone From 9684c8e59f58d2b7285b65122c3250fe7b97ac26 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 20 Jun 2018 12:21:22 +0300 Subject: [PATCH 12/59] Refactor Devise integration - Use scoped users - Use the named route helpers instead of hardcoded paths --- app/controllers/admin/base_controller.rb | 14 ++++- .../admin/pending_deletes_controller.rb | 4 +- .../admin/pending_updates_controller.rb | 4 +- app/controllers/admin/sessions_controller.rb | 23 +++++--- app/controllers/application_controller.rb | 56 ++---------------- .../registrant/contacts_controller.rb | 3 +- .../domain_delete_confirms_controller.rb | 2 +- .../domain_update_confirms_controller.rb | 2 +- .../registrant/domains_controller.rb | 4 +- .../registrant/sessions_controller.rb | 21 +++++-- app/controllers/registrant_controller.rb | 15 ++++- .../account_activities_controller.rb | 2 +- app/controllers/registrar/base_controller.rb | 14 +++-- .../registrar/bulk_change_controller.rb | 2 +- .../registrar/contacts_controller.rb | 6 +- .../registrar/current_user_controller.rb | 4 +- .../registrar/deposits_controller.rb | 2 +- app/controllers/registrar/depp_controller.rb | 10 ++-- .../registrar/domain_transfers_controller.rb | 2 +- .../registrar/domains_controller.rb | 8 +-- .../registrar/invoices_controller.rb | 2 +- .../registrar/nameservers_controller.rb | 2 +- .../registrar/profile_controller.rb | 4 +- .../registrar/sessions_controller.rb | 32 +++++----- .../registrar/tech_contacts_controller.rb | 2 +- app/views/admin/base/_menu.haml | 2 +- .../admin/sessions/{login.haml => new.haml} | 2 +- app/views/layouts/devise.haml | 2 +- .../layouts/registrant/application.html.erb | 6 +- .../sessions/{login.haml => new.haml} | 0 .../registrar/base/_current_user.html.erb | 4 +- app/views/registrar/invoices/index.haml | 4 +- .../sessions/{login.haml => new.haml} | 2 +- config/locales/registrar/sessions.en.yml | 2 +- config/routes.rb | 59 ++++++++----------- doc/controllers_complete.svg | 8 --- spec/features/registrar/home_link_spec.rb | 2 +- .../registrar/sign_in/mobile_id_spec.rb | 2 +- .../registrar/sign_in/password_spec.rb | 39 ------------ spec/features/registrar/sign_out_spec.rb | 14 ----- .../requests/registrar/ip_restriction_spec.rb | 12 ++-- spec/requests/registrar/linked_users_spec.rb | 9 ++- .../registrar/sign_in/password_spec.rb | 16 ----- spec/requests/registrar/sign_out_spec.rb | 18 ------ spec/support/features/session_helpers.rb | 4 +- spec/support/requests/session_helpers.rb | 6 +- test/integration/admin/login_test.rb | 27 +++++++++ test/integration/admin/logout_test.rb | 15 +++++ test/integration/admin/protected_area_test.rb | 22 +++++++ test/integration/registrar/login_test.rb | 39 ++++++++++++ test/integration/registrar/logout_test.rb | 15 +++++ .../registrar/protected_area_test.rb | 22 +++++++ 52 files changed, 313 insertions(+), 280 deletions(-) rename app/views/admin/sessions/{login.haml => new.haml} (84%) rename app/views/registrant/sessions/{login.haml => new.haml} (100%) rename app/views/registrar/sessions/{login.haml => new.haml} (88%) delete mode 100644 spec/features/registrar/sign_in/password_spec.rb delete mode 100644 spec/features/registrar/sign_out_spec.rb delete mode 100644 spec/requests/registrar/sign_in/password_spec.rb delete mode 100644 spec/requests/registrar/sign_out_spec.rb create mode 100644 test/integration/admin/login_test.rb create mode 100644 test/integration/admin/logout_test.rb create mode 100644 test/integration/admin/protected_area_test.rb create mode 100644 test/integration/registrar/login_test.rb create mode 100644 test/integration/registrar/logout_test.rb create mode 100644 test/integration/registrar/protected_area_test.rb diff --git a/app/controllers/admin/base_controller.rb b/app/controllers/admin/base_controller.rb index 7de43f7fc2..52ff6aa7ce 100644 --- a/app/controllers/admin/base_controller.rb +++ b/app/controllers/admin/base_controller.rb @@ -1,10 +1,20 @@ module Admin class BaseController < ApplicationController - before_action :authenticate_user! + before_action :authenticate_admin_user! helper_method :head_title_sufix def head_title_sufix t(:admin_head_title_sufix) end + + private + + def current_ability + @current_ability ||= Ability.new(current_admin_user) + end + + def user_for_paper_trail + current_admin_user.present? ? current_admin_user.id_role_username : 'public' + end end -end +end \ No newline at end of file diff --git a/app/controllers/admin/pending_deletes_controller.rb b/app/controllers/admin/pending_deletes_controller.rb index 86529da840..9cc8702c5a 100644 --- a/app/controllers/admin/pending_deletes_controller.rb +++ b/app/controllers/admin/pending_deletes_controller.rb @@ -6,7 +6,7 @@ class PendingDeletesController < BaseController def update authorize! :update, :pending - if registrant_verification.domain_registrant_delete_confirm!("admin #{current_user.username}") + if registrant_verification.domain_registrant_delete_confirm!("admin #{current_admin_user.username}") redirect_to admin_domain_path(@domain.id), notice: t(:pending_applied) else redirect_to admin_domain_path(@domain.id), alert: t(:failure) @@ -16,7 +16,7 @@ def update def destroy authorize! :destroy, :pending - if registrant_verification.domain_registrant_delete_reject!("admin #{current_user.username}") + if registrant_verification.domain_registrant_delete_reject!("admin #{current_admin_user.username}") redirect_to admin_domain_path(@domain.id), notice: t(:pending_removed) else redirect_to admin_domain_path(@domain.id), alert: t(:failure) diff --git a/app/controllers/admin/pending_updates_controller.rb b/app/controllers/admin/pending_updates_controller.rb index e402227e0c..4a2e5ec7c2 100644 --- a/app/controllers/admin/pending_updates_controller.rb +++ b/app/controllers/admin/pending_updates_controller.rb @@ -6,7 +6,7 @@ class PendingUpdatesController < BaseController def update authorize! :update, :pending - if registrant_verification.domain_registrant_change_confirm!("admin #{current_user.username}") + if registrant_verification.domain_registrant_change_confirm!("admin #{current_admin_user.username}") redirect_to admin_domain_path(@domain.id), notice: t(:pending_applied) else redirect_to edit_admin_domain_path(@domain.id), alert: t(:failure) @@ -15,7 +15,7 @@ def update def destroy authorize! :destroy, :pending - if registrant_verification.domain_registrant_change_reject!("admin #{current_user.username}") + if registrant_verification.domain_registrant_change_reject!("admin #{current_admin_user.username}") redirect_to admin_domain_path(@domain.id), notice: t(:pending_removed) else redirect_to admin_domain_path(@domain.id), alert: t(:failure) diff --git a/app/controllers/admin/sessions_controller.rb b/app/controllers/admin/sessions_controller.rb index 1bdcd30dcc..1e9be9eb7d 100644 --- a/app/controllers/admin/sessions_controller.rb +++ b/app/controllers/admin/sessions_controller.rb @@ -1,8 +1,6 @@ module Admin class SessionsController < Devise::SessionsController - skip_authorization_check only: :create - - def login + def new @admin_user = AdminUser.new end @@ -10,19 +8,28 @@ def create if params[:admin_user].blank? @admin_user = AdminUser.new flash[:alert] = 'Something went wrong' - return render 'login' + return render :new end @admin_user = AdminUser.find_by(username: params[:admin_user][:username]) @admin_user ||= AdminUser.new(username: params[:admin_user][:username]) if @admin_user.valid_password?(params[:admin_user][:password]) - sign_in @admin_user, event: :authentication - redirect_to admin_root_url, notice: I18n.t(:welcome) + sign_in_and_redirect(:admin_user, @admin_user, event: :authentication) else flash[:alert] = 'Authorization error' - render 'login' + render :new end end + + private + + def after_sign_in_path_for(resource_or_scope) + admin_root_path + end + + def after_sign_out_path_for(resource_or_scope) + new_admin_user_session_path + end end -end +end \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 87dabad018..518b752b7e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,63 +12,15 @@ class ApplicationController < ActionController::Base end rescue_from CanCan::AccessDenied do |exception| - redirect_to current_root_url, alert: exception.message + redirect_to root_url, alert: exception.message end - helper_method :registrant_request?, :registrar_request?, :admin_request?, :current_root_url helper_method :available_languages - def registrant_request? - request.path.match(/^\/registrant/) - end - - def registrar_request? - request.path.match(/^\/registrar/) - end - - def admin_request? - request.path.match(/^\/admin/) - end - - def current_root_url - if registrar_request? - registrar_root_url - elsif registrant_request? - registrant_login_url - elsif admin_request? - admin_root_url - end - end - - def after_sign_in_path_for(_resource) - rt = session[:user_return_to].to_s.presence - login_paths = [admin_login_path, registrar_login_path, '/login'] - return rt if rt && !login_paths.include?(rt) - current_root_url - end - - def after_sign_out_path_for(_resource) - if registrar_request? - registrar_login_url - elsif registrant_request? - registrant_login_url - elsif admin_request? - admin_login_url - end - end - def info_for_paper_trail { uuid: request.uuid } end - def user_for_paper_trail - user_log_str(current_user) - end - - def user_log_str(user) - user.nil? ? 'public' : user.id_role_username - end - def comma_support_for(parent_key, key) return if params[parent_key].blank? return if params[parent_key][key].blank? @@ -80,4 +32,8 @@ def comma_support_for(parent_key, key) def available_languages { en: 'English', et: 'Estonian' }.invert end -end + + def user_for_paper_trail + current_user.present? ? current_user.id_role_username : 'public' + end +end \ No newline at end of file diff --git a/app/controllers/registrant/contacts_controller.rb b/app/controllers/registrant/contacts_controller.rb index db6c279ebd..948bc1a949 100644 --- a/app/controllers/registrant/contacts_controller.rb +++ b/app/controllers/registrant/contacts_controller.rb @@ -2,7 +2,6 @@ class Registrant::ContactsController < RegistrantController helper_method :domain_ids def show @contact = Contact.where(id: contacts).find_by(id: params[:id]) - @current_user = current_user authorize! :read, @contact end @@ -19,7 +18,7 @@ def contacts def domain_ids @domain_ids ||= begin - ident_cc, ident = @current_user.registrant_ident.to_s.split '-' + ident_cc, ident = current_registrant_user.registrant_ident.to_s.split '-' BusinessRegistryCache.fetch_by_ident_and_cc(ident, ident_cc).associated_domain_ids end end diff --git a/app/controllers/registrant/domain_delete_confirms_controller.rb b/app/controllers/registrant/domain_delete_confirms_controller.rb index af8516462f..a57c6178a8 100644 --- a/app/controllers/registrant/domain_delete_confirms_controller.rb +++ b/app/controllers/registrant/domain_delete_confirms_controller.rb @@ -19,7 +19,7 @@ def update domain_name: @domain.name, verification_token: params[:token]) - initiator = current_user ? current_user.username : t(:user_not_authenticated) + initiator = current_registrant_user ? current_registrant_user.username : t(:user_not_authenticated) if params[:rejected] if @registrant_verification.domain_registrant_delete_reject!("email link #{initiator}") diff --git a/app/controllers/registrant/domain_update_confirms_controller.rb b/app/controllers/registrant/domain_update_confirms_controller.rb index ca91f0192d..feaa39d6ea 100644 --- a/app/controllers/registrant/domain_update_confirms_controller.rb +++ b/app/controllers/registrant/domain_update_confirms_controller.rb @@ -19,7 +19,7 @@ def update domain_name: @domain.name, verification_token: params[:token]) - initiator = current_user ? current_user.username : t(:user_not_authenticated) + initiator = current_registrant_user ? current_registrant_user.username : t(:user_not_authenticated) if params[:rejected] if @registrant_verification.domain_registrant_change_reject!("email link, #{initiator}") diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index 0e2f6eeaf6..06b24624db 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -54,13 +54,13 @@ def set_domain end def domains - ident_cc, ident = @current_user.registrant_ident.split '-' + ident_cc, ident = current_registrant_user.registrant_ident.split '-' begin BusinessRegistryCache.fetch_associated_domains ident, ident_cc rescue Soap::Arireg::NotAvailableError => error flash[:notice] = I18n.t(error.json[:message]) Rails.logger.fatal("[EXCEPTION] #{error.to_s}") - current_user.domains + current_registrant_user.domains end end diff --git a/app/controllers/registrant/sessions_controller.rb b/app/controllers/registrant/sessions_controller.rb index 80a23eb0a3..c29c920b04 100644 --- a/app/controllers/registrant/sessions_controller.rb +++ b/app/controllers/registrant/sessions_controller.rb @@ -1,7 +1,7 @@ class Registrant::SessionsController < Devise::SessionsController layout 'registrant/application' - def login + def new end def id @@ -10,11 +10,10 @@ def id @user = RegistrantUser.find_or_create_by_idc_data(id_code, id_issuer) if @user - sign_in(@user, event: :authentication) - redirect_to registrant_root_url + sign_in_and_redirect(:registrant_user, @user, event: :authentication) else flash[:alert] = t('login_failed_check_id_card') - redirect_to registrant_login_url + redirect_to new_registrant_user_session_url end end @@ -68,7 +67,7 @@ def mid_status when 'USER_AUTHENTICATED' @user = RegistrantUser.find_by(registrant_ident: "#{session[:user_country]}-#{session[:user_id_code]}") - sign_in @user + sign_in(:registrant_user, @user) flash[:notice] = t(:welcome) flash.keep(:notice) render js: "window.location = '#{registrant_root_path}'" @@ -97,4 +96,14 @@ def find_user_by_idc(idc) return User.new unless idc ApiUser.find_by(identity_code: idc) || User.new end -end + + private + + def after_sign_in_path_for(resource_or_scope) + registrant_root_path + end + + def after_sign_out_path_for(resource_or_scope) + new_registrant_user_session_path + end +end \ No newline at end of file diff --git a/app/controllers/registrant_controller.rb b/app/controllers/registrant_controller.rb index 72fb78a086..76be97a1fc 100644 --- a/app/controllers/registrant_controller.rb +++ b/app/controllers/registrant_controller.rb @@ -1,11 +1,22 @@ class RegistrantController < ApplicationController - before_action :authenticate_user! + before_action :authenticate_registrant_user! layout 'registrant/application' include Registrant::ApplicationHelper helper_method :head_title_sufix + def head_title_sufix t(:registrant_head_title_sufix) end -end + + private + + def current_ability + @current_ability ||= Ability.new(current_registrant_user, request.remote_ip) + end + + def user_for_paper_trail + current_registrant_user.present? ? current_registrant_user.id_role_username : 'public' + end +end \ No newline at end of file diff --git a/app/controllers/registrar/account_activities_controller.rb b/app/controllers/registrar/account_activities_controller.rb index 0b95d0122b..baa0256afb 100644 --- a/app/controllers/registrar/account_activities_controller.rb +++ b/app/controllers/registrar/account_activities_controller.rb @@ -4,7 +4,7 @@ class AccountActivitiesController < BaseController def index params[:q] ||= {} - account = current_user.registrar.cash_account + account = current_registrar_user.registrar.cash_account ca_cache = params[:q][:created_at_lteq] begin diff --git a/app/controllers/registrar/base_controller.rb b/app/controllers/registrar/base_controller.rb index 90f2f5210a..2bd2eb492f 100644 --- a/app/controllers/registrar/base_controller.rb +++ b/app/controllers/registrar/base_controller.rb @@ -2,7 +2,7 @@ class Registrar class BaseController < ApplicationController include Registrar::ApplicationHelper - before_action :authenticate_user! + before_action :authenticate_registrar_user! before_action :check_ip_restriction helper_method :depp_controller? helper_method :head_title_sufix @@ -10,21 +10,21 @@ class BaseController < ApplicationController protected def current_ability - @current_ability ||= Ability.new(current_user, request.remote_ip) + @current_ability ||= Ability.new(current_registrar_user, request.remote_ip) end private def check_ip_restriction ip_restriction = Authorization::RestrictedIP.new(request.ip) - allowed = ip_restriction.can_access_registrar_area?(current_user.registrar) + allowed = ip_restriction.can_access_registrar_area?(current_registrar_user.registrar) return if allowed - sign_out current_user + sign_out current_registrar_user flash[:alert] = t('registrar.authorization.ip_not_allowed', ip: request.ip) - redirect_to registrar_login_url + redirect_to new_registrar_user_session_url end def depp_controller? @@ -34,5 +34,9 @@ def depp_controller? def head_title_sufix t(:registrar_head_title_sufix) end + + def user_for_paper_trail + current_registrar_user.present? ? current_registrar_user.id_role_username : 'public' + end end end diff --git a/app/controllers/registrar/bulk_change_controller.rb b/app/controllers/registrar/bulk_change_controller.rb index 562344a460..441127f6c7 100644 --- a/app/controllers/registrar/bulk_change_controller.rb +++ b/app/controllers/registrar/bulk_change_controller.rb @@ -10,7 +10,7 @@ def new private def available_contacts - current_user.registrar.contacts.order(:name).pluck(:name, :code) + current_registrar_user.registrar.contacts.order(:name).pluck(:name, :code) end def default_tab diff --git a/app/controllers/registrar/contacts_controller.rb b/app/controllers/registrar/contacts_controller.rb index cb059641ec..f343f9bfb5 100644 --- a/app/controllers/registrar/contacts_controller.rb +++ b/app/controllers/registrar/contacts_controller.rb @@ -21,11 +21,11 @@ def index end if params[:statuses_contains] - contacts = current_user.registrar.contacts.includes(:registrar).where( + contacts = current_registrar_user.registrar.contacts.includes(:registrar).where( "contacts.statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}" ) else - contacts = current_user.registrar.contacts.includes(:registrar) + contacts = current_registrar_user.registrar.contacts.includes(:registrar) end normalize_search_parameters do @@ -45,7 +45,7 @@ def download_list @contacts = Contact.find_by(name: params[:q][:name_matches]) end - contacts = current_user.registrar.contacts.includes(:registrar) + contacts = current_registrar_user.registrar.contacts.includes(:registrar) contacts = contacts.filter_by_states(params[:statuses_contains]) if params[:statuses_contains] normalize_search_parameters do diff --git a/app/controllers/registrar/current_user_controller.rb b/app/controllers/registrar/current_user_controller.rb index 266e4b9158..624ee294ef 100644 --- a/app/controllers/registrar/current_user_controller.rb +++ b/app/controllers/registrar/current_user_controller.rb @@ -3,9 +3,9 @@ class CurrentUserController < BaseController skip_authorization_check def switch - raise 'Cannot switch to unlinked user' unless current_user.linked_with?(new_user) + raise 'Cannot switch to unlinked user' unless current_registrar_user.linked_with?(new_user) - sign_in(new_user) + sign_in(:registrar_user, new_user) redirect_to :back, notice: t('.switched', new_user: new_user) end diff --git a/app/controllers/registrar/deposits_controller.rb b/app/controllers/registrar/deposits_controller.rb index ec6d139779..6b10ccdd3e 100644 --- a/app/controllers/registrar/deposits_controller.rb +++ b/app/controllers/registrar/deposits_controller.rb @@ -7,7 +7,7 @@ def new end def create - @deposit = Deposit.new(deposit_params.merge(registrar: current_user.registrar)) + @deposit = Deposit.new(deposit_params.merge(registrar: current_registrar_user.registrar)) @invoice = @deposit.issue_prepayment_invoice if @invoice&.persisted? diff --git a/app/controllers/registrar/depp_controller.rb b/app/controllers/registrar/depp_controller.rb index 234ab40b7c..87269b160d 100644 --- a/app/controllers/registrar/depp_controller.rb +++ b/app/controllers/registrar/depp_controller.rb @@ -5,13 +5,13 @@ class DeppController < BaseController rescue_from(Errno::ECONNRESET, Errno::ECONNREFUSED) do |exception| logger.error 'COULD NOT CONNECT TO REGISTRY' logger.error exception.backtrace.join("\n") - redirect_to registrar_login_url, alert: t(:no_connection_to_registry) + redirect_to new_registrar_user_session_url, alert: t(:no_connection_to_registry) end before_action :authenticate_user def authenticate_user - redirect_to registrar_login_url and return unless depp_current_user + redirect_to new_registrar_user_session_url and return unless depp_current_user end def depp_controller? @@ -19,10 +19,10 @@ def depp_controller? end def depp_current_user - return nil unless current_user + return nil unless current_registrar_user @depp_current_user ||= Depp::User.new( - tag: current_user.username, - password: current_user.password + tag: current_registrar_user.username, + password: current_registrar_user.password ) end diff --git a/app/controllers/registrar/domain_transfers_controller.rb b/app/controllers/registrar/domain_transfers_controller.rb index 7c0925f032..f65f3cece5 100644 --- a/app/controllers/registrar/domain_transfers_controller.rb +++ b/app/controllers/registrar/domain_transfers_controller.rb @@ -21,7 +21,7 @@ def create uri = URI.parse("#{ENV['repp_url']}domain_transfers") request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json') request.body = { data: { domainTransfers: domain_transfers } }.to_json - request.basic_auth(current_user.username, current_user.password) + request.basic_auth(current_registrar_user.username, current_registrar_user.password) if Rails.env.test? diff --git a/app/controllers/registrar/domains_controller.rb b/app/controllers/registrar/domains_controller.rb index 7cb8fdfbee..d2969bb69b 100644 --- a/app/controllers/registrar/domains_controller.rb +++ b/app/controllers/registrar/domains_controller.rb @@ -16,11 +16,11 @@ def index end if params[:statuses_contains] - domains = current_user.registrar.domains.includes(:registrar, :registrant).where( + domains = current_registrar_user.registrar.domains.includes(:registrar, :registrant).where( "statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}" ) else - domains = current_user.registrar.domains.includes(:registrar, :registrant) + domains = current_registrar_user.registrar.domains.includes(:registrar, :registrant) end normalize_search_parameters do @@ -142,7 +142,7 @@ def renew def search_contacts authorize! :create, Depp::Domain - scope = current_user.registrar.contacts.limit(10) + scope = current_registrar_user.registrar.contacts.limit(10) if params[:query].present? escaped_str = ActiveRecord::Base.connection.quote_string params[:query] scope = scope.where("name ilike '%#{escaped_str}%' OR code ilike '%#{escaped_str}%' ") @@ -159,7 +159,7 @@ def init_domain def contacts - current_user.registrar.contacts + current_registrar_user.registrar.contacts end def normalize_search_parameters diff --git a/app/controllers/registrar/invoices_controller.rb b/app/controllers/registrar/invoices_controller.rb index 735df91a31..548e47ebe1 100644 --- a/app/controllers/registrar/invoices_controller.rb +++ b/app/controllers/registrar/invoices_controller.rb @@ -6,7 +6,7 @@ class InvoicesController < BaseController def index params[:q] ||= {} - invoices = current_user.registrar.invoices.includes(:invoice_items, :account_activity) + invoices = current_registrar_user.registrar.invoices.includes(:invoice_items, :account_activity) normalize_search_parameters do @q = invoices.search(params[:q]) diff --git a/app/controllers/registrar/nameservers_controller.rb b/app/controllers/registrar/nameservers_controller.rb index b6f7af8291..90dd5afb42 100644 --- a/app/controllers/registrar/nameservers_controller.rb +++ b/app/controllers/registrar/nameservers_controller.rb @@ -12,7 +12,7 @@ def update attributes: { hostname: params[:new_hostname], ipv4: ipv4, ipv6: ipv6 } } }.to_json - request.basic_auth(current_user.username, current_user.password) + request.basic_auth(current_registrar_user.username, current_registrar_user.password) if Rails.env.test? response = Net::HTTP.start(uri.hostname, uri.port, diff --git a/app/controllers/registrar/profile_controller.rb b/app/controllers/registrar/profile_controller.rb index 5f202a894d..1fe6d6a0b6 100644 --- a/app/controllers/registrar/profile_controller.rb +++ b/app/controllers/registrar/profile_controller.rb @@ -5,13 +5,13 @@ class ProfileController < BaseController helper_method :linked_users def show - @user = current_user + @user = current_registrar_user end private def linked_users - current_user.linked_users + current_registrar_user.linked_users end end end diff --git a/app/controllers/registrar/sessions_controller.rb b/app/controllers/registrar/sessions_controller.rb index 1a8b195ee8..d7a6907521 100644 --- a/app/controllers/registrar/sessions_controller.rb +++ b/app/controllers/registrar/sessions_controller.rb @@ -3,7 +3,7 @@ class SessionsController < Devise::SessionsController before_action :check_ip_restriction helper_method :depp_controller? - def login + def new @depp_user = Depp::User.new end @@ -30,7 +30,7 @@ def create unless @api_user @depp_user.errors.add(:base, t(:no_such_user)) - render 'login' and return + render :new and return end if @depp_user.pki @@ -41,14 +41,13 @@ def create if @depp_user.errors.none? if @api_user.active? - sign_in @api_user - redirect_to registrar_root_url + sign_in_and_redirect(:registrar_user, @api_user) else @depp_user.errors.add(:base, :not_active) - render 'login' + render :new end else - render 'login' + render :new end end @@ -56,11 +55,10 @@ def id @user = ApiUser.find_by_idc_data_and_allowed(request.env['SSL_CLIENT_S_DN'], request.ip) if @user - sign_in(@user, event: :authentication) - redirect_to registrar_root_url + sign_in_and_redirect(:registrar_user, @user, event: :authentication) else flash[:alert] = t('no_such_user') - redirect_to registrar_login_url + redirect_to new_registrar_user_session_url end end @@ -91,7 +89,7 @@ def mid @user = find_user_by_idc_and_allowed(response.user_id_code) else @user = find_user_by_idc(response.user_id_code) - end + end if @user.persisted? session[:user_id_code] = response.user_id_code @@ -117,7 +115,7 @@ def mid_status render json: { message: t(:check_your_phone_for_confirmation_code) }, status: :ok when 'USER_AUTHENTICATED' @user = find_user_by_idc_and_allowed(session[:user_id_code]) - sign_in @user + sign_in(:registrar_user, @user) flash[:notice] = t(:welcome) flash.keep(:notice) render js: "window.location = '#{registrar_root_url}'" @@ -163,8 +161,6 @@ def find_user_by_idc_and_allowed(idc) end end - - def check_ip_restriction ip_restriction = Authorization::RestrictedIP.new(request.ip) allowed = ip_restriction.can_access_registrar_area_sign_in_page? @@ -173,5 +169,13 @@ def check_ip_restriction render text: t('registrar.authorization.ip_not_allowed', ip: request.ip) end + + def after_sign_in_path_for(resource_or_scope) + registrar_root_path + end + + def after_sign_out_path_for(resource_or_scope) + new_registrar_user_session_path + end end -end +end \ No newline at end of file diff --git a/app/controllers/registrar/tech_contacts_controller.rb b/app/controllers/registrar/tech_contacts_controller.rb index 9d4568ad6a..fe3dd86da4 100644 --- a/app/controllers/registrar/tech_contacts_controller.rb +++ b/app/controllers/registrar/tech_contacts_controller.rb @@ -8,7 +8,7 @@ def update request = Net::HTTP::Patch.new(uri) request.set_form_data(current_contact_id: params[:current_contact_id], new_contact_id: params[:new_contact_id]) - request.basic_auth(current_user.username, current_user.password) + request.basic_auth(current_registrar_user.username, current_registrar_user.password) if Rails.env.test? response = Net::HTTP.start(uri.hostname, uri.port, diff --git a/app/views/admin/base/_menu.haml b/app/views/admin/base/_menu.haml index 7c813e43e8..957b7826da 100644 --- a/app/views/admin/base/_menu.haml +++ b/app/views/admin/base/_menu.haml @@ -41,4 +41,4 @@ - if signed_in? %ul.nav.navbar-nav.navbar-right - %li= link_to t(:log_out, user: current_user), '/admin/logout' + %li= link_to t(:log_out, user: current_admin_user), destroy_admin_user_session_path, method: :delete, class: 'navbar-link' diff --git a/app/views/admin/sessions/login.haml b/app/views/admin/sessions/new.haml similarity index 84% rename from app/views/admin/sessions/login.haml rename to app/views/admin/sessions/new.haml index 1ecca10aed..d37461c855 100644 --- a/app/views/admin/sessions/login.haml +++ b/app/views/admin/sessions/new.haml @@ -3,7 +3,7 @@ %h2.form-signin-heading.text-center Eesti Interneti SA %hr .form-signin - = form_for(@admin_user, url: admin_sessions_path, method: :create, html: {class: 'form-signin'}) do |f| + = form_for(@admin_user, url: admin_user_session_path, html: {class: 'form-signin'}) do |f| = render 'admin/shared/errors', object: f.object - error_class = f.object.errors.any? ? 'has-error' : '' diff --git a/app/views/layouts/devise.haml b/app/views/layouts/devise.haml index aaa1c8e31e..839290cef2 100644 --- a/app/views/layouts/devise.haml +++ b/app/views/layouts/devise.haml @@ -18,7 +18,7 @@ %span.icon-bar %span.icon-bar %span.icon-bar - = link_to admin_login_path, class: 'navbar-brand' do + = link_to new_admin_user_session_path, class: 'navbar-brand' do = ENV['app_name'] - if unstable_env.present? .text-center diff --git a/app/views/layouts/registrant/application.html.erb b/app/views/layouts/registrant/application.html.erb index 075ac46526..6d47b72cfb 100644 --- a/app/views/layouts/registrant/application.html.erb +++ b/app/views/layouts/registrant/application.html.erb @@ -37,7 +37,7 @@ <% end %> <% end %> - <% if current_user %> + <% if current_registrant_user %>