Add Registrant User

This commit is contained in:
Martin Lensment 2015-05-14 18:02:31 +03:00
parent 412ececd9c
commit ca2183817a
8 changed files with 57 additions and 51 deletions

View file

@ -45,6 +45,13 @@ class Registrant::SessionsController < ::SessionsController
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity
def id
logger.error request.env['SSL_CLIENT_CERT']
# @user = RegistrantUser.where(identity_code: 'EE-123').first_or_create
# sign_in(@user, event: :authentication)
redirect_to registrant_root_url
end
def login_mid
@user = User.new
end
@ -55,7 +62,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

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

View file

@ -1,46 +1,8 @@
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
class RegistrantUser < User
attr_accessor :registrar_typeahead
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
end
def queued_messages
registrar.messages.queued
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