This commit is contained in:
Priit Tark 2015-05-21 11:24:44 +03:00
parent 17bf5c373e
commit d444552b9b
9 changed files with 31 additions and 273 deletions

View file

@ -1,32 +0,0 @@
class Registrant::DeppController < RegistrantController # EPP controller
helper_method :depp_current_user
rescue_from(Errno::ECONNRESET, Errno::ECONNREFUSED) do |_exception|
redirect_to registrant_login_url, alert: t(:no_connection_to_registry)
end
before_action :authenticate_user
def authenticate_user
redirect_to registrant_login_url and return unless depp_current_user
end
def depp_controller?
true
end
def depp_current_user
return nil unless current_user
@depp_current_user ||= Depp::User.new(
tag: current_user.username,
password: current_user.password
)
end
def response_ok?
@data.css('result').each do |x|
success_codes = %(1000, 1001, 1300, 1301)
return false unless success_codes.include?(x['code'])
end
true
end
end

View file

@ -1,119 +1,5 @@
class Registrant::DomainsController < Registrant::DeppController # EPP controller
before_action :init_domain, except: :new
class Registrant::DomainsController < RegistrantController
def index
authorize! :view, Depp::Domain
limit, offset = pagination_details
res = depp_current_user.repp_request('domains', { details: true, limit: limit, offset: offset })
if res.code == '200'
@response = res.parsed_body.with_indifferent_access
@contacts = @response ? @response[:contacts] : []
@paginatable_array = Kaminari.paginate_array(
[], total_count: @response[:total_number_of_records]
).page(params[:page]).per(limit)
end
flash.now[:epp_results] = [{ 'code' => res.code, 'msg' => res.message }]
end
def info
authorize! :view, Depp::Domain
@data = @domain.info(params[:domain_name]) if params[:domain_name]
if response_ok?
render 'info'
else
flash[:alert] = t(:domain_not_found)
redirect_to registrant_domains_url and return
end
end
def check
authorize! :view, Depp::Domain
if params[:domain_name]
@data = @domain.check(params[:domain_name])
render 'check_index' and return unless response_ok?
else
render 'check_index'
end
end
def new
authorize! :create, Depp::Domain
@domain_params = Depp::Domain.default_params
end
def create
authorize! :create, Depp::Domain
@domain_params = params[:domain]
@data = @domain.create(@domain_params)
if response_ok?
redirect_to info_registrant_domains_url(domain_name: @domain_params[:name])
else
render 'new'
end
end
def edit
authorize! :update, Depp::Domain
@data = @domain.info(params[:domain_name])
@domain_params = Depp::Domain.construct_params_from_server_data(@data)
end
def update
authorize! :update, Depp::Domain
@domain_params = params[:domain]
@data = @domain.update(@domain_params)
if response_ok?
redirect_to info_registrant_domains_url(domain_name: @domain_params[:name])
else
params[:domain_name] = @domain_params[:name]
render 'new'
end
end
def delete
authorize! :delete, Depp::Domain
end
def destroy
authorize! :delete, Depp::Domain
@data = @domain.delete(params[:domain])
@results = @data.css('result')
if response_ok?
params[:domain_name] = nil
render 'info_index'
else
params[:domain_name] = params[:domain][:name]
render 'delete'
end
end
def renew
authorize! :renew, Depp::Domain
if params[:domain_name] && params[:cur_exp_date]
@data = @domain.renew(params)
render 'renew_index' and return unless response_ok?
else
render 'renew_index'
end
end
def transfer
authorize! :transfer, Depp::Domain
if params[:domain_name]
@data = @domain.transfer(params)
render 'transfer_index' and return unless response_ok?
else
render 'transfer_index'
end
end
private
def init_domain
@domain = Depp::Domain.new(current_user: depp_current_user)
# @domains = [Domain.last]
end
end

View file

@ -1,51 +1,15 @@
class Registrant::SessionsController < Devise::SessionsController
layout 'registrant/application'
helper_method :depp_controller?
def depp_controller?
false
end
def login
@depp_user = Depp::User.new
end
# rubocop:disable Metrics/PerceivedComplexity
# rubocop:disable Metrics/CyclomaticComplexity
def create
@depp_user = Depp::User.new(params[:depp_user].merge(
pki: !Rails.env.development?
)
)
if @depp_user.pki && request.env['HTTP_SSL_CLIENT_S_DN_CN'].blank?
@depp_user.errors.add(:base, :webserver_missing_user_name_directive)
end
if @depp_user.pki && request.env['HTTP_SSL_CLIENT_S_DN_CN'] == '(null)'
@depp_user.errors.add(:base, :webserver_user_name_directive_should_be_required)
end
if @depp_user.pki && request.env['HTTP_SSL_CLIENT_S_DN_CN'] != params[:depp_user][:tag]
@depp_user.errors.add(:base, :invalid_cert)
end
if @depp_user.errors.none? && @depp_user.valid?
@api_user = ApiUser.find_by(username: params[:depp_user][:tag])
if @api_user.active?
sign_in @api_user
redirect_to registrant_root_url
else
@depp_user.errors.add(:base, :not_active)
render 'login'
end
else
render 'login'
end
end
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity
def id
if Rails.env.development?
sign_in(RegistrantUser.find_or_create_by_idc_data('test'), event: :authentication)
return redirect_to registrant_root_url
end
logger.error request.env['SSL_CLIENT_S_DN']
logger.error request.env['SSL_CLIENT_S_DN'].encoding
@user = RegistrantUser.find_or_create_by_idc_data(request.env['SSL_CLIENT_S_DN'])

View file

@ -4,11 +4,6 @@ class RegistrantController < ApplicationController
include Registrant::ApplicationHelper
helper_method :depp_controller?
def depp_controller?
false
end
helper_method :head_title_sufix
def head_title_sufix
t(:registrant_head_title_sufix)

View file

@ -45,8 +45,6 @@
.container
= render 'shared/flash'
- if depp_controller?
= render 'registrar/shared/epp_results'
= yield
%footer.footer

View file

@ -1,46 +1,27 @@
- content_for :actions do
-# = link_to(t(:new), new_registrant_domain_path, class: 'btn btn-primary')
= render 'shared/title', name: t(:domains)
.row
.col-md-12{style: 'margin-bottom: -15px;'}
= form_tag info_registrant_domains_path, class: 'form-horizontal', method: :get do
.col-md-11
.form-group
= text_field_tag :domain_name, params[:domain_name], class: 'form-control', placeholder: t(:domain_name), autocomplete: 'off', autofocus: true
.col-md-1.text-right.text-center-xs
.form-group
%button.btn.btn-default
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
%hr
- if @response
.table-responsive
%table.table.table-hover.table-condensed
%thead
%tr
%th{class: 'col-xs-3'}= t(:name)
%th{class: 'col-xs-6'}= t(:valid)
%th{class: 'col-xs-3'}= t(:actions)
%tbody
- @response['domains'].each do |x|
.row
.col-md-12
.table-responsive
%table.table.table-hover.table-bordered.table-condensed
%thead
%tr
%td= link_to(x['name'], info_registrant_domains_path(domain_name: x['name']))
%td
= Time.zone.parse(x['valid_from']).try(:to_date)
\-
= Time.zone.parse(x['valid_to']).try(:to_date)
%td
= link_to(t(:view), info_registrant_domains_path(domain_name: x['name']),
class: 'btn btn-primary btn-xs')
-# = link_to(t(:edit), edit_registrant_domains_path(domain_name: x['name']),
-# class: 'btn btn-primary btn-xs')
-# = link_to(t(:renew), renew_registrant_domains_path(domain_name: x['name']),
-# class: 'btn btn-default btn-xs')
-# = link_to(t(:delete), delete_registrant_domains_path(domain_name: x['name']),
-# class: 'btn btn-default btn-xs')
%th{class: 'col-xs-2'}
= t(:name)
%th{class: 'col-xs-2'}
= t(:registrant)
%th{class: 'col-xs-2'}
= t(:valid_to)
%th{class: 'col-xs-2'}
= t(:registrar)
%tbody
- @domains.each do |x|
%tr
%td= link_to(x, admin_domain_path(x))
%td
- if x.registrant
= link_to(x.registrant, [:admin, x.registrant])
= paginate @paginatable_array
%td= l(x.valid_to, format: :short)
%td= link_to(x.registrar, admin_registrar_path(x.registrar)) if x.registrar

View file

@ -1,26 +0,0 @@
- content_for :actions do
-# = link_to(t(:edit), edit_registrar_domains_path(domain_name: params[:domain_name]),
-# class: 'btn btn-default')
-# = link_to(t(:renew), renew_registrar_domains_path(domain_name: params[:domain_name]),
-# class: 'btn btn-default')
-# = link_to(t(:delete), delete_registrar_domains_path(domain_name: params[:domain_name]),
-# class: 'btn btn-default')
= render 'shared/title', name: truncate(@data.css('name').text)
.row
.col-sm-12
- if @data.css('result').first['code'] == '1000'
.row
.col-md-12= render 'registrar/domains/partials/general'
.row
.col-md-12= render 'registrar/domains/partials/contacts'
.row
.col-md-12= render 'registrar/domains/partials/statuses'
.row
.col-md-12= render 'registrar/domains/partials/nameservers'
.row
.col-md-12= render 'registrar/domains/partials/dnskeys'
- else
.row
.col-sm-6
%h1= t(:not_found)

View file

@ -4,11 +4,3 @@
%hr
= link_to '/registrant/id', method: :post do
= image_tag 'id_card.gif'
%hr
-# = link_to '/regisrant/login/mid' do
-# = image_tag 'mid.gif'
-# = link_to '/registrant/login/id' do
-# = image_tag 'id_card.gif'

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150520163237) do
ActiveRecord::Schema.define(version: 20150520164507) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -954,7 +954,7 @@ ActiveRecord::Schema.define(version: 20150520163237) do
t.text "crt"
t.string "type"
t.string "registrant_ident"
t.string "encrypted_password", default: "", null: false
t.string "encrypted_password", default: ""
t.datetime "remember_created_at"
t.integer "failed_attempts", default: 0, null: false
t.datetime "locked_at"