diff --git a/app/controllers/registrar/sessions_controller.rb b/app/controllers/registrar/sessions_controller.rb index c45c930e1..f9a60c6b1 100644 --- a/app/controllers/registrar/sessions_controller.rb +++ b/app/controllers/registrar/sessions_controller.rb @@ -3,12 +3,8 @@ class Registrar before_action :check_ip_restriction helper_method :depp_controller? - def new - @depp_user = Depp::User.new - end - def create - @depp_user = Depp::User.new(params[:depp_user].merge(pki: !(Rails.env.development? || Rails.env.test?))) + @depp_user = Depp::User.new(depp_user_params) if @depp_user.pki && request.env['HTTP_SSL_CLIENT_S_DN_CN'].blank? @depp_user.errors.add(:base, :webserver_missing_user_name_directive) @@ -26,12 +22,12 @@ class Registrar @depp_user.errors.add(:base, :webserver_client_cert_directive_should_be_required) end - @api_user = ApiUser.find_by(username: params[:depp_user][:tag], - plain_text_password: params[:depp_user][:password]) + @api_user = ApiUser.find_by(username: sign_in_params[:username], + plain_text_password: sign_in_params[:password]) unless @api_user @depp_user.errors.add(:base, t(:no_such_user)) - render :new and return + show_error and return end if @depp_user.pki @@ -45,10 +41,10 @@ class Registrar sign_in_and_redirect(:registrar_user, @api_user) else @depp_user.errors.add(:base, :not_active) - render :new + show_error and return end else - render :new + show_error and return end end @@ -190,5 +186,16 @@ class Registrar def user_for_paper_trail current_registrar_user ? current_registrar_user.id_role_username : 'anonymous' end + + def depp_user_params + params = sign_in_params + params[:tag] = params.delete(:username) + params.merge!(pki: !(Rails.env.development? || Rails.env.test?)) + params + end + + def show_error + redirect_to new_registrar_user_session_url, alert: @depp_user.errors.full_messages.first + end end end \ No newline at end of file diff --git a/app/models/api_user.rb b/app/models/api_user.rb index ccc71eac0..ae9ed0b28 100644 --- a/app/models/api_user.rb +++ b/app/models/api_user.rb @@ -2,7 +2,7 @@ require 'open3' class ApiUser < User include EppErrors - devise :database_authenticatable, :trackable, :timeoutable + devise :database_authenticatable, :trackable, :timeoutable, authentication_keys: [:username] def epp_code_map { diff --git a/app/views/registrar/sessions/new.html.erb b/app/views/registrar/sessions/new.html.erb index e3f8d6128..eda6af9fc 100644 --- a/app/views/registrar/sessions/new.html.erb +++ b/app/views/registrar/sessions/new.html.erb @@ -1,24 +1,29 @@
- -
- <%= form_for @depp_user, url: registrar_user_session_path, html: { class: 'form-signin' } do |f| %> - <%= render 'registrar/shared/errors', object: f.object %> - <% error_class = f.object.errors.any? ? 'has-error' : '' %> -
- <%= f.text_field :tag, class: 'form-control', placeholder: t(:username), required: true %> - <%= f.password_field :password, class: 'form-control', autocomplete: 'off', placeholder: t(:password), required: true %> -
- +

<%= t(:log_in) %>

+ +
+ + <%= form_for resource, as: resource_name, url: session_path(resource_name) do |f| %> + <%= f.text_field :username, placeholder: ApiUser.human_attribute_name(:username), + autofocus: true, + required: true, + class: 'form-control' %> + <%= f.password_field :password, + autocomplete: 'off', + placeholder: ApiUser.human_attribute_name(:password), + required: true, + class: 'form-control' %> + + <%= f.submit t('.submit_btn'), class: 'btn btn-lg btn-primary btn-block' %> <% end %> -
+ +
+ <%= link_to '/registrar/login/mid', id: 'login-with-mobile-id-btn' do %> <%= image_tag 'mid.gif' %> <% end %> + <%= link_to '/registrar/id', method: :post do %> <%= image_tag 'id_card.gif' %> <% end %> diff --git a/app/views/registrar/shared/_errors.haml b/app/views/registrar/shared/_errors.haml deleted file mode 100644 index 50eb6de12..000000000 --- a/app/views/registrar/shared/_errors.haml +++ /dev/null @@ -1,5 +0,0 @@ -- if object.errors.any? - %p.text-danger - - object.errors.each do |attr, err| - = err - %br diff --git a/config/locales/registrar/sessions.en.yml b/config/locales/registrar/sessions.en.yml index 55d72979c..2278687ec 100644 --- a/config/locales/registrar/sessions.en.yml +++ b/config/locales/registrar/sessions.en.yml @@ -2,6 +2,6 @@ en: registrar: sessions: new: - login_btn: Login + submit_btn: Login login_mid: login_btn: Login diff --git a/test/system/registrar_area/sign_in/password_test.rb b/test/system/registrar_area/sign_in/password_test.rb index 6878cd119..9b624d75f 100644 --- a/test/system/registrar_area/sign_in/password_test.rb +++ b/test/system/registrar_area/sign_in/password_test.rb @@ -7,8 +7,8 @@ class RegistrarAreaPasswordSignInTest < ApplicationSystemTestCase def test_correct_username_and_password visit new_registrar_user_session_url - fill_in 'depp_user_tag', with: @user.username - fill_in 'depp_user_password', with: 'testtest' + fill_in 'registrar_user_username', with: @user.username + fill_in 'registrar_user_password', with: 'testtest' click_button 'Login' assert_text 'Log out' @@ -17,8 +17,8 @@ class RegistrarAreaPasswordSignInTest < ApplicationSystemTestCase def test_wrong_password visit new_registrar_user_session_url - fill_in 'depp_user_tag', with: @user.username - fill_in 'depp_user_password', with: 'wrong' + fill_in 'registrar_user_username', with: @user.username + fill_in 'registrar_user_password', with: 'wrong' click_button 'Login' assert_text 'No such user' @@ -29,8 +29,8 @@ class RegistrarAreaPasswordSignInTest < ApplicationSystemTestCase @user.update!(active: false) visit new_registrar_user_session_url - fill_in 'depp_user_tag', with: @user.username - fill_in 'depp_user_password', with: 'testtest' + fill_in 'registrar_user_username', with: @user.username + fill_in 'registrar_user_password', with: 'testtest' click_button 'Login' assert_text 'User is not active'