Separate into two concerns: onsite verification + onsite verification emails
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
34
app/models/verification/on_site_email.rb
Normal file
34
app/models/verification/on_site_email.rb
Normal file
@@ -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
|
||||
14
app/views/management/_menu.html.erb
Normal file
14
app/views/management/_menu.html.erb
Normal file
@@ -0,0 +1,14 @@
|
||||
<nav class="admin-sidebar">
|
||||
<ul id="admin_menu">
|
||||
<li>
|
||||
<%= link_to t("management.dashboard.index.title"), management_root_path %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=active" if controller_name == "on_site_verifications" %>>
|
||||
<%= link_to management_on_site_verifications_path do %>
|
||||
<i class="icon-tag"></i>
|
||||
<%= t("management.menu.on_site_verifications") %>
|
||||
<% end %>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
3
app/views/management/dashboard/index.html.erb
Normal file
3
app/views/management/dashboard/index.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<div class="dashboard">
|
||||
<h2><%= t("management.dashboard.index.title") %></h2>
|
||||
</div>
|
||||
@@ -1,6 +1,6 @@
|
||||
<p class="account-info">
|
||||
<%= t("management.document_type_label") %> <strong><%= humanize_document_type(@verification_on_site.document_type) %></strong>
|
||||
<%= t("management.document_number") %> <strong><%= @verification_on_site.document_number %></strong>
|
||||
<%= t("management.document_type_label") %> <strong><%= humanize_document_type(@verification_on_site_email.document_type) %></strong>
|
||||
<%= t("management.document_number") %> <strong><%= @verification_on_site_email.document_number %></strong>
|
||||
</p>
|
||||
|
||||
<div class="alert-box success radius">
|
||||
@@ -13,10 +13,11 @@
|
||||
|
||||
<p><%= t("management.users.has_account_note") %></p>
|
||||
|
||||
<%= 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 %>
|
||||
</li>
|
||||
@@ -25,7 +26,7 @@
|
||||
<strong><%= t("management.users.has_not_account") %></strong>
|
||||
|
||||
<p class="margin-top">
|
||||
<a href="#" class="button radius success"><%= t("management.users.create_user") %></a>
|
||||
<a href="javascript:window.print();" class="button warning radius"><%= t("management.print_info") %></a>
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -1,12 +1,10 @@
|
||||
<p class="account-info">
|
||||
<%= t("management.document_type_label") %> <strong><%= humanize_document_type(@verification_on_site.document_type) %></strong>
|
||||
<%= t("management.document_number") %> <strong><%= @verification_on_site.document_number %></strong>
|
||||
<%= t("management.username_label") %> <strong><%= @verification_on_site.user.username %></strong>
|
||||
<%= t("management.email_label") %> <strong><%= @verification_on_site.user.email %></strong>
|
||||
<%= t("management.document_type_label") %> <strong><%= humanize_document_type(@verification_on_site_email.document_type) %></strong>
|
||||
<%= t("management.document_number") %> <strong><%= @verification_on_site_email.document_number %></strong>
|
||||
<%= t("management.username_label") %> <strong><%= @verification_on_site_email.user.username %></strong>
|
||||
<%= t("management.email_label") %> <strong><%= @verification_on_site_email.user.email %></strong>
|
||||
</p>
|
||||
|
||||
<p class="account-info"><%= t("management.document_type_label") %> <strong>DNI</strong> <%= t("management.document_number") %> <strong>73562454D</strong> <%= t("management.username_label") %> <strong>Alberto</strong> <%= t("management.email_label") %> <strong>alberto@mail.com</strong> </p>
|
||||
|
||||
<div class="alert-box success radius">
|
||||
<%= t("management.users.email_sent") %>
|
||||
</div>
|
||||
@@ -1,4 +1,4 @@
|
||||
<h2><%= t("management.verification_on_sites.title") %></h2>
|
||||
<h2><%= t("management.users.title") %></h2>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-8 column">
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user