mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 13:15:40 +02:00
Use standard login form
This commit is contained in:
parent
080defa228
commit
1d95c1ccbc
6 changed files with 45 additions and 38 deletions
|
@ -3,12 +3,8 @@ class Registrar
|
||||||
before_action :check_ip_restriction
|
before_action :check_ip_restriction
|
||||||
helper_method :depp_controller?
|
helper_method :depp_controller?
|
||||||
|
|
||||||
def new
|
|
||||||
@depp_user = Depp::User.new
|
|
||||||
end
|
|
||||||
|
|
||||||
def create
|
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?
|
if @depp_user.pki && request.env['HTTP_SSL_CLIENT_S_DN_CN'].blank?
|
||||||
@depp_user.errors.add(:base, :webserver_missing_user_name_directive)
|
@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)
|
@depp_user.errors.add(:base, :webserver_client_cert_directive_should_be_required)
|
||||||
end
|
end
|
||||||
|
|
||||||
@api_user = ApiUser.find_by(username: params[:depp_user][:tag],
|
@api_user = ApiUser.find_by(username: sign_in_params[:username],
|
||||||
plain_text_password: params[:depp_user][:password])
|
plain_text_password: sign_in_params[:password])
|
||||||
|
|
||||||
unless @api_user
|
unless @api_user
|
||||||
@depp_user.errors.add(:base, t(:no_such_user))
|
@depp_user.errors.add(:base, t(:no_such_user))
|
||||||
render :new and return
|
show_error and return
|
||||||
end
|
end
|
||||||
|
|
||||||
if @depp_user.pki
|
if @depp_user.pki
|
||||||
|
@ -45,10 +41,10 @@ class Registrar
|
||||||
sign_in_and_redirect(:registrar_user, @api_user)
|
sign_in_and_redirect(:registrar_user, @api_user)
|
||||||
else
|
else
|
||||||
@depp_user.errors.add(:base, :not_active)
|
@depp_user.errors.add(:base, :not_active)
|
||||||
render :new
|
show_error and return
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
render :new
|
show_error and return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -190,5 +186,16 @@ class Registrar
|
||||||
def user_for_paper_trail
|
def user_for_paper_trail
|
||||||
current_registrar_user ? current_registrar_user.id_role_username : 'anonymous'
|
current_registrar_user ? current_registrar_user.id_role_username : 'anonymous'
|
||||||
end
|
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
|
||||||
end
|
end
|
|
@ -2,7 +2,7 @@ require 'open3'
|
||||||
|
|
||||||
class ApiUser < User
|
class ApiUser < User
|
||||||
include EppErrors
|
include EppErrors
|
||||||
devise :database_authenticatable, :trackable, :timeoutable
|
devise :database_authenticatable, :trackable, :timeoutable, authentication_keys: [:username]
|
||||||
|
|
||||||
def epp_code_map
|
def epp_code_map
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,24 +1,29 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="form-signin col-md-6 center-block text-center">
|
<div class="form-signin col-md-6 center-block text-center">
|
||||||
<h2 class="form-signin-heading text-center">
|
<h1 class="form-signin-heading text-center"><%= t(:log_in) %></h1>
|
||||||
<%= t(:log_in) %>
|
|
||||||
</h2>
|
<hr>
|
||||||
<hr/>
|
|
||||||
<%= form_for @depp_user, url: registrar_user_session_path, html: { class: 'form-signin' } do |f| %>
|
<%= form_for resource, as: resource_name, url: session_path(resource_name) do |f| %>
|
||||||
<%= render 'registrar/shared/errors', object: f.object %>
|
<%= f.text_field :username, placeholder: ApiUser.human_attribute_name(:username),
|
||||||
<% error_class = f.object.errors.any? ? 'has-error' : '' %>
|
autofocus: true,
|
||||||
<div class="<%= error_class %>">
|
required: true,
|
||||||
<%= f.text_field :tag, class: 'form-control', placeholder: t(:username), required: true %>
|
class: 'form-control' %>
|
||||||
<%= f.password_field :password, class: 'form-control', autocomplete: 'off', placeholder: t(:password), required: true %>
|
<%= f.password_field :password,
|
||||||
</div>
|
autocomplete: 'off',
|
||||||
<button class="btn btn-lg btn-primary btn-block" type="submit">
|
placeholder: ApiUser.human_attribute_name(:password),
|
||||||
<%= t '.login_btn' %>
|
required: true,
|
||||||
</button>
|
class: 'form-control' %>
|
||||||
|
|
||||||
|
<%= f.submit t('.submit_btn'), class: 'btn btn-lg btn-primary btn-block' %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<hr/>
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
<%= link_to '/registrar/login/mid', id: 'login-with-mobile-id-btn' do %>
|
<%= link_to '/registrar/login/mid', id: 'login-with-mobile-id-btn' do %>
|
||||||
<%= image_tag 'mid.gif' %>
|
<%= image_tag 'mid.gif' %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= link_to '/registrar/id', method: :post do %>
|
<%= link_to '/registrar/id', method: :post do %>
|
||||||
<%= image_tag 'id_card.gif' %>
|
<%= image_tag 'id_card.gif' %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
- if object.errors.any?
|
|
||||||
%p.text-danger
|
|
||||||
- object.errors.each do |attr, err|
|
|
||||||
= err
|
|
||||||
%br
|
|
|
@ -2,6 +2,6 @@ en:
|
||||||
registrar:
|
registrar:
|
||||||
sessions:
|
sessions:
|
||||||
new:
|
new:
|
||||||
login_btn: Login
|
submit_btn: Login
|
||||||
login_mid:
|
login_mid:
|
||||||
login_btn: Login
|
login_btn: Login
|
||||||
|
|
|
@ -7,8 +7,8 @@ class RegistrarAreaPasswordSignInTest < ApplicationSystemTestCase
|
||||||
|
|
||||||
def test_correct_username_and_password
|
def test_correct_username_and_password
|
||||||
visit new_registrar_user_session_url
|
visit new_registrar_user_session_url
|
||||||
fill_in 'depp_user_tag', with: @user.username
|
fill_in 'registrar_user_username', with: @user.username
|
||||||
fill_in 'depp_user_password', with: 'testtest'
|
fill_in 'registrar_user_password', with: 'testtest'
|
||||||
click_button 'Login'
|
click_button 'Login'
|
||||||
|
|
||||||
assert_text 'Log out'
|
assert_text 'Log out'
|
||||||
|
@ -17,8 +17,8 @@ class RegistrarAreaPasswordSignInTest < ApplicationSystemTestCase
|
||||||
|
|
||||||
def test_wrong_password
|
def test_wrong_password
|
||||||
visit new_registrar_user_session_url
|
visit new_registrar_user_session_url
|
||||||
fill_in 'depp_user_tag', with: @user.username
|
fill_in 'registrar_user_username', with: @user.username
|
||||||
fill_in 'depp_user_password', with: 'wrong'
|
fill_in 'registrar_user_password', with: 'wrong'
|
||||||
click_button 'Login'
|
click_button 'Login'
|
||||||
|
|
||||||
assert_text 'No such user'
|
assert_text 'No such user'
|
||||||
|
@ -29,8 +29,8 @@ class RegistrarAreaPasswordSignInTest < ApplicationSystemTestCase
|
||||||
@user.update!(active: false)
|
@user.update!(active: false)
|
||||||
|
|
||||||
visit new_registrar_user_session_url
|
visit new_registrar_user_session_url
|
||||||
fill_in 'depp_user_tag', with: @user.username
|
fill_in 'registrar_user_username', with: @user.username
|
||||||
fill_in 'depp_user_password', with: 'testtest'
|
fill_in 'registrar_user_password', with: 'testtest'
|
||||||
click_button 'Login'
|
click_button 'Login'
|
||||||
|
|
||||||
assert_text 'User is not active'
|
assert_text 'User is not active'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue