From 78d6f5e53a5b6e26ad9545aebab54d5c17116752 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 30 Sep 2015 21:00:42 +0200 Subject: [PATCH] Adds a half-done implementation of on_site_verifications MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Things missing: * Implement models/verification/on_site#send_verification_email * Implement the “create new user” path * Tests --- .../on_site_verifications_controller.rb | 55 +++++++++++++++++++ .../user_verification_controller.rb | 25 +++++++++ app/models/verification/on_site.rb | 53 ++++++++++++++++++ .../already_verified.html.erb | 25 +++++++++ .../on_site_verifications/email_sent.html.erb | 28 ++++++++++ .../existing_user.html.erb | 31 +++++++++++ .../on_site_verifications/index.html.erb | 22 ++++++++ .../invalid_document.html.erb | 27 +++++++++ .../on_site_verifications/new.html.erb | 29 ++++++++++ .../on_site_verifications/verified.html.erb | 25 +++++++++ config/locales/management.es.yml | 41 ++++++++++++++ config/routes.rb | 7 +++ 12 files changed, 368 insertions(+) create mode 100644 app/controllers/management/on_site_verifications_controller.rb create mode 100644 app/controllers/management/user_verification_controller.rb create mode 100644 app/models/verification/on_site.rb create mode 100644 app/views/management/on_site_verifications/already_verified.html.erb create mode 100644 app/views/management/on_site_verifications/email_sent.html.erb create mode 100644 app/views/management/on_site_verifications/existing_user.html.erb create mode 100644 app/views/management/on_site_verifications/index.html.erb create mode 100644 app/views/management/on_site_verifications/invalid_document.html.erb create mode 100644 app/views/management/on_site_verifications/new.html.erb create mode 100644 app/views/management/on_site_verifications/verified.html.erb create mode 100644 config/locales/management.es.yml diff --git a/app/controllers/management/on_site_verifications_controller.rb b/app/controllers/management/on_site_verifications_controller.rb new file mode 100644 index 000000000..f71218829 --- /dev/null +++ b/app/controllers/management/on_site_verifications_controller.rb @@ -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 + + + diff --git a/app/controllers/management/user_verification_controller.rb b/app/controllers/management/user_verification_controller.rb new file mode 100644 index 000000000..4693be1c8 --- /dev/null +++ b/app/controllers/management/user_verification_controller.rb @@ -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 diff --git a/app/models/verification/on_site.rb b/app/models/verification/on_site.rb new file mode 100644 index 000000000..8eaab0013 --- /dev/null +++ b/app/models/verification/on_site.rb @@ -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 + + + diff --git a/app/views/management/on_site_verifications/already_verified.html.erb b/app/views/management/on_site_verifications/already_verified.html.erb new file mode 100644 index 000000000..60b81566c --- /dev/null +++ b/app/views/management/on_site_verifications/already_verified.html.erb @@ -0,0 +1,25 @@ +

+ <%= 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.users.already_verified") %> +
+ +
+ +

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

+ + + +
+ +<%= t("management.print_info") %> diff --git a/app/views/management/on_site_verifications/email_sent.html.erb b/app/views/management/on_site_verifications/email_sent.html.erb new file mode 100644 index 000000000..721d81524 --- /dev/null +++ b/app/views/management/on_site_verifications/email_sent.html.erb @@ -0,0 +1,28 @@ +

+ <%= 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") %> DNI <%= t("management.document_number") %> 73562454D <%= t("management.username_label") %> Alberto <%= t("management.email_label") %> alberto@mail.com

+ +
+ <%= t("management.users.email_sent") %> +
+ +
+ +

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

+ + + +
+ +<%= t("management.print_info") %> + diff --git a/app/views/management/on_site_verifications/existing_user.html.erb b/app/views/management/on_site_verifications/existing_user.html.erb new file mode 100644 index 000000000..ac271f07a --- /dev/null +++ b/app/views/management/on_site_verifications/existing_user.html.erb @@ -0,0 +1,31 @@ +

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

+ +
+ <%= t("management.users.census_success") %> +
+ + diff --git a/app/views/management/on_site_verifications/index.html.erb b/app/views/management/on_site_verifications/index.html.erb new file mode 100644 index 000000000..e20d7573b --- /dev/null +++ b/app/views/management/on_site_verifications/index.html.erb @@ -0,0 +1,22 @@ +

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

+ +
+
+ <%= form_for @verification_on_site, url: check_management_on_site_verifications_path do |f| %> +
+ <%= 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")) %> +
+
+ <%= f.text_field :document_number, + placeholder: t('management.document_number'), + label: t("management.document_number") + %> +
+ <%= f.submit t("management.check") %> + <% end %> +
+
diff --git a/app/views/management/on_site_verifications/invalid_document.html.erb b/app/views/management/on_site_verifications/invalid_document.html.erb new file mode 100644 index 000000000..c95d3c01e --- /dev/null +++ b/app/views/management/on_site_verifications/invalid_document.html.erb @@ -0,0 +1,27 @@ +

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

+ +
+ <%= t("management.users.census_error") %> +
+ +
+ +

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

+ + + +

+ <%= t("management.users.has_not_account_html", + url: link_to(t("management.users.portal_url"), t("management.users.portal_url"), + target: "_blank")).html_safe %> +

+ +
diff --git a/app/views/management/on_site_verifications/new.html.erb b/app/views/management/on_site_verifications/new.html.erb new file mode 100644 index 000000000..cc7d6e914 --- /dev/null +++ b/app/views/management/on_site_verifications/new.html.erb @@ -0,0 +1,29 @@ +

+ <%= 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.users.census_success_account") %> +
+ +
+ +

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

+ + + + <%= 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 %> + +
diff --git a/app/views/management/on_site_verifications/verified.html.erb b/app/views/management/on_site_verifications/verified.html.erb new file mode 100644 index 000000000..60b81566c --- /dev/null +++ b/app/views/management/on_site_verifications/verified.html.erb @@ -0,0 +1,25 @@ +

+ <%= 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.users.already_verified") %> +
+ +
+ +

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

+ + + +
+ +<%= t("management.print_info") %> diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml new file mode 100644 index 000000000..30a9515da --- /dev/null +++ b/config/locales/management.es.yml @@ -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 'Registrarse' 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 'Mi cuenta' y haga clic en el botón 'Cambiar datos de acceso'" + verify: "Verificar usuario" + diff --git a/config/routes.rb b/config/routes.rb index 2103c0fce..f512a47f5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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: