Adds a half-done implementation of on_site_verifications
Things missing: * Implement models/verification/on_site#send_verification_email * Implement the “create new user” path * Tests
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
class Management::OnSiteVerificationsController < ActionController::Base
|
||||
|
||||
def index
|
||||
@verification_on_site = Verification::OnSite.new()
|
||||
end
|
||||
|
||||
def check
|
||||
@verification_on_site = Verification::OnSite.new(verification_on_site_params)
|
||||
|
||||
if @verification_on_site.valid?
|
||||
if @verification_on_site.verified?
|
||||
render :verified
|
||||
elsif @verification_on_site.user?
|
||||
render :new
|
||||
elsif @verification_on_site.in_census?
|
||||
render :existing_user
|
||||
else
|
||||
render :invalid_document
|
||||
end
|
||||
else
|
||||
render :index
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@verification_on_site = Verification::OnSite.new(verification_on_site_params)
|
||||
@verification_on_site.verify
|
||||
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
|
||||
|
||||
|
||||
|
||||
25
app/controllers/management/user_verification_controller.rb
Normal file
25
app/controllers/management/user_verification_controller.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
class Management::OnSiteVerificationController < ActionController::Base
|
||||
|
||||
def new
|
||||
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
verification = Verification::OnSite()
|
||||
|
||||
end
|
||||
|
||||
|
||||
def invalid_document
|
||||
|
||||
end
|
||||
|
||||
def user_exists
|
||||
|
||||
end
|
||||
|
||||
def
|
||||
|
||||
|
||||
end
|
||||
53
app/models/verification/on_site.rb
Normal file
53
app/models/verification/on_site.rb
Normal file
@@ -0,0 +1,53 @@
|
||||
class Verification::OnSite
|
||||
include ActiveModel::Model
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
def user?
|
||||
user.present?
|
||||
end
|
||||
|
||||
def in_census?
|
||||
CensusApi.new.call(document_type, document_number).valid?
|
||||
end
|
||||
|
||||
def verified?
|
||||
user? && user.level_three_verified?
|
||||
end
|
||||
|
||||
def verify
|
||||
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
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<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>
|
||||
</p>
|
||||
|
||||
<div class="alert-box success radius">
|
||||
<%= t("management.users.already_verified") %>
|
||||
</div>
|
||||
|
||||
<div class="user-permissions">
|
||||
|
||||
<p><%= t("management.users.census_success_info") %></p>
|
||||
|
||||
<ul>
|
||||
<li><i class="icon-check"></i> <%= t("management.users.user_permission_debates") %></li>
|
||||
<li><i class="icon-check"></i> <%= t("management.users.user_permission_proposal") %></li>
|
||||
<li><i class="icon-check"></i> <%= t("management.users.user_permission_support_proposal") %></li>
|
||||
<li><i class="icon-check"></i> <%= t("management.users.user_permission_votes") %></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<a href="javascript:window.print();" class="button warning radius"><%= t("management.print_info") %></a>
|
||||
@@ -0,0 +1,28 @@
|
||||
<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>
|
||||
</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>
|
||||
|
||||
<div class="user-permissions">
|
||||
|
||||
<p><%= t("management.users.census_success_info") %></p>
|
||||
|
||||
<ul>
|
||||
<li><i class="icon-check"></i> <%= t("management.users.user_permission_debates") %></li>
|
||||
<li><i class="icon-check"></i> <%= t("management.users.user_permission_proposal") %></li>
|
||||
<li><i class="icon-check"></i> <%= t("management.users.user_permission_support_proposal") %></li>
|
||||
<li><i class="icon-check"></i> <%= t("management.users.user_permission_votes") %></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<a href="javascript:window.print();" class="button warning radius"><%= t("management.print_info") %></a>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<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>
|
||||
</p>
|
||||
|
||||
<div class="alert-box success radius">
|
||||
<%= t("management.users.census_success") %>
|
||||
</div>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<strong><%= t("management.users.has_account") %></strong>
|
||||
|
||||
<p><%= t("management.users.has_account_note") %></p>
|
||||
|
||||
<%= form_for @verification_on_site, url: send_email_management_on_site_verifications_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>
|
||||
|
||||
<li>
|
||||
<strong><%= t("management.users.has_not_account") %></strong>
|
||||
|
||||
<p class="margin-top">
|
||||
<a href="#" class="button radius success"><%= t("management.users.create_user") %></a>
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
22
app/views/management/on_site_verifications/index.html.erb
Normal file
22
app/views/management/on_site_verifications/index.html.erb
Normal file
@@ -0,0 +1,22 @@
|
||||
<h2><%= t("management.verification_on_sites.title") %></h2>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-8 column">
|
||||
<%= form_for @verification_on_site, url: check_management_on_site_verifications_path do |f| %>
|
||||
<div class="small-12 medium-4">
|
||||
<%= f.select(:document_type,
|
||||
[[humanize_document_type("1"), 1],
|
||||
[humanize_document_type("2"), 2],
|
||||
[humanize_document_type("3"), 3]],
|
||||
label: t("management.document_type_label")) %>
|
||||
</div>
|
||||
<div class="small-12 medium-5">
|
||||
<%= f.text_field :document_number,
|
||||
placeholder: t('management.document_number'),
|
||||
label: t("management.document_number")
|
||||
%>
|
||||
</div>
|
||||
<%= f.submit t("management.check") %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,27 @@
|
||||
<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>
|
||||
</p>
|
||||
|
||||
<div class="alert-box alert radius">
|
||||
<%= t("management.users.census_error") %>
|
||||
</div>
|
||||
|
||||
<div class="user-permissions">
|
||||
|
||||
<p><%= t("management.users.census_error_info") %></p>
|
||||
|
||||
<ul>
|
||||
<li><i class="icon-check"></i> <%= t("management.users.user_permission_debates") %></li>
|
||||
<li><i class="icon-check"></i> <%= t("management.users.user_permission_proposal") %></li>
|
||||
<li><i class="icon-x"></i> <%= t("management.users.user_permission_support_proposal") %></li>
|
||||
<li><i class="icon-x"></i> <%= t("management.users.user_permission_votes") %></li>
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
<%= t("management.users.has_not_account_html",
|
||||
url: link_to(t("management.users.portal_url"), t("management.users.portal_url"),
|
||||
target: "_blank")).html_safe %>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
29
app/views/management/on_site_verifications/new.html.erb
Normal file
29
app/views/management/on_site_verifications/new.html.erb
Normal file
@@ -0,0 +1,29 @@
|
||||
<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>
|
||||
</p>
|
||||
|
||||
<div class="alert-box success radius">
|
||||
<%= t("management.users.census_success_account") %>
|
||||
</div>
|
||||
|
||||
<div class="user-permissions">
|
||||
|
||||
<p><%= t("management.users.census_success_info") %></p>
|
||||
|
||||
<ul>
|
||||
<li><i class="icon-check"></i> <%= t("management.users.user_permission_debates") %></li>
|
||||
<li><i class="icon-check"></i> <%= t("management.users.user_permission_proposal") %></li>
|
||||
<li><i class="icon-check"></i> <%= t("management.users.user_permission_support_proposal") %></li>
|
||||
<li><i class="icon-x"></i> <%= t("management.users.user_permission_votes") %></li>
|
||||
</ul>
|
||||
|
||||
<%= form_for @verification_on_site, url: management_on_site_verifications_path do |f| %>
|
||||
<%= f.hidden_field :document_type %>
|
||||
<%= f.hidden_field :document_number %>
|
||||
<%= f.submit t("management.users.verify"), class: "button success radius" %>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
25
app/views/management/on_site_verifications/verified.html.erb
Normal file
25
app/views/management/on_site_verifications/verified.html.erb
Normal file
@@ -0,0 +1,25 @@
|
||||
<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>
|
||||
</p>
|
||||
|
||||
<div class="alert-box success radius">
|
||||
<%= t("management.users.already_verified") %>
|
||||
</div>
|
||||
|
||||
<div class="user-permissions">
|
||||
|
||||
<p><%= t("management.users.census_success_info") %></p>
|
||||
|
||||
<ul>
|
||||
<li><i class="icon-check"></i> <%= t("management.users.user_permission_debates") %></li>
|
||||
<li><i class="icon-check"></i> <%= t("management.users.user_permission_proposal") %></li>
|
||||
<li><i class="icon-check"></i> <%= t("management.users.user_permission_support_proposal") %></li>
|
||||
<li><i class="icon-check"></i> <%= t("management.users.user_permission_votes") %></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<a href="javascript:window.print();" class="button warning radius"><%= t("management.print_info") %></a>
|
||||
41
config/locales/management.es.yml
Normal file
41
config/locales/management.es.yml
Normal file
@@ -0,0 +1,41 @@
|
||||
es:
|
||||
management:
|
||||
print: "Imprimir"
|
||||
print_info: "Imprimir esta información"
|
||||
username_label: "Nombre de usuario"
|
||||
email_label: "Email"
|
||||
check: "Comprobar"
|
||||
document_number: "Número de documento"
|
||||
document_type_label: "Tipo de documento"
|
||||
on_site_verifications:
|
||||
title: "Gestionar usuario"
|
||||
|
||||
users:
|
||||
title: "Gestionar usuario"
|
||||
census_error: "Este documento no está registrado en el Padrón Municipal de Madrid."
|
||||
census_error_info: "Las personas no empadronadas en Madrid pueden participar en el Portal de Gobierno Abierto del Ayuntamiento de Madrid con las siguientes posibilidades:"
|
||||
census_success: "Este documento está en el registro del padrón municipal, pero todavía no tiene una cuenta de usuario asociada. Elige una de las opciones siguientes:"
|
||||
census_success_info: "Este usuario puede participar en el Portal de Gobierno Abierto del Ayuntamiento de Madrid con las siguientes posibilidades:"
|
||||
census_success_account: "Compruebe que los datos anteriores son correctos para proceder a verificar la cuenta completamente."
|
||||
user_permission_debates: "Participar en debates"
|
||||
user_permission_proposal: "Crear nuevas propuestas"
|
||||
user_permission_support_proposal: "Apoyar propuestas"
|
||||
user_permission_votes: "Participar en las votaciones finales"
|
||||
has_not_account_html: "Para crear un usuario entre en %{url} y haga clic en la opción <b>'Registrarse'</b> en la parte superior derecha de la pantalla."
|
||||
portal_url: "http://decide.madrid.es"
|
||||
already_verified: "Esta cuenta de usuario ya está verificada."
|
||||
has_account: "Si la persona ya ha creado una cuenta de usuario en la web"
|
||||
has_not_account: "Si la persona todavía no ha creado una cuenta de usuario en la web"
|
||||
has_account_note: "Introduce el email con el que creó la cuenta:"
|
||||
has_account_placeholder: "Introduce el email de registro"
|
||||
has_account_send_email: "Enviar email de verificación"
|
||||
email_sent: "Para terminar de verificar esta cuenta es necesario que haga clic en el enlace que le hemos enviado a la dirección de correo que figura arriba. Este paso es necesario para confirmar que dicha cuenta de usuario es suya."
|
||||
create_user: "Crear nueva cuenta de usuario"
|
||||
create_user_info: "Procedemos a crear un usuario con la siguiente información:"
|
||||
create_user_submit: "Crear usuario"
|
||||
create_user_success_html:
|
||||
"Le hemos mandado un correo electrónico a la dirección de correo anterior para verificar que es suya.
|
||||
Le recomendamos cambiar la contraseña en su primer uso. Para ello entre en %{url} con su usuario y contraseña,
|
||||
acceda a la sección <b>'Mi cuenta'</b> y haga clic en el botón <b>'Cambiar datos de acceso'</b>"
|
||||
verify: "Verificar usuario"
|
||||
|
||||
@@ -165,6 +165,13 @@ Rails.application.routes.draw do
|
||||
|
||||
namespace :management do
|
||||
|
||||
resources :on_site_verifications, only: [:index, :new, :create] do
|
||||
collection do
|
||||
post :check
|
||||
post :send_email
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Example of regular route:
|
||||
|
||||
Reference in New Issue
Block a user