+
+
+
+ <%= t("pages.verify.title") %>
+
- <%= link_to account_path, class: "left back clear" do %>
-
- <%= t("verification.back") %>
- <% end %>
-
-
-
-
<%= t("verification.letter.edit.title") %>
-
-
- <%= t("verification.letter.create.flash.success_html",
- offices: link_to(t("verification.letter.create.flash.offices"),
- t("verification.letter.create.flash.offices_url"),
- target: "_blank")).html_safe
- %>
+
<%= t("pages.verify.info") %>
- <%= link_to t("verification.letter.edit.see_all"), proposals_path, class: "button warning radius" %>
+
+ <%= form_for @letter, url: letter_path, method: :patch do |f| %>
+ <%= f.text_field :email, label: t("pages.verify.email"), placeholder: t("pages.verify.email") %>
+ <%= f.password_field :password, label: t("pages.verify.password"), placeholder: t("pages.verify.password") %>
+
+
+
+
+
+
+ <%= t("pages.verify.info_code") %>
+
+
+ <%= f.text_field :verification_code, label: t("pages.verify.code"), placeholder: t("pages.verify.code") %>
+
+ <%= f.submit(class: "button radius success expand", value: t("pages.verify.submit")) %>
+ <% end %>
+
diff --git a/app/views/verification/letter/show.html.erb b/app/views/verification/letter/show.html.erb
new file mode 100644
index 000000000..d5722f1fb
--- /dev/null
+++ b/app/views/verification/letter/show.html.erb
@@ -0,0 +1,22 @@
+
+
+ <%= link_to account_path, class: "left back clear" do %>
+
+ <%= t("verification.back") %>
+ <% end %>
+
+
+
+
<%= t("verification.letter.edit.title") %>
+
+
+ <%= t("verification.letter.create.flash.success_html",
+ offices: link_to(t("verification.letter.create.flash.offices"),
+ t("verification.letter.create.flash.offices_url"),
+ target: "_blank")).html_safe
+ %>
+
+
+ <%= link_to t("verification.letter.edit.see_all"), proposals_path, class: "button warning radius" %>
+
+
diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml
index ff1b5c179..d725a77d8 100644
--- a/config/i18n-tasks.yml
+++ b/config/i18n-tasks.yml
@@ -96,6 +96,7 @@ ignore_missing:
- 'unauthorized.*'
- 'errors.messages.blank'
- 'errors.messages.taken'
+ - 'devise.failure.invalid'
- 'devise.registrations.destroyed'
## Consider these keys used:
diff --git a/config/locales/en.yml b/config/locales/en.yml
index db56b3e4f..e2d604c72 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -71,6 +71,7 @@ en:
debate: debate
proposal: proposal
verification::sms: phone
+ verification::letter: verification
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 e05ed35e9..c20524f47 100644
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -71,6 +71,7 @@ es:
debate: el debate
proposal: la propuesta
verification::sms: el teléfono
+ verification::letter: la verificación
application:
alert:
only_beta_testers: "Lo sentimos sólo los usuarios de pruebas tienen acceso de momento"
diff --git a/config/locales/pages.en.yml b/config/locales/pages.en.yml
index 051217223..ef2b271a9 100644
--- a/config/locales/pages.en.yml
+++ b/config/locales/pages.en.yml
@@ -18,4 +18,12 @@ en:
transparency:
"Transparency"
opendata:
- "Open Data"
\ No newline at end of file
+ "Open Data"
+ verify:
+ title: "Verify your account"
+ info: "For verufy your account introduce your access data:"
+ info_code: "Now introduce the code you received in letter:"
+ email: "Email"
+ password: "Password"
+ code: "Code you received in letter"
+ submit: "Verify my account"
\ No newline at end of file
diff --git a/config/locales/pages.es.yml b/config/locales/pages.es.yml
index e1068f4ed..623b38ecf 100644
--- a/config/locales/pages.es.yml
+++ b/config/locales/pages.es.yml
@@ -21,3 +21,11 @@ es:
"Transparencia"
opendata:
"Datos abiertos"
+ verify:
+ title: "Verifica tu cuenta"
+ info: "Para verificar tu cuenta introduce los datos con los que te registraste:"
+ info_code: "Ahora introduce el código que has recibido en tu carta:"
+ email: "Email"
+ password: "Contraseña"
+ code: "Código que has recibido en tu carta"
+ submit: "Verificar mi cuenta"
diff --git a/config/locales/verification.en.yml b/config/locales/verification.en.yml
index 50e0d425b..014f143ab 100644
--- a/config/locales/verification.en.yml
+++ b/config/locales/verification.en.yml
@@ -88,12 +88,11 @@ en:
see_all: "See proposals"
update:
flash:
- success: "Correct code. Your account is verified"
+ success: "Your account has been verified"
alert:
unconfirmed_code: "You have not yet enter the confirmation code"
errors:
- letter_not_sent: "We have not sent you the letter with the code yet"
- incorect_code: "Incorrect confirmation code"
+ incorrect_code: "Incorrect confirmation code"
verified_user:
show:
title: "Available information"
diff --git a/config/locales/verification.es.yml b/config/locales/verification.es.yml
index fbd7c9499..57ffeff43 100644
--- a/config/locales/verification.es.yml
+++ b/config/locales/verification.es.yml
@@ -88,12 +88,11 @@ es:
see_all: "Ver propuestas"
update:
flash:
- success: "Código correcto. Tu cuenta ya está verificada"
+ success: "Tu cuenta ya está verificada"
alert:
unconfirmed_code: "Todavía no has introducido el código de confirmación"
errors:
- letter_not_sent: "Aún no te hemos enviado la carta con el código"
- incorect_code: "Código de verificación incorrecto"
+ incorrect_code: "Código de verificación incorrecto"
verified_user:
show:
title: "Información disponible"
diff --git a/config/routes.rb b/config/routes.rb
index 5e6f07c2c..712e835c1 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -70,7 +70,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, :edit, :update]
+ resource :letter, controller: "letter", only: [:new, :create, :show, :edit, :update]
end
namespace :admin do
@@ -272,5 +272,5 @@ Rails.application.routes.draw do
get "/participation_world", to: "pages#participation_world"
get "/blog", to: "pages#blog"
get "/accessibility", to: "pages#accessibility"
-
+ get "/verifica", to: "verification/letter#edit"
end
diff --git a/db/migrate/20151020112354_remove_letter_sent_at_from_users.rb b/db/migrate/20151020112354_remove_letter_sent_at_from_users.rb
new file mode 100644
index 000000000..0b982dfbb
--- /dev/null
+++ b/db/migrate/20151020112354_remove_letter_sent_at_from_users.rb
@@ -0,0 +1,5 @@
+class RemoveLetterSentAtFromUsers < ActiveRecord::Migration
+ def change
+ remove_column :users, :letter_sent_at, :datetime
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 29fda8e68..8b03adc9e 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: 20151019133719) do
+ActiveRecord::Schema.define(version: 20151020112354) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -284,7 +284,6 @@ ActiveRecord::Schema.define(version: 20151019133719) do
t.string "document_number"
t.string "document_type"
t.datetime "residence_verified_at"
- t.datetime "letter_sent_at"
t.string "email_verification_token"
t.datetime "verified_at"
t.string "unconfirmed_phone"
diff --git a/spec/factories.rb b/spec/factories.rb
index 83bc79af1..a3784678e 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -79,6 +79,9 @@ FactoryGirl.define do
factory :verification_letter, class: Verification::Letter do
user
+ email 'user@madrid.es'
+ password '1234'
+ verification_code '5555'
end
factory :lock do
diff --git a/spec/features/verification/letter_spec.rb b/spec/features/verification/letter_spec.rb
index d4b7eeb30..00baef12d 100644
--- a/spec/features/verification/letter_spec.rb
+++ b/spec/features/verification/letter_spec.rb
@@ -2,10 +2,9 @@ require 'rails_helper'
feature 'Verify Letter' do
- scenario 'Verify' do
+ scenario 'Request a letter' do
user = create(:user, residence_verified_at: Time.now,
- confirmed_phone: "611111111",
- letter_sent_at: 1.day.ago)
+ confirmed_phone: "611111111")
login_as(user)
visit new_letter_path
@@ -17,8 +16,7 @@ feature 'Verify Letter' do
scenario 'Go to office instead of send letter' do
user = create(:user, residence_verified_at: Time.now,
- confirmed_phone: "611111111",
- letter_sent_at: 1.day.ago)
+ confirmed_phone: "611111111")
login_as(user)
visit new_letter_path
@@ -26,19 +24,6 @@ feature 'Verify Letter' do
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",
- letter_sent_at: 1.day.ago)
-
- login_as(user)
- visit new_letter_path
-
- click_link "Request a letter"
- expect(page).to have_content "Before voting you'll receive a letter whith the instructions for verify your account."
-
- end
-
scenario "Deny access unless verified residence" do
user = create(:user)
@@ -58,4 +43,79 @@ feature 'Verify Letter' do
expect(page).to have_content 'You have not yet enter the confirmation code'
expect(current_path).to eq(new_sms_path)
end
+
+ context "Code verification" do
+
+ scenario "Valid verification user logged in" do
+ user = create(:user, residence_verified_at: Time.now,
+ confirmed_phone: "611111111",
+ letter_verification_code: "123456")
+
+ login_as(user)
+ visit edit_letter_path
+
+ fill_in "verification_letter_email", with: user.email
+ fill_in "verification_letter_password", with: user.password
+ fill_in "verification_letter_verification_code", with: user.letter_verification_code
+ click_button "Verify my account"
+
+ expect(page).to have_content "Your account has been verified"
+ expect(current_path).to eq(account_path)
+ end
+
+ scenario "Valid verification user not logged in" do
+ user = create(:user, residence_verified_at: Time.now,
+ confirmed_phone: "611111111",
+ letter_verification_code: "123456")
+
+ visit edit_letter_path
+
+ fill_in "verification_letter_email", with: user.email
+ fill_in "verification_letter_password", with: user.password
+ fill_in "verification_letter_verification_code", with: user.letter_verification_code
+ click_button "Verify my account"
+
+ expect(page).to have_content "Your account has been verified"
+ expect(current_path).to eq(account_path)
+ end
+
+ scenario "Error messages on authentication" do
+ visit edit_letter_path
+
+ click_button "Verify my account"
+
+ expect(page).to have_content "Invalid email or password."
+ end
+
+ scenario "Error messages on verification" do
+ user = create(:user, residence_verified_at: Time.now,
+ confirmed_phone: "611111111")
+
+ visit edit_letter_path
+ fill_in "verification_letter_email", with: user.email
+ fill_in "verification_letter_password", with: user.password
+ click_button "Verify my account"
+
+ expect(page).to have_content "can't be blank"
+ end
+
+ scenario '6 tries allowed' do
+ user = create(:user, residence_verified_at: Time.now,
+ confirmed_phone: "611111111",
+ letter_verification_code: "123456")
+
+ visit edit_letter_path
+
+ 6.times do
+ fill_in "verification_letter_email", with: user.email
+ fill_in "verification_letter_password", with: user.password
+ fill_in "verification_letter_verification_code", with: "1"
+ click_button "Verify my account"
+ end
+
+ expect(page).to have_content "You have reached the maximum number of verification tries. Please try again later."
+ expect(current_path).to eq(account_path)
+ end
+
+ end
end
diff --git a/spec/features/verification/verification_path_spec.rb b/spec/features/verification/verification_path_spec.rb
index bfd284500..7ec9fa8ff 100644
--- a/spec/features/verification/verification_path_spec.rb
+++ b/spec/features/verification/verification_path_spec.rb
@@ -51,7 +51,7 @@ feature 'Verification path' do
end
scenario "User received verification email" do
- user = create(:user, letter_requested_at: Time.now, letter_verification_code: "666")
+ user = create(:user, residence_verified_at: Time.now, email_verification_token: "1234")
login_as(user)
visit verification_path
@@ -90,7 +90,7 @@ feature 'Verification path' do
login_as(user)
- verification_paths = [new_residence_path, verified_user_path, edit_sms_path, new_letter_path, edit_letter_path]
+ verification_paths = [new_residence_path, verified_user_path, edit_sms_path, new_letter_path]
verification_paths.each do |step_path|
visit step_path
diff --git a/spec/models/letter_spec.rb b/spec/models/letter_spec.rb
index 683fb06d5..68d6afe5b 100644
--- a/spec/models/letter_spec.rb
+++ b/spec/models/letter_spec.rb
@@ -21,44 +21,33 @@ describe 'Verification::Letter' do
describe "save" do
- before(:each) do
- letter = Verification::Letter.new(user: user)
- letter.save
- user.reload
- end
-
it "should update letter_requested" do
- expect(user.letter_requested_at).to be
+ letter = build(:verification_letter)
+ letter.save
+ expect(letter.user.letter_requested_at).to be
end
end
- describe "#verified?" do
+ describe "#verify" do
- let(:letter) { build(:verification_letter) }
+ let(:letter) { build(:verification_letter, verify: true) }
- it "letter not sent" do
- letter.user.update(letter_sent_at: nil)
+ it "incorrect code" do
+ letter.user.update(letter_verification_code: "123456")
+ letter.verification_code = "5555"
- expect(letter.verified?).to eq(false)
- expect(letter.errors[:verification_code].first).to eq("We have not sent you the letter with the code yet")
- end
-
- it "letter sent but incorrect code" do
- letter.user.update(letter_sent_at: 1.day.ago, letter_verification_code: "123456")
- letter.verification_code = nil
-
- expect(letter.verified?).to eq(false)
+ expect(letter.valid?).to eq(false)
expect(letter.errors[:verification_code].first).to eq("Incorrect confirmation code")
end
- it "letter sent and correct code" do
- letter.user.update(letter_sent_at: 1.day.ago, letter_verification_code: "123456")
+ it "correct code" do
+ letter.user.update(letter_verification_code: "123456")
letter.verification_code = "123456"
- expect(letter.verified?).to eq(true)
+ expect(letter.valid?).to eq(true)
expect(letter.errors).to be_empty
end
end
-end
\ No newline at end of file
+end