From 280028cfa4a8da1d21bb807b9797530c3ca29553 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 2 Sep 2015 21:45:53 +0200 Subject: [PATCH 1/5] adds missing translation for incorrect phone --- config/locales/en.yml | 2 +- config/locales/es.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 7cb05e302..35ce20772 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -54,7 +54,7 @@ en: accept_terms: I accept the privacy policy and the legal terms user: account debate: debate - sms: phone + verification::sms: phone application: alert: only_beta_testers: "Sorry only Beta Testers are allowed access at the moment" diff --git a/config/locales/es.yml b/config/locales/es.yml index f05b2a5e9..81cf1258a 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -54,7 +54,7 @@ es: accept_terms: Acepto la política de privacidad y el aviso legal user: la cuenta debate: el debate - sms: el teléfono + verification::sms: el teléfono application: alert: only_beta_testers: "Lo sentimos sólo los usuarios de pruebas tienen acceso de momento" From 99d779bcec8345bfb2a01333bfb6026ac3182231 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 2 Sep 2015 21:56:39 +0200 Subject: [PATCH 2/5] adds letter code verification --- .../verification/letter_controller.rb | 19 +++++++++- app/models/verification/letter.rb | 16 +++++--- app/views/verification/letter/edit.html.erb | 37 +++++++++++++++++++ app/views/verification/letter/new.html.erb | 13 ------- config/locales/verification.en.yml | 9 ++++- config/locales/verification.es.yml | 7 ++++ config/routes.rb | 2 +- ...5_add_letter_verification_code_to_users.rb | 5 +++ db/schema.rb | 13 ++++--- spec/features/verification/letter_spec.rb | 37 +++++++++++++++++-- 10 files changed, 126 insertions(+), 32 deletions(-) create mode 100644 app/views/verification/letter/edit.html.erb create mode 100644 db/migrate/20150902191315_add_letter_verification_code_to_users.rb diff --git a/app/controllers/verification/letter_controller.rb b/app/controllers/verification/letter_controller.rb index 152590b20..a1146520c 100644 --- a/app/controllers/verification/letter_controller.rb +++ b/app/controllers/verification/letter_controller.rb @@ -11,17 +11,32 @@ class Verification::LetterController < ApplicationController def create @letter = Verification::Letter.new(user: current_user) if @letter.save - redirect_to account_path, notice: t('verification.letter.create.flash.success') + redirect_to edit_letter_path, notice: t('verification.letter.create.flash.success') else flash.now.alert = t('verification.letter.create.alert.failure') render :new end end + def edit + @letter = Verification::Letter.new(user: current_user) + end + + def update + @letter = Verification::Letter.new(letter_params.merge(user: current_user)) + if @letter.verify? + current_user.update(verified_at: Time.now) + redirect_to account_path, notice: t('verification.letter.update.flash.success') + else + @error = t('verification.letter.update.error') + render :edit + end + end + private def letter_params - params.require(:letter).permit() + params.require(:letter).permit(:verification_code) end def verify_phone_or_email! diff --git a/app/models/verification/letter.rb b/app/models/verification/letter.rb index 566fe1fd7..077890600 100644 --- a/app/models/verification/letter.rb +++ b/app/models/verification/letter.rb @@ -1,16 +1,12 @@ class Verification::Letter include ActiveModel::Model - attr_accessor :user, :address + attr_accessor :user, :address, :verification_code validates :user, presence: true validates :address, presence: true validate :correct_address - def initialize(attrs={}) - @user = attrs[:user] - end - def save valid? && letter_requested! && @@ -22,7 +18,11 @@ class Verification::Letter end def letter_requested! - user.update(letter_requested_at: Time.now) + user.update(letter_requested_at: Time.now, letter_verification_code: four_digit_code) + end + + def verify? + user.letter_verification_code == verification_code end def update_user_address @@ -50,4 +50,8 @@ class Verification::Letter district: address[:nombre_distrito] } end + def four_digit_code + rand.to_s[2..5] + end + end diff --git a/app/views/verification/letter/edit.html.erb b/app/views/verification/letter/edit.html.erb new file mode 100644 index 000000000..56b76caa5 --- /dev/null +++ b/app/views/verification/letter/edit.html.erb @@ -0,0 +1,37 @@ + \ No newline at end of file diff --git a/app/views/verification/letter/new.html.erb b/app/views/verification/letter/new.html.erb index 850ec75bf..33b1f97cd 100644 --- a/app/views/verification/letter/new.html.erb +++ b/app/views/verification/letter/new.html.erb @@ -28,22 +28,9 @@ %> <%= form_for @letter, as: "letter", url: letter_path do |f| %> - <%= render "shared/errors", resource: @letter %> <%= f.submit t("verification.letter.new.send_letter"), class: "button radius secondary inline-block" %> <% end %> - -
- Gracias por solicitar tu código de máxima seguridad, en unos días te lo enviaremos a la dirección que figura en tus datos del padrón. Recuerda que puedes ahorrar el envío recogiendo tu código en cualquiera de las Oficinas de Atención al Ciudadano. -
-
- <%= form_tag do %> - <%= label_tag t("verification.letter.new.introduce_code") %> - <%= text_field_tag(:q) %> - <%= submit_tag t("verification.letter.new.send_code"), class: "button radius success" %> - <% end %> -
- diff --git a/config/locales/verification.en.yml b/config/locales/verification.en.yml index 6ee9fd26e..d131fb7df 100644 --- a/config/locales/verification.en.yml +++ b/config/locales/verification.en.yml @@ -71,9 +71,16 @@ en: send_code: "Send" create: flash: - success: "Thank you for requesting a code maximum security in a few days we will send it to the address on your census data. Remember that you can save shipping collecting your code in any of the Office of Citizen Services." + success: "Thank you for requesting a maximum security code in a few days we will send it to the address on your census data. Remember that you can save shipping collecting your code in any of the Office of Citizen Services." alert: failure: "We could not verify your address with the Census please try again later" + edit: + title: "Security code confirmation" + confirmation_code: "Code confirmation in your letter" + update: + error: "Incorrect confirmation code" + flash: + success: "Correct code. Your account is verified" alert: unconfirmed_code: "You have not yet enter the confirmation code" verified_user: diff --git a/config/locales/verification.es.yml b/config/locales/verification.es.yml index 0865eb690..55fe020b5 100644 --- a/config/locales/verification.es.yml +++ b/config/locales/verification.es.yml @@ -74,6 +74,13 @@ es: success: "Gracias por solicitar tu código de máxima seguridad, en unos días te lo enviaremos a la dirección que figura en tus datos del padrón. Recuerda que puedes ahorrar el envío recogiendo tu código en cualquiera de las Oficinas de Atención al Ciudadano." alert: failure: "No podemos verificar tu dirección con el Padrón, por favor inténtalo otra vez más tarde" + edit: + title: "Confirmación de código de seguridad" + confirmation_code: "Introduce el código que has recibido en tu carta" + update: + error: "Código de verificación incorrecto" + flash: + success: "Código correcto. Tu cuenta ya está verificada" alert: unconfirmed_code: "Todavía no has introducido el código de confirmación" verified_user: diff --git a/config/routes.rb b/config/routes.rb index 3bef1e3d9..98c88894d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -48,7 +48,7 @@ Rails.application.routes.draw do resource :sms, controller: "sms", only: [:new, :create, :edit, :update] resource :verified_user, controller: "verified_user", only: [:show] resource :email, controller: "email", only: [:new, :show, :create] - resource :letter, controller: "letter", only: [:new, :create] + resource :letter, controller: "letter", only: [:new, :create, :edit, :update] end namespace :admin do diff --git a/db/migrate/20150902191315_add_letter_verification_code_to_users.rb b/db/migrate/20150902191315_add_letter_verification_code_to_users.rb new file mode 100644 index 000000000..83142122e --- /dev/null +++ b/db/migrate/20150902191315_add_letter_verification_code_to_users.rb @@ -0,0 +1,5 @@ +class AddLetterVerificationCodeToUsers < ActiveRecord::Migration + def change + add_column :users, :letter_verification_code, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 883d2a7e1..ae7bc6e44 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150830212600) do +ActiveRecord::Schema.define(version: 20150902191315) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -67,8 +67,8 @@ ActiveRecord::Schema.define(version: 20150830212600) do t.integer "rgt" t.datetime "created_at" t.datetime "updated_at" - t.integer "children_count", default: 0 t.datetime "hidden_at" + t.integer "children_count", default: 0 t.integer "flags_count", default: 0 t.datetime "ignored_flag_at" t.integer "moderator_id" @@ -92,8 +92,8 @@ ActiveRecord::Schema.define(version: 20150830212600) do t.integer "author_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.datetime "hidden_at" t.string "visit_id" + t.datetime "hidden_at" t.integer "flags_count", default: 0 t.datetime "ignored_flag_at" t.integer "cached_votes_total", default: 0 @@ -200,13 +200,12 @@ ActiveRecord::Schema.define(version: 20150830212600) do t.string "unconfirmed_email" t.boolean "email_on_debate_comment", default: false t.boolean "email_on_comment_reply", default: false + t.string "phone_number", limit: 30 t.string "official_position" t.integer "official_level", default: 0 t.datetime "hidden_at" - t.string "phone_number", limit: 30 - t.string "username" - t.datetime "confirmed_hide_at" t.string "sms_confirmation_code" + t.string "username" t.string "document_number" t.string "document_type" t.datetime "residence_verified_at" @@ -218,6 +217,8 @@ ActiveRecord::Schema.define(version: 20150830212600) do t.string "unconfirmed_phone" t.string "confirmed_phone" t.datetime "letter_requested_at" + t.datetime "confirmed_hide_at" + t.string "letter_verification_code" end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree diff --git a/spec/features/verification/letter_spec.rb b/spec/features/verification/letter_spec.rb index 9a462feaf..e2ebe5aa5 100644 --- a/spec/features/verification/letter_spec.rb +++ b/spec/features/verification/letter_spec.rb @@ -2,15 +2,46 @@ require 'rails_helper' feature 'Verify Letter' do - scenario 'Send letter level 2 verified with phone' do + scenario 'Verify' do user = create(:user, residence_verified_at: Time.now, confirmed_phone: "611111111") login_as(user) visit new_letter_path - click_button "Send me a letter" + click_button "Send me a letter with the code" - expect(page).to have_content "Thank you for requesting a code maximum security in a few days we will send it to the address on your census data. Remember that you can save shipping collecting your code in any of the Office of Citizen Services." + expect(page).to have_content "Thank you for requesting a maximum security code in a few days we will send it to the address on your census data." + + user.reload + fill_in "letter_verification_code", with: user.letter_verification_code + click_button "Send" + + expect(page).to have_content "Correct code. Your account is verified" + end + + scenario 'Go to office instead of send letter' do + user = create(:user, residence_verified_at: Time.now, confirmed_phone: "611111111") + + login_as(user) + visit new_letter_path + + expect(page).to have_link "Office of Citizen", href: "http://www.madrid.es/portales/munimadrid/es/Inicio/El-Ayuntamiento/Atencion-al-ciudadano/Oficinas-de-Atencion-al-Ciudadano?vgnextfmt=default&vgnextchannel=5b99cde2e09a4310VgnVCM1000000b205a0aRCRD" + end + + scenario 'Errors on verification code' do + user = create(:user, residence_verified_at: Time.now, confirmed_phone: "611111111") + + login_as(user) + visit new_letter_path + + click_button "Send me a letter with the code" + + expect(page).to have_content "Thank you for requesting a maximum security code in a few days we will send it to the address on your census data." + + fill_in "letter_verification_code", with: "1" + click_button "Send" + + expect(page).to have_content "Incorrect confirmation code" end scenario "Error accessing address from CensusApi" do From 4d97063887b57e4e8a61c2661433c5c887aec7f2 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 2 Sep 2015 21:59:51 +0200 Subject: [PATCH 3/5] removes unused spec --- app/controllers/verification/letter_controller.rb | 4 ++-- spec/features/verification/letter_spec.rb | 11 ----------- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/app/controllers/verification/letter_controller.rb b/app/controllers/verification/letter_controller.rb index a1146520c..e302a1bc6 100644 --- a/app/controllers/verification/letter_controller.rb +++ b/app/controllers/verification/letter_controller.rb @@ -1,7 +1,7 @@ class Verification::LetterController < ApplicationController before_action :authenticate_user! before_action :verify_resident! - before_action :verify_phone_or_email! + before_action :verify_phone! skip_authorization_check def new @@ -39,7 +39,7 @@ class Verification::LetterController < ApplicationController params.require(:letter).permit(:verification_code) end - def verify_phone_or_email! + def verify_phone! unless current_user.confirmed_phone? redirect_to verified_user_path, alert: t('verification.letter.alert.unconfirmed_code') end diff --git a/spec/features/verification/letter_spec.rb b/spec/features/verification/letter_spec.rb index e2ebe5aa5..9fc97267f 100644 --- a/spec/features/verification/letter_spec.rb +++ b/spec/features/verification/letter_spec.rb @@ -57,17 +57,6 @@ feature 'Verify Letter' do expect(page).to have_content "We could not verify your address with the Census please try again later" end - scenario 'Send letter level 2 user verified with email' do - user = create(:user, residence_verified_at: Time.now, confirmed_phone: "611111111") - - login_as(user) - visit new_letter_path - - click_button "Send me a letter" - - expect(page).to have_content "Thank you for requesting a code maximum security in a few days we will send it to the address on your census data. Remember that you can save shipping collecting your code in any of the Office of Citizen Services." - end - scenario "Deny access unless verified residence" do user = create(:user) From 4cb7a698fe2729e54e1a21624f97321f2ed91ded Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 2 Sep 2015 22:01:07 +0200 Subject: [PATCH 4/5] fixes spec --- .../verification/level_three_verification_spec.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spec/features/verification/level_three_verification_spec.rb b/spec/features/verification/level_three_verification_spec.rb index 112fd859b..4fa392087 100644 --- a/spec/features/verification/level_three_verification_spec.rb +++ b/spec/features/verification/level_three_verification_spec.rb @@ -85,8 +85,14 @@ feature 'Level three verification' do expect(page).to have_content 'Correct code' - click_button "Send me a letter" + click_button "Send me a letter with the code" - expect(page).to have_content "Thank you for requesting a code maximum security in a few days we will send it to the address on your census data. Remember that you can save shipping collecting your code in any of the Office of Citizen Services." + expect(page).to have_content "Thank you for requesting a maximum security code in a few days we will send it to the address on your census data." + + user.reload + fill_in "letter_verification_code", with: user.letter_verification_code + click_button "Send" + + expect(page).to have_content "Correct code. Your account is verified" end end \ No newline at end of file From b8e35ac95fa988f16039a7a5368ee576038a5f9f Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 2 Sep 2015 22:06:50 +0200 Subject: [PATCH 5/5] cleans up --- config/locales/verification.en.yml | 3 +-- config/locales/verification.es.yml | 1 - spec/features/verification/letter_spec.rb | 1 - spec/features/verification/level_three_verification_spec.rb | 2 -- 4 files changed, 1 insertion(+), 6 deletions(-) diff --git a/config/locales/verification.en.yml b/config/locales/verification.en.yml index d131fb7df..1588d3713 100644 --- a/config/locales/verification.en.yml +++ b/config/locales/verification.en.yml @@ -67,7 +67,6 @@ en: offices: "See Office of Citizen" offices_url: "http://www.madrid.es/portales/munimadrid/es/Inicio/El-Ayuntamiento/Atencion-al-ciudadano/Oficinas-de-Atencion-al-Ciudadano?vgnextfmt=default&vgnextchannel=5b99cde2e09a4310VgnVCM1000000b205a0aRCRD" send_letter: "Send me a letter with the code" - introduce_code: "Enter the security code" send_code: "Send" create: flash: @@ -76,7 +75,7 @@ en: failure: "We could not verify your address with the Census please try again later" edit: title: "Security code confirmation" - confirmation_code: "Code confirmation in your letter" + confirmation_code: "Enter the security code in your letter" update: error: "Incorrect confirmation code" flash: diff --git a/config/locales/verification.es.yml b/config/locales/verification.es.yml index 55fe020b5..7d30a4dc0 100644 --- a/config/locales/verification.es.yml +++ b/config/locales/verification.es.yml @@ -67,7 +67,6 @@ es: offices: "Ver Oficinas de Atención al Ciudadano" offices_url: "http://www.madrid.es/portales/munimadrid/es/Inicio/El-Ayuntamiento/Atencion-al-ciudadano/Oficinas-de-Atencion-al-Ciudadano?vgnextfmt=default&vgnextchannel=5b99cde2e09a4310VgnVCM1000000b205a0aRCRD" send_letter: "Enviarme una carta con el código" - introduce_code: "Introduce el código de seguridad" send_code: "Enviar" create: flash: diff --git a/spec/features/verification/letter_spec.rb b/spec/features/verification/letter_spec.rb index 9fc97267f..a065edfc0 100644 --- a/spec/features/verification/letter_spec.rb +++ b/spec/features/verification/letter_spec.rb @@ -35,7 +35,6 @@ feature 'Verify Letter' do visit new_letter_path click_button "Send me a letter with the code" - expect(page).to have_content "Thank you for requesting a maximum security code in a few days we will send it to the address on your census data." fill_in "letter_verification_code", with: "1" diff --git a/spec/features/verification/level_three_verification_spec.rb b/spec/features/verification/level_three_verification_spec.rb index 4fa392087..93f60c175 100644 --- a/spec/features/verification/level_three_verification_spec.rb +++ b/spec/features/verification/level_three_verification_spec.rb @@ -26,8 +26,6 @@ feature 'Level three verification' do fill_in 'sms_confirmation_code', with: user.sms_confirmation_code click_button 'Send' - expect(page).to have_content 'Correct code' - expect(page).to have_content "Correct code. Your account is verified" expect(page).to_not have_link "Verify my account"