Merge branch 'master' of github.com:domify/registry

This commit is contained in:
Priit Tark 2015-05-14 23:55:29 +03:00
commit 28fe91ebeb
12 changed files with 82 additions and 55 deletions

View file

@ -45,6 +45,17 @@ class Registrant::SessionsController < ::SessionsController
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity
def id
@user = RegistrantUser.find_or_create_by_idc_data(request.env['SSL_CLIENT_S_DN'])
if @user
sign_in(@user, event: :authentication)
redirect_to registrant_root_url
else
flash[:alert] = t('login_failed_check_id_card')
redirect_to registrant_login_url
end
end
def login_mid
@user = User.new
end
@ -55,7 +66,7 @@ class Registrant::SessionsController < ::SessionsController
if Rails.env.test? && phone == "123"
@user = ApiUser.find_by(identity_code: "14212128025")
sign_in(@user, event: :authentication)
sign_in(@user, event: :authentication)
return redirect_to registrant_root_url
end

View file

@ -6,13 +6,13 @@ class DomainMailer < ApplicationMailer
return if @domain.deliver_emails != true
if @domain.registrant_verification_token.blank?
logger.warn "EMAIL DID NOT DELIVERED: registrant_verification_token is missing for #{@domain.name}"
return
return
end
@old_registrant = Registrant.find(@domain.registrant_id_was)
@verification_url = "#{ENV['registrant_url']}/etc/"
mail(to: @old_registrant.email,
mail(to: @old_registrant.email,
subject: "#{I18n.t(:domain_registrant_update_subject, name: @domain.name)} [#{@domain.name}]")
end
end

View file

@ -13,7 +13,9 @@ class Ability
when 'ApiUser'
epp
registrar
registrant # refactor
registrant # refactor
when 'RegistrantUser'
registrant
end
can :show, :dashboard
@ -65,7 +67,8 @@ class Ability
end
def registrant
can :manage, :registrant_whois
can :manage, Registrant::Whois
can :manage, Depp::Domain
end
def user

View file

@ -60,7 +60,7 @@ class Domain < ActiveRecord::Base
def manage_statuses
return unless registrant_id_changed?
if registrant_verification_asked_at.present?
domain_statuses.build(value: DomainStatus::PENDING_UPDATE)
domain_statuses.build(value: DomainStatus::PENDING_UPDATE)
DomainMailer.registrant_updated(self).deliver_now
end
true
@ -141,8 +141,8 @@ class Domain < ActiveRecord::Base
def included
includes(
:registrant,
:registrar,
:nameservers,
:registrar,
:nameservers,
:whois_record,
{ tech_contacts: :registrar },
{ admin_contacts: :registrar }
@ -254,7 +254,7 @@ class Domain < ActiveRecord::Base
end
# otherwise domain_statuses are in old state for domain object
domain_statuses.reload
domain_statuses.reload
end
def children_log

View file

@ -1,46 +1,22 @@
require 'open3'
# rubocop: disable Metrics/ClassLength
class ApiUser < User
include EppErrors
def epp_code_map # rubocop:disable Metrics/MethodLength
{
'2306' => [ # Parameter policy error
[:password, :blank]
]
}
end
# TODO: should have max request limit per day
belongs_to :registrar
has_many :certificates
validates :username, :password, :registrar, presence: true
validates :username, uniqueness: true
attr_accessor :registrar_typeahead
class RegistrantUser < User
attr_accessor :idc_data
def ability
@ability ||= Ability.new(self)
end
delegate :can?, :cannot?, to: :ability
after_initialize :set_defaults
def set_defaults
return unless new_record?
self.active = true unless active_changed?
end
def registrar_typeahead
@registrar_typeahead || registrar || nil
end
def to_s
username
registrant_ident
end
def queued_messages
registrar.messages.queued
class << self
def find_or_create_by_idc_data(idc_data)
return false if idc_data.blank?
identity_code = idc_data.scan(/serialNumber=(\d+)/).flatten.first
country = idc_data.scan(/^\/C=(.{2})/).flatten.first
where(registrant_ident: "#{country}-#{identity_code}").first_or_create
end
end
end
# rubocop: enable Metrics/ClassLength

View file

@ -2,15 +2,8 @@
.form-signin.col-md-6.center-block.text-center
%h2.form-signin-heading.text-center= t(:log_in)
%hr
= form_for @depp_user, url: registrant_sessions_path, html: {class: 'form-signin'} do |f|
= render 'registrar/shared/errors', object: f.object
- error_class = f.object.errors.any? ? 'has-error' : ''
%div{class: error_class}
= f.text_field :tag, class: 'form-control', placeholder: t(:username), required: true
= f.password_field :password, class: 'form-control', placeholder: t(:password), required: true
%button.btn.btn-lg.btn-primary.btn-block{:type => 'submit'}= t(:log_in)
= link_to '/registrant/id', method: :post do
= image_tag 'id_card.gif'
%hr
-# = link_to '/regisrant/login/mid' do