diff --git a/app/controllers/management/on_site_verification_emails_controller.rb b/app/controllers/management/on_site_verification_emails_controller.rb new file mode 100644 index 000000000..52fb8b279 --- /dev/null +++ b/app/controllers/management/on_site_verification_emails_controller.rb @@ -0,0 +1,25 @@ +class Management::OnSiteVerificationEmailsController < Management::BaseController + + def new + @verification_on_site_email = Verification::OnSiteEmail.new(verification_on_site_email_params) + end + + def create + @verification_on_site_email = Verification::OnSiteEmail.new(verification_on_site_email_params) + + if @verification_on_site_email.valid? + @verification_on_site_email.send_email + render :sent + else + render :new + end + end + + private + + def verification_on_site_email_params + params.require(:verification_on_site_email).permit(:document_type, :document_number, :email) + end + +end + diff --git a/app/controllers/management/on_site_verifications_controller.rb b/app/controllers/management/on_site_verifications_controller.rb index f71218829..46409c869 100644 --- a/app/controllers/management/on_site_verifications_controller.rb +++ b/app/controllers/management/on_site_verifications_controller.rb @@ -1,4 +1,4 @@ -class Management::OnSiteVerificationsController < ActionController::Base +class Management::OnSiteVerificationsController < Management::BaseController def index @verification_on_site = Verification::OnSite.new() @@ -13,7 +13,7 @@ class Management::OnSiteVerificationsController < ActionController::Base elsif @verification_on_site.user? render :new elsif @verification_on_site.in_census? - render :existing_user + redirect_to new_management_on_site_verification_email_path(verification_on_site_email: verification_on_site_params) else render :invalid_document end @@ -28,27 +28,13 @@ class Management::OnSiteVerificationsController < ActionController::Base render :verified end - def send_email - @verification_on_site = Verification::OnSite.new(verification_on_site_with_email_params) - @verification_on_site.should_validate_email = true - - if @verification_on_site.valid? - @verification_on_site.send_verification_email - render :email_sent - else - render :existing_user - end - end - private def verification_on_site_params params.require(:verification_on_site).permit(:document_type, :document_number) end - def verification_on_site_with_email_params - params.require(:verification_on_site).permit(:document_type, :document_number, :email) - end + end diff --git a/app/models/verification/on_site.rb b/app/models/verification/on_site.rb index 8eaab0013..f7c3c20e7 100644 --- a/app/models/verification/on_site.rb +++ b/app/models/verification/on_site.rb @@ -3,16 +3,11 @@ class Verification::OnSite attr_accessor :document_type attr_accessor :document_number - attr_accessor :email - attr_accessor :should_validate_email validates :document_type, :document_number, presence: true - validate :validate_email, if: :should_validate_email def user - @user ||= - User.where(email: email).first || - User.by_document(document_type, document_number).first + @user = User.by_document(document_type, document_number).first end def user? @@ -31,22 +26,6 @@ class Verification::OnSite user.update(verified_at: Time.now) if user? end - def send_verification_email - # FIXME - # Should assign document_number here? - # Should send verification email here? - end - - def validate_email - if email.blank? - errors.add(:email, I18n.t('errors.messages.blank')) - elsif email !~ Devise.email_regexp - errors.add(:email, I18n.t('errors.messages.invalid')) - elsif !user? - errors.add(:email, I18n.t('errors.messages.user_not_found')) unless user? - end - end - end diff --git a/app/models/verification/on_site_email.rb b/app/models/verification/on_site_email.rb new file mode 100644 index 000000000..abe61d4f7 --- /dev/null +++ b/app/models/verification/on_site_email.rb @@ -0,0 +1,34 @@ +class Verification::OnSiteEmail + include ActiveModel::Model + + attr_accessor :document_type + attr_accessor :document_number + attr_accessor :email + + validates :document_type, :document_number, presence: true + validate :validate_email + + def user + @user ||= User.where(email: email).first + end + + def user? + user.present? + end + + def send_email + # FIXME + # Should assign document_number here? + # Should send verification email here? + end + + def validate_email + if email.blank? + errors.add(:email, I18n.t('errors.messages.blank')) + elsif email !~ Devise.email_regexp + errors.add(:email, I18n.t('errors.messages.invalid')) + elsif !user? + errors.add(:email, I18n.t('errors.messages.user_not_found')) unless user? + end + end +end diff --git a/app/views/management/_menu.html.erb b/app/views/management/_menu.html.erb new file mode 100644 index 000000000..74c5151d4 --- /dev/null +++ b/app/views/management/_menu.html.erb @@ -0,0 +1,14 @@ + diff --git a/app/views/management/dashboard/index.html.erb b/app/views/management/dashboard/index.html.erb new file mode 100644 index 000000000..8fc1b6100 --- /dev/null +++ b/app/views/management/dashboard/index.html.erb @@ -0,0 +1,3 @@ +
+

<%= t("management.dashboard.index.title") %>

+
diff --git a/app/views/management/on_site_verifications/existing_user.html.erb b/app/views/management/on_site_verification_emails/new.html.erb similarity index 71% rename from app/views/management/on_site_verifications/existing_user.html.erb rename to app/views/management/on_site_verification_emails/new.html.erb index ac271f07a..bafc1e11d 100644 --- a/app/views/management/on_site_verifications/existing_user.html.erb +++ b/app/views/management/on_site_verification_emails/new.html.erb @@ -1,6 +1,6 @@

- <%= t("management.document_type_label") %> <%= humanize_document_type(@verification_on_site.document_type) %> - <%= t("management.document_number") %> <%= @verification_on_site.document_number %> + <%= t("management.document_type_label") %> <%= humanize_document_type(@verification_on_site_email.document_type) %> + <%= t("management.document_number") %> <%= @verification_on_site_email.document_number %>

@@ -13,10 +13,11 @@

<%= t("management.users.has_account_note") %>

- <%= form_for @verification_on_site, url: send_email_management_on_site_verifications_path do |f| %> + <%= form_for @verification_on_site_email, url: management_on_site_verification_emails_path do |f| %> <%= f.hidden_field :document_type %> <%= f.hidden_field :document_number %> <%= f.text_field :email, label: false, placeholder: t('management.users.has_account_placeholder') %> + <%= f.submit t("management.users.has_account_send_email"), class: "button success radius" %> <% end %> @@ -25,7 +26,7 @@ <%= t("management.users.has_not_account") %>

- <%= t("management.users.create_user") %> + <%= t("management.print_info") %>

diff --git a/app/views/management/on_site_verifications/email_sent.html.erb b/app/views/management/on_site_verification_emails/sent.html.erb similarity index 67% rename from app/views/management/on_site_verifications/email_sent.html.erb rename to app/views/management/on_site_verification_emails/sent.html.erb index 721d81524..d3aa3035d 100644 --- a/app/views/management/on_site_verifications/email_sent.html.erb +++ b/app/views/management/on_site_verification_emails/sent.html.erb @@ -1,12 +1,10 @@

- <%= t("management.document_type_label") %> <%= humanize_document_type(@verification_on_site.document_type) %> - <%= t("management.document_number") %> <%= @verification_on_site.document_number %> - <%= t("management.username_label") %> <%= @verification_on_site.user.username %> - <%= t("management.email_label") %> <%= @verification_on_site.user.email %> + <%= t("management.document_type_label") %> <%= humanize_document_type(@verification_on_site_email.document_type) %> + <%= t("management.document_number") %> <%= @verification_on_site_email.document_number %> + <%= t("management.username_label") %> <%= @verification_on_site_email.user.username %> + <%= t("management.email_label") %> <%= @verification_on_site_email.user.email %>

-

<%= t("management.document_type_label") %> DNI <%= t("management.document_number") %> 73562454D <%= t("management.username_label") %> Alberto <%= t("management.email_label") %> alberto@mail.com

-
<%= t("management.users.email_sent") %>
diff --git a/app/views/management/on_site_verifications/index.html.erb b/app/views/management/on_site_verifications/index.html.erb index e20d7573b..41f62bd70 100644 --- a/app/views/management/on_site_verifications/index.html.erb +++ b/app/views/management/on_site_verifications/index.html.erb @@ -1,4 +1,4 @@ -

<%= t("management.verification_on_sites.title") %>

+

<%= t("management.users.title") %>

diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml index 30a9515da..d59126973 100644 --- a/config/locales/management.es.yml +++ b/config/locales/management.es.yml @@ -7,9 +7,13 @@ es: check: "Comprobar" document_number: "Número de documento" document_type_label: "Tipo de documento" + menu: + on_site_verifications: "Usuarios" on_site_verifications: title: "Gestionar usuario" - + dashboard: + index: + title: "Gestión" users: title: "Gestionar usuario" census_error: "Este documento no está registrado en el Padrón Municipal de Madrid." diff --git a/config/routes.rb b/config/routes.rb index 8c798ed49..ca8ee1e12 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -169,10 +169,12 @@ Rails.application.routes.draw do resources :on_site_verifications, only: [:index, :new, :create] do collection do post :check - post :send_email end end + resources :on_site_verification_emails, only: [:new, :create] + + end # Example of regular route: