From 6821afff6551264c036d108f7caeff4fcb7afdbe Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Fri, 15 May 2015 10:00:04 +0300 Subject: [PATCH] Added domain confirmation verification url --- .../domain_update_confirms_controller.rb | 16 ++++++++++++++++ app/mailers/domain_mailer.rb | 4 +++- app/models/ability.rb | 4 +++- .../domain_mailer/registrant_updated.html.erb | 4 ++-- .../registrant/domain_update_confirms/show.haml | 2 ++ config/locales/en.yml | 1 + config/routes.rb | 2 ++ spec/mailers/domain_mailer_spec.rb | 7 ++++--- 8 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 app/controllers/registrant/domain_update_confirms_controller.rb create mode 100644 app/views/registrant/domain_update_confirms/show.haml diff --git a/app/controllers/registrant/domain_update_confirms_controller.rb b/app/controllers/registrant/domain_update_confirms_controller.rb new file mode 100644 index 000000000..f02d3e97b --- /dev/null +++ b/app/controllers/registrant/domain_update_confirms_controller.rb @@ -0,0 +1,16 @@ +class Registrant::DomainUpdateConfirmsController < RegistrantController + skip_before_action :authenticate_user!, only: [:show, :create] + skip_authorization_check only: [:show, :create] + + def show + @domain = Domain.find(params[:id]) + + if @domain.present? && params[:token].present? && @domain.registrant_verification_token == params[:token] + else + @domain = nil + end + end + + def create + end +end diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index 937ff3a4e..131018672 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -10,7 +10,9 @@ class DomainMailer < ApplicationMailer end @old_registrant = Registrant.find(@domain.registrant_id_was) - @verification_url = "#{ENV['registrant_url']}/etc/" + + confirm_path = "#{ENV['registrant_url']}/registrant/domain_update_confirms" + @verification_url = "#{confirm_path}/#{@domain.id}?token=#{@domain.registrant_verification_token}" mail(to: @old_registrant.email, subject: "#{I18n.t(:domain_registrant_update_subject, name: @domain.name)} [#{@domain.name}]") diff --git a/app/models/ability.rb b/app/models/ability.rb index 097f09020..84be67c3a 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -18,7 +18,9 @@ class Ability registrant end + # Public user can :show, :dashboard + can :create, :registrant_domain_update_confirm end # rubocop: disable Metrics/CyclomaticComplexity @@ -67,7 +69,7 @@ class Ability end def registrant - can :manage, Registrant::Whois + can :manage, :registrant_whois can :manage, Depp::Domain end diff --git a/app/views/domain_mailer/registrant_updated.html.erb b/app/views/domain_mailer/registrant_updated.html.erb index 72115fddb..b081bf2b4 100644 --- a/app/views/domain_mailer/registrant_updated.html.erb +++ b/app/views/domain_mailer/registrant_updated.html.erb @@ -16,7 +16,7 @@ Linn: <%= @domain.registrant_city %>
Riik: <%= @domain.registrant_country %>

Muudatuse kinnitamiseks külastage palun allolevat võrgulehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan:
-<%= @verification_url %> +<%= link_to @verification_url, @verification_url %>

Lugupidamisega
Eesti Interneti SA @@ -41,7 +41,7 @@ City: <%= @domain.registrant_city %>
Country: <%= @domain.registrant_country %>

To confirm the update please visit this website, once again review the data and press approve:
-<%= @verification_url %> +<%= link_to @verification_url, @verification_url %>

Best Regards,
Estonian Internet Foundation diff --git a/app/views/registrant/domain_update_confirms/show.haml b/app/views/registrant/domain_update_confirms/show.haml new file mode 100644 index 000000000..ee495fa38 --- /dev/null +++ b/app/views/registrant/domain_update_confirms/show.haml @@ -0,0 +1,2 @@ +- if @domain.blank? + %h1= t(:not_valid_domain_verification) diff --git a/config/locales/en.yml b/config/locales/en.yml index bcab7ee6c..c739fd53e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -768,3 +768,4 @@ en: domain_registrant_update_subject: "Kinnitustaotlus domeeni %{name} registreerija vahetuseks / Application for approval for registrant chache of %{name}" whois: WHOIS login_failed_check_id_card: 'Log in failed, check ID card' + not_valid_domain_verification: Not valid domain update verification diff --git a/config/routes.rb b/config/routes.rb index 04c63fd9c..d46d3f2b7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -103,6 +103,8 @@ Rails.application.routes.draw do # resources :deposits # resources :account_activities + resources :domain_update_confirms + devise_scope :user do get 'login' => 'sessions#login' get 'login/mid' => 'sessions#login_mid' diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb index 3fcffa1dc..bdf0f1e2a 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -31,10 +31,7 @@ describe DomainMailer do @new_registrant = Fabricate(:registrant, email: 'test@example.org') @domain = Fabricate(:domain, registrant: @registrant) @domain.deliver_emails = true -<<<<<<< HEAD -======= @domain.registrant_verification_token = '123' ->>>>>>> 0ddd2b6f32fa7e9abec8b2e7c88173585a78f3dd @domain.registrant = @new_registrant @mail = DomainMailer.registrant_updated(@domain) end @@ -54,5 +51,9 @@ describe DomainMailer do it 'should render body' do @mail.body.encoded.should =~ /Registrisse laekus taotlus domeeni/ end + + it 'should render verification url' do + @mail.body.encoded.should =~ /registrant\/domain_update_confirms/ + end end end