From 65e0becafc9a0368cdb90a4a9e8444aee9cbd429 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Mon, 5 Oct 2015 12:31:31 +0200 Subject: [PATCH 01/15] adds verify account page for letter code --- app/assets/stylesheets/layout.scss | 13 +++++++++++++ app/controllers/pages_controller.rb | 3 +++ app/views/pages/verifica.html.erb | 27 +++++++++++++++++++++++++++ config/locales/pages.en.yml | 9 ++++++++- config/locales/pages.es.yml | 7 +++++++ config/routes.rb | 1 + 6 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 app/views/pages/verifica.html.erb diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 5e7c189bb..88a4ccab0 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -1767,6 +1767,19 @@ table { } } +.verify { + margin: rem-calc(24) 0 rem-calc(48); + + h1 { + color: $check; + + .icon-check { + line-height: rem-calc(30); + vertical-align: middle; + } + } +} + // 18. Comments // - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index daa90c7da..a75f65f06 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -46,6 +46,9 @@ class PagesController < ApplicationController def participation_world end + def verifica + end + def blog redirect_to "http://diario.madrid.es/participa/" end diff --git a/app/views/pages/verifica.html.erb b/app/views/pages/verifica.html.erb new file mode 100644 index 000000000..0a3110b29 --- /dev/null +++ b/app/views/pages/verifica.html.erb @@ -0,0 +1,27 @@ +
+
+
+

+ + <%= t("pages.verify.title") %> +

+ +

<%= t("pages.verify.info") %>

+
+ +
+
+ + "> + + + "> + + + "> + + " class="button radius success expand"> +
+
+
+
diff --git a/config/locales/pages.en.yml b/config/locales/pages.en.yml index 051217223..a01b380d7 100644 --- a/config/locales/pages.en.yml +++ b/config/locales/pages.en.yml @@ -18,4 +18,11 @@ en: transparency: "Transparency" opendata: - "Open Data" \ No newline at end of file + "Open Data" + verify: + title: "Verify your account" + info: "Introduce your access data and the code you received in letter." + email: "Email" + password: "Password" + code: "Secure code" + 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..8749aa715 100644 --- a/config/locales/pages.es.yml +++ b/config/locales/pages.es.yml @@ -21,3 +21,10 @@ es: "Transparencia" opendata: "Datos abiertos" + verify: + title: "Verifica tu cuenta" + info: "Introduce tus datos con los que te registraste y el código que has recibido en tu carta." + email: "Email" + password: "Contraseña" + code: "Código de seguridad" + submit: "Verificar mi cuenta" diff --git a/config/routes.rb b/config/routes.rb index c1a0e38ba..991a0e870 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -270,5 +270,6 @@ 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: "pages#verifica" end From ce134862724ddcb800d726f46c9f9be7967ed0af Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 19 Oct 2015 19:27:03 +0200 Subject: [PATCH 02/15] uses english for method and filenames --- app/controllers/pages_controller.rb | 2 +- app/views/pages/{verifica.html.erb => verify.html.erb} | 0 config/routes.rb | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename app/views/pages/{verifica.html.erb => verify.html.erb} (100%) diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index a75f65f06..20093c33e 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -46,7 +46,7 @@ class PagesController < ApplicationController def participation_world end - def verifica + def verify end def blog diff --git a/app/views/pages/verifica.html.erb b/app/views/pages/verify.html.erb similarity index 100% rename from app/views/pages/verifica.html.erb rename to app/views/pages/verify.html.erb diff --git a/config/routes.rb b/config/routes.rb index 991a0e870..7d7dda966 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -270,6 +270,6 @@ 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: "pages#verifica" + get "/verifica", to: "pages#verify" end From fd8684e713b6025379a001d4e3f32a4e4294154e Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 19 Oct 2015 19:32:53 +0200 Subject: [PATCH 03/15] redirects to show after asking for letter --- .../verification/letter_controller.rb | 5 ++++- app/views/verification/letter/edit.html.erb | 21 ------------------ app/views/verification/letter/show.html.erb | 22 +++++++++++++++++++ config/routes.rb | 2 +- 4 files changed, 27 insertions(+), 23 deletions(-) create mode 100644 app/views/verification/letter/show.html.erb diff --git a/app/controllers/verification/letter_controller.rb b/app/controllers/verification/letter_controller.rb index 105eef0ad..ac551910e 100644 --- a/app/controllers/verification/letter_controller.rb +++ b/app/controllers/verification/letter_controller.rb @@ -13,7 +13,10 @@ class Verification::LetterController < ApplicationController def create @letter = Verification::Letter.new(user: current_user) @letter.save - redirect_to edit_letter_path + redirect_to letter_path + end + + def show end def edit diff --git a/app/views/verification/letter/edit.html.erb b/app/views/verification/letter/edit.html.erb index d5722f1fb..8b1378917 100644 --- a/app/views/verification/letter/edit.html.erb +++ b/app/views/verification/letter/edit.html.erb @@ -1,22 +1 @@ - 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 @@ + diff --git a/config/routes.rb b/config/routes.rb index 7d7dda966..e513ee70a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -68,7 +68,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 From a6fd1fb489ab451bc05baf14c2ff52799a8c96e9 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 19 Oct 2015 19:37:16 +0200 Subject: [PATCH 04/15] moves letter verification to letter controller --- .../verification/letter_controller.rb | 6 +++-- app/views/verification/letter/edit.html.erb | 26 +++++++++++++++++++ config/routes.rb | 3 +-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/app/controllers/verification/letter_controller.rb b/app/controllers/verification/letter_controller.rb index ac551910e..34521cce9 100644 --- a/app/controllers/verification/letter_controller.rb +++ b/app/controllers/verification/letter_controller.rb @@ -1,11 +1,13 @@ class Verification::LetterController < ApplicationController - before_action :authenticate_user! + before_action :authenticate_user!, except: :edit before_action :verify_resident! before_action :verify_phone! before_action :verify_verified! before_action :verify_lock skip_authorization_check + layout :pages, only: :edit + def new @letter = Verification::Letter.new(user: current_user) end @@ -20,7 +22,7 @@ class Verification::LetterController < ApplicationController end def edit - @letter = Verification::Letter.new(user: current_user) + @letter = Verification::Letter.new end def update diff --git a/app/views/verification/letter/edit.html.erb b/app/views/verification/letter/edit.html.erb index 8b1378917..6c86a5766 100644 --- a/app/views/verification/letter/edit.html.erb +++ b/app/views/verification/letter/edit.html.erb @@ -1 +1,27 @@ +
+
+
+

+ + <%= t("pages.verify.title") %> +

+

<%= t("pages.verify.info") %>

+
+ +
+
+ + "> + + + "> + + + "> + + " class="button radius success expand"> +
+
+
+
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index e513ee70a..a69f08ab3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -270,6 +270,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: "pages#verify" - + get "/verifica", to: "verification/letter#edit" end From 5ac2784294d247af0443a9e4cb2ec71004e9af62 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 19 Oct 2015 20:32:55 +0200 Subject: [PATCH 05/15] removes unnecessary layout --- app/controllers/verification/letter_controller.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/controllers/verification/letter_controller.rb b/app/controllers/verification/letter_controller.rb index 34521cce9..5bb58d759 100644 --- a/app/controllers/verification/letter_controller.rb +++ b/app/controllers/verification/letter_controller.rb @@ -6,8 +6,6 @@ class Verification::LetterController < ApplicationController before_action :verify_lock skip_authorization_check - layout :pages, only: :edit - def new @letter = Verification::Letter.new(user: current_user) end From 0d01f431fb3f8b17252c228e67c5b9879f86243b Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 19 Oct 2015 20:33:10 +0200 Subject: [PATCH 06/15] simplifies verification form --- app/models/verification/letter.rb | 2 +- app/views/verification/letter/edit.html.erb | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/app/models/verification/letter.rb b/app/models/verification/letter.rb index aa6fd6a4b..96321a419 100644 --- a/app/models/verification/letter.rb +++ b/app/models/verification/letter.rb @@ -1,7 +1,7 @@ class Verification::Letter include ActiveModel::Model - attr_accessor :user, :verification_code + attr_accessor :user, :verification_code, :email, :password validates :user, presence: true diff --git a/app/views/verification/letter/edit.html.erb b/app/views/verification/letter/edit.html.erb index 6c86a5766..73c9b9a48 100644 --- a/app/views/verification/letter/edit.html.erb +++ b/app/views/verification/letter/edit.html.erb @@ -10,18 +10,13 @@
-
- - "> + <%= form_for @letter, url: edit_letter_path do |f| %> + <%= f.text_field :email, label: t("pages.verify.email") %> + <%= f.password_field :password, label: t("pages.verify.password") %> + <%= f.text_field :verification_code, label: t("pages.verify.code") %> - - "> - - - "> - - " class="button radius success expand"> -
+ <%= f.submit(class: "button radius success expand", value: t("pages.verify.submit")) %> + <% end %>
\ No newline at end of file From 5fe1bb3eeed4265d54023efdaaa45e8c1a627947 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 19 Oct 2015 22:58:44 +0200 Subject: [PATCH 07/15] verifies the letter's code --- .../verification/letter_controller.rb | 28 +++++++++++++------ app/models/verification/letter.rb | 21 +++++++------- app/views/verification/letter/edit.html.erb | 3 +- config/locales/en.yml | 1 + config/locales/es.yml | 1 + config/locales/verification.en.yml | 2 +- config/locales/verification.es.yml | 2 +- 7 files changed, 37 insertions(+), 21 deletions(-) diff --git a/app/controllers/verification/letter_controller.rb b/app/controllers/verification/letter_controller.rb index 5bb58d759..5f0513556 100644 --- a/app/controllers/verification/letter_controller.rb +++ b/app/controllers/verification/letter_controller.rb @@ -1,9 +1,12 @@ class Verification::LetterController < ApplicationController - before_action :authenticate_user!, except: :edit - before_action :verify_resident! - before_action :verify_phone! - before_action :verify_verified! - before_action :verify_lock + before_action :authenticate_user!, except: [:edit, :update] + before_action :check_credentials, only: :update + + before_action :verify_resident!, except: :edit + before_action :verify_phone!, except: :edit + before_action :verify_verified!, except: :edit + before_action :verify_lock, except: :edit + skip_authorization_check def new @@ -24,8 +27,8 @@ class Verification::LetterController < ApplicationController end def update - @letter = Verification::Letter.new(letter_params.merge(user: current_user)) - if @letter.verified? + @letter = Verification::Letter.new(letter_params.merge(user: current_user, verify: true)) + if @letter.valid? current_user.update(verified_at: Time.now) redirect_to account_path, notice: t('verification.letter.update.flash.success') else @@ -37,7 +40,7 @@ class Verification::LetterController < ApplicationController private def letter_params - params.require(:letter).permit(:verification_code) + params.require(:verification_letter).permit(:verification_code, :email, :password) end def verify_phone! @@ -46,4 +49,13 @@ class Verification::LetterController < ApplicationController end end + def check_credentials + user = User.where(email: letter_params[:email]).first + if user && user.valid_password?(letter_params[:password]) + sign_in(user) + else + redirect_to edit_letter_path, alert: t('devise.failure.invalid', authentication_keys: 'email') + end + end + end \ No newline at end of file diff --git a/app/models/verification/letter.rb b/app/models/verification/letter.rb index 96321a419..c1ace6063 100644 --- a/app/models/verification/letter.rb +++ b/app/models/verification/letter.rb @@ -1,9 +1,12 @@ class Verification::Letter include ActiveModel::Model - attr_accessor :user, :verification_code, :email, :password + attr_accessor :user, :verification_code, :email, :password, :verify - validates :user, presence: true + validates :user, presence: true, on: :create + + validate :letter_sent, if: :verify? + validate :correct_code, if: :verify? def save valid? && @@ -14,22 +17,20 @@ class Verification::Letter user.update(letter_requested_at: Time.now, letter_verification_code: generate_verification_code) end - def verified? - validate_letter_sent - validate_correct_code - errors.blank? - end - - def validate_letter_sent + def letter_sent errors.add(:verification_code, I18n.t('verification.letter.errors.letter_not_sent')) unless user.letter_sent_at.present? end - def validate_correct_code + def correct_code errors.add(:verification_code, I18n.t('verification.letter.errors.incorect_code')) unless user.letter_verification_code == verification_code end + def verify? + verify.present? + end + def increase_letter_verification_tries user.update(letter_verification_tries: user.letter_verification_tries += 1) end diff --git a/app/views/verification/letter/edit.html.erb b/app/views/verification/letter/edit.html.erb index 73c9b9a48..3f2084d26 100644 --- a/app/views/verification/letter/edit.html.erb +++ b/app/views/verification/letter/edit.html.erb @@ -10,7 +10,8 @@
- <%= form_for @letter, url: edit_letter_path do |f| %> + <%= form_for @letter, url: letter_path, method: :patch do |f| %> + <%= render "/shared/errors", resource: @letter %> <%= f.text_field :email, label: t("pages.verify.email") %> <%= f.password_field :password, label: t("pages.verify.password") %> <%= f.text_field :verification_code, label: t("pages.verify.code") %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 8e56cd69e..7365d2703 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 18763a895..6c94c2ef5 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/verification.en.yml b/config/locales/verification.en.yml index 50e0d425b..68aba1603 100644 --- a/config/locales/verification.en.yml +++ b/config/locales/verification.en.yml @@ -88,7 +88,7 @@ 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: diff --git a/config/locales/verification.es.yml b/config/locales/verification.es.yml index fbd7c9499..859eadf3a 100644 --- a/config/locales/verification.es.yml +++ b/config/locales/verification.es.yml @@ -88,7 +88,7 @@ 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: From 17bb6335676315069085d4866f6486a824c3e626 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 19 Oct 2015 22:58:54 +0200 Subject: [PATCH 08/15] adds specs --- spec/features/verification/letter_spec.rb | 93 +++++++++++++++++++---- spec/models/letter_spec.rb | 10 +-- 2 files changed, 84 insertions(+), 19 deletions(-) diff --git a/spec/features/verification/letter_spec.rb b/spec/features/verification/letter_spec.rb index d4b7eeb30..e1fe948f5 100644 --- a/spec/features/verification/letter_spec.rb +++ b/spec/features/verification/letter_spec.rb @@ -2,7 +2,7 @@ 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) @@ -26,19 +26,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 +45,82 @@ 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_sent_at: 1.day.ago, + 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_sent_at: 1.day.ago, + 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 error_message + end + + scenario '6 tries allowed' do + user = create(:user, residence_verified_at: Time.now, + confirmed_phone: "611111111", + letter_sent_at: 1.day.ago, + 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/models/letter_spec.rb b/spec/models/letter_spec.rb index 683fb06d5..6b5e10d77 100644 --- a/spec/models/letter_spec.rb +++ b/spec/models/letter_spec.rb @@ -33,14 +33,14 @@ describe 'Verification::Letter' do 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) - expect(letter.verified?).to eq(false) + expect(letter.valid?).to eq(false) expect(letter.errors[:verification_code].first).to eq("We have not sent you the letter with the code yet") end @@ -48,7 +48,7 @@ describe 'Verification::Letter' 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 @@ -56,7 +56,7 @@ describe 'Verification::Letter' do letter.user.update(letter_sent_at: 1.day.ago, 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 From 8904748ae23cda26c0c27122d32967a8fa54757e Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 19 Oct 2015 23:19:53 +0200 Subject: [PATCH 09/15] fixes specs --- app/models/verification/letter.rb | 2 +- config/i18n-tasks.yml | 1 + spec/features/verification/verification_path_spec.rb | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/verification/letter.rb b/app/models/verification/letter.rb index c1ace6063..0dcaf1c83 100644 --- a/app/models/verification/letter.rb +++ b/app/models/verification/letter.rb @@ -3,7 +3,7 @@ class Verification::Letter attr_accessor :user, :verification_code, :email, :password, :verify - validates :user, presence: true, on: :create + validates :user, presence: true validate :letter_sent, if: :verify? validate :correct_code, if: :verify? diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index da441e691..5f4943744 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' ## Consider these keys used: ignore_unused: 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 From 20aee99bbf1ed780b91ed09deb69db46f2066dfe Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 20 Oct 2015 13:16:40 +0200 Subject: [PATCH 10/15] remove letter_sent verification --- app/models/verification/letter.rb | 8 +------- config/locales/verification.en.yml | 3 +-- config/locales/verification.es.yml | 3 +-- spec/features/verification/letter_spec.rb | 9 ++------- spec/models/letter_spec.rb | 17 +++++------------ 5 files changed, 10 insertions(+), 30 deletions(-) diff --git a/app/models/verification/letter.rb b/app/models/verification/letter.rb index 0dcaf1c83..2124e1664 100644 --- a/app/models/verification/letter.rb +++ b/app/models/verification/letter.rb @@ -5,7 +5,6 @@ class Verification::Letter validates :user, presence: true - validate :letter_sent, if: :verify? validate :correct_code, if: :verify? def save @@ -17,13 +16,8 @@ class Verification::Letter user.update(letter_requested_at: Time.now, letter_verification_code: generate_verification_code) end - def letter_sent - errors.add(:verification_code, I18n.t('verification.letter.errors.letter_not_sent')) unless - user.letter_sent_at.present? - end - def correct_code - errors.add(:verification_code, I18n.t('verification.letter.errors.incorect_code')) unless + errors.add(:verification_code, I18n.t('verification.letter.errors.incorrect_code')) unless user.letter_verification_code == verification_code end diff --git a/config/locales/verification.en.yml b/config/locales/verification.en.yml index 68aba1603..014f143ab 100644 --- a/config/locales/verification.en.yml +++ b/config/locales/verification.en.yml @@ -92,8 +92,7 @@ en: 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 859eadf3a..57ffeff43 100644 --- a/config/locales/verification.es.yml +++ b/config/locales/verification.es.yml @@ -92,8 +92,7 @@ es: 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/spec/features/verification/letter_spec.rb b/spec/features/verification/letter_spec.rb index e1fe948f5..656f6708e 100644 --- a/spec/features/verification/letter_spec.rb +++ b/spec/features/verification/letter_spec.rb @@ -4,8 +4,7 @@ feature 'Verify Letter' 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 @@ -51,7 +49,6 @@ feature 'Verify Letter' do scenario "Valid verification user logged in" do user = create(:user, residence_verified_at: Time.now, confirmed_phone: "611111111", - letter_sent_at: 1.day.ago, letter_verification_code: "123456") login_as(user) @@ -69,7 +66,6 @@ feature 'Verify Letter' do scenario "Valid verification user not logged in" do user = create(:user, residence_verified_at: Time.now, confirmed_phone: "611111111", - letter_sent_at: 1.day.ago, letter_verification_code: "123456") visit edit_letter_path @@ -106,7 +102,6 @@ feature 'Verify Letter' do scenario '6 tries allowed' do user = create(:user, residence_verified_at: Time.now, confirmed_phone: "611111111", - letter_sent_at: 1.day.ago, letter_verification_code: "123456") visit edit_letter_path diff --git a/spec/models/letter_spec.rb b/spec/models/letter_spec.rb index 6b5e10d77..3b774b618 100644 --- a/spec/models/letter_spec.rb +++ b/spec/models/letter_spec.rb @@ -37,23 +37,16 @@ describe 'Verification::Letter' do let(:letter) { build(:verification_letter, verify: true) } - it "letter not sent" do - letter.user.update(letter_sent_at: nil) - - expect(letter.valid?).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") + it "incorrect code" do + letter.user.update(letter_verification_code: "123456") letter.verification_code = nil 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.valid?).to eq(true) @@ -61,4 +54,4 @@ describe 'Verification::Letter' do end end -end \ No newline at end of file +end From faf29e81b7589bebe702c4beec4d51a989850b41 Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 20 Oct 2015 13:31:52 +0200 Subject: [PATCH 11/15] removes user.letter_sent from the database --- .../20151020112354_remove_letter_sent_at_from_users.rb | 5 +++++ db/schema.rb | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20151020112354_remove_letter_sent_at_from_users.rb 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 56d5a4a9f..b0af9bb10 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: 20151015135154) 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: 20151015135154) 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" From b33553cc1d39f2f24240c00663d63a6acc17a029 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Tue, 20 Oct 2015 15:45:08 +0200 Subject: [PATCH 12/15] Adds new styles to verifica page --- app/assets/fonts/icons.eot | Bin 10544 -> 10856 bytes app/assets/fonts/icons.svg | 1 + app/assets/fonts/icons.ttf | Bin 10388 -> 10700 bytes app/assets/fonts/icons.woff | Bin 8084 -> 8300 bytes app/assets/stylesheets/icons.scss | 3 +++ app/assets/stylesheets/layout.scss | 21 ++++++++++++++- app/views/verification/letter/edit.html.erb | 27 +++++++++++++------- config/locales/pages.en.yml | 5 ++-- config/locales/pages.es.yml | 5 ++-- 9 files changed, 48 insertions(+), 14 deletions(-) diff --git a/app/assets/fonts/icons.eot b/app/assets/fonts/icons.eot index fed38cb4b73b91b2adc9fd5f288de42bdce9660e..3046c50cc222d1c158d1f8748287cb28c02f44be 100644 GIT binary patch delta 794 zcmYjPUq}=|82@HwclK^?_w3wj&Ff0{E_b~H%dYc`@LzD{gVBYGL>aZ%r4L?SX;D%r zK1ffIjYvf#K|&7^hEPw@OD{t8VEB^0)KfteLA`3byqZUV#nTe$8U9KL>`C;t2efP^$QIh1$L%P);zVjFStr-nxc+`BFJ zcL1k=I^y3;C%J6NdooNz^VCM@GkPn$hC`&Tr(iKrjo(+i-2v8INR=U28|C_}_(n=EI6M5fNlJI2Z5iNfUa1U9@C5i{UfwK?$mdP;~$3H2x z!{B>?Ig%XM4EHJYc1oGoeHN>p)I%aJ3cG5=5C=}*#D`q!^ z(#;uks4~f#U(IHu5Ysec!Zb9Eg``YY^;0I1ClaHC5K7oaKa*%u&zVeO8j*dfq;ecS znP^O=W=^jN>UELuMt?Y>2MzMX2J0cXxkPZTH*A6~F`^42F&9Mb~o!U~`a`nlxh3?{7$SzK8Z5 zlQWAGE9dKvfb<2ZBU2$`+`j95vYzv25QbGHfIOPyVIpzsgh0&vgFE?#C#V zNCv0*AFxAAbZ|mOf~tew-v*sX&@IH%1j9n66HTI!)FKqag%Y@-q7-HDpd1>{l$QCN zl*^B#W8N!wP^+_)JgV{{&7-M^SgtbcNLkp93|v}RA^nL@YpT|aN|8)Xqg?6Ow6Gm{ zIIyrn`Yk`zhMAY==#{kk^Z-xlZo28I-g72b6tGqipHX<5X^=%MUq~jGpphz@OlV>Z Mxbq)8i28qgKUB(T9RL6T diff --git a/app/assets/fonts/icons.svg b/app/assets/fonts/icons.svg index 602058baf..c107e740d 100644 --- a/app/assets/fonts/icons.svg +++ b/app/assets/fonts/icons.svg @@ -44,4 +44,5 @@ + diff --git a/app/assets/fonts/icons.ttf b/app/assets/fonts/icons.ttf index 96e94423136a4d546cf33e396661d0ab27ad8889..b933f1c3f1f5f651f93736c4336dbde93769ad04 100644 GIT binary patch delta 862 zcmYjPO-vI(7=1Id-L~6qN!hw+E!ZErEhH$`QjFn86RZc+q9w!_jA?2G475eiDAAO7 zFrJLE#Ha_kz)52?Bzn8aUB+JdGj9#2*k3X0itonf2ih06Rx~C_j-ae+_+$Gx^ZIj3bwbbZn;bA3EI6q#>=jOVe z>;}XO(g!DUH_Euq?~~_Y;=y8WqHyPP$4Si4m8#_! zau%XJiOUoXG@=Rn5JnIoM9>TaQN$28ukgDpZf^2-=5x`{y+@aSiwmJjb>AoldrNCF z$Pwv~?Xum&sFTAnBetJWXT)~-8uUYo;!L&)RXAk3U3L&?OFESe zi3>74XeWCn$eY{RLrQPG;6h=|+%9t}vYj)90_uAem+lK}t!jS1#yU0C<56K|qwz`@ zWh*rjY*?_c4KBR5uuS?|HEoiU6onpk2XlB(Z()Hxv|3oA7}LTw=vcC_O!_LukVgqc zOaWv0QqlYq?H38On`xt!C)&+PW6)eNLiB^a8v~pf%c7vTKSJ4Yo_R{Qd(Zj4d(XMwckX((yXPPP$ih4<2>AWMPW@u<2vDbp zb+6PBm-{^^JQ#vNab?R9|*qhMe zVW)5H8Yl@8m(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JKg&*#~SarFt2{@GhDnw}Q* z^*GsFRIf)Onf*_v}yc_mHYM&h{nU7 zGh;m+J>#7ltmdeO){KV6(%;}hbm;`XR&BPJ)jZ5*0%;8bx`v{9^^;9>mw+#CeyUVoqp#OkvqpHsw_89`39*5*`P zPID)`9T2%|6x~Uy(MXUGuCvcyFlB$kUNRj-nbL2t*Yq+PT3WJy1fJT1Ql!Cq9jONg zY)arWhQm!G9)e%Lle8;VVW0l)f-$Ef88@GP6h_uVwcyIsFX9LTb-Cf+h+3B z8a|{)P7xf#Cpc_yn-{#itXGVdSSh3@Yi9!8qX~+}gE`1gu#4W`aCaHB!~bnZuG=*| zcfDUhgIP)!3)cI5gwwxs9)M*ZH*3~^fNs*?5YydrbwPQSW@ctqfH1E1xT)}c#daQj zc4B}WKY|Sa@L!*mnb`)M#YY58GYhj1655|^V6F%O@S6a=RCsbtuq=L<8S0lGg>=f8 z2bH*?;hnd*CgI^AV^qi-nTpABt`)Y}-jOaY%Gz928*diPipBD{Q1-509eGcCtoNVd z6i{+L2@4MznJxruE4hd)tcHY2UW_~h!pK0tV%^l+0+)GISC@M# za=oQ$V&7$M5C!oOH<}hjum=f@%4ZN*x7}Tup2HkCqrQK){eS5Ii}byWhOGzZK2A3- zj*x!Zl^kZPoERA9DVQR_hh4-!se}}|U;r~F!uuzq8UR4|-$>`gCWj$*T&zG?DGx%Z zB17rDh2`5rN6uBEnm6I8Vsze5dm(jbIK^C8?MYFAKz=do`H$o57tY>gAYCvkXcKrL z^#UX_?BTqdaSm#@3@zD#B%+DWwT-UIG{*Kx){3J?6%`FuvwDMhSFgiT3>wOebgs+s z`b293?eguJ95d+Xs#(XEGZN~oAD#-^Qo_6lo@8<(mHx0E3$EvOHNPpn016&B{r>N0 PY{U@aQSII#5di-`VvBQE diff --git a/app/assets/stylesheets/icons.scss b/app/assets/stylesheets/icons.scss index 93f7ebcf3..eda8b979d 100644 --- a/app/assets/stylesheets/icons.scss +++ b/app/assets/stylesheets/icons.scss @@ -148,3 +148,6 @@ .icon-youtube:before { content: "K"; } +.icon-letter:before { + content: "L"; +} \ No newline at end of file diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 88a4ccab0..356299fba 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -1768,7 +1768,8 @@ table { } .verify { - margin: rem-calc(24) 0 rem-calc(48); + margin-bottom: rem-calc(48); + margin-top: rem-calc(24); h1 { color: $check; @@ -1778,6 +1779,24 @@ table { vertical-align: middle; } } + + .letter-divider { + border-top: 1px solid #DDDDDD; + clear: both; + height: 0; + margin: rem-calc(24) 0; + position: relative; + + .icon-letter { + background: white; + color: $info-color; + font-size: rem-calc(24); + margin-left: rem-calc(-27); + padding: 0 rem-calc(12); + position: absolute; + top: rem-calc(-12); + } + } } // 18. Comments diff --git a/app/views/verification/letter/edit.html.erb b/app/views/verification/letter/edit.html.erb index 3f2084d26..65da25a05 100644 --- a/app/views/verification/letter/edit.html.erb +++ b/app/views/verification/letter/edit.html.erb @@ -1,5 +1,5 @@
-
+

@@ -9,15 +9,24 @@

<%= t("pages.verify.info") %>

-
- <%= form_for @letter, url: letter_path, method: :patch do |f| %> - <%= render "/shared/errors", resource: @letter %> - <%= f.text_field :email, label: t("pages.verify.email") %> - <%= f.password_field :password, label: t("pages.verify.password") %> - <%= f.text_field :verification_code, label: t("pages.verify.code") %> +
+ <%= form_for @letter, url: letter_path, method: :patch do |f| %> + <%= render "/shared/errors", resource: @letter %> + <%= 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") %> - <%= f.submit(class: "button radius success expand", value: t("pages.verify.submit")) %> - <% end %> +

+ +

+ +

+ <%= 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 %>
\ No newline at end of file diff --git a/config/locales/pages.en.yml b/config/locales/pages.en.yml index a01b380d7..ef2b271a9 100644 --- a/config/locales/pages.en.yml +++ b/config/locales/pages.en.yml @@ -21,8 +21,9 @@ en: "Open Data" verify: title: "Verify your account" - info: "Introduce your access data and the code you received in letter." + info: "For verufy your account introduce your access data:" + info_code: "Now introduce the code you received in letter:" email: "Email" password: "Password" - code: "Secure code" + 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 8749aa715..623b38ecf 100644 --- a/config/locales/pages.es.yml +++ b/config/locales/pages.es.yml @@ -23,8 +23,9 @@ es: "Datos abiertos" verify: title: "Verifica tu cuenta" - info: "Introduce tus datos con los que te registraste y el código que has recibido en tu carta." + 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 de seguridad" + code: "Código que has recibido en tu carta" submit: "Verificar mi cuenta" From 0d0806c9aec45914cc02ddf04a8b38f6b97cbb6b Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 20 Oct 2015 16:19:17 +0200 Subject: [PATCH 13/15] improvements in the letter verification error messages --- app/controllers/application_controller.rb | 8 ++++--- .../verification/letter_controller.rb | 15 +++++++------ app/models/verification/letter.rb | 21 ++++++++++++++----- app/views/verification/letter/edit.html.erb | 3 +-- spec/factories.rb | 3 +++ spec/features/verification/letter_spec.rb | 2 +- spec/models/letter_spec.rb | 12 ++++------- 7 files changed, 37 insertions(+), 27 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d5d351038..03b175e17 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -52,7 +52,7 @@ class ApplicationController < ActionController::Base end def verify_lock - if current_user.locked? + if current_user.try(:locked?) redirect_to account_path, alert: t('verification.alert.lock') end end @@ -97,12 +97,14 @@ class ApplicationController < ActionController::Base end def verify_resident! - unless current_user.residence_verified? + if current_user && !current_user.residence_verified? redirect_to new_residence_path, alert: t('verification.residence.alert.unconfirmed_residency') end end def verify_verified! - redirect_to(account_path, notice: t('verification.redirect_notices.already_verified')) if current_user.level_three_verified? + if current_user.try(:level_three_verified?) + redirect_to(account_path, notice: t('verification.redirect_notices.already_verified')) + end end end diff --git a/app/controllers/verification/letter_controller.rb b/app/controllers/verification/letter_controller.rb index 5f0513556..8b8a19f55 100644 --- a/app/controllers/verification/letter_controller.rb +++ b/app/controllers/verification/letter_controller.rb @@ -1,6 +1,6 @@ class Verification::LetterController < ApplicationController before_action :authenticate_user!, except: [:edit, :update] - before_action :check_credentials, only: :update + before_action :login_via_form, only: :update before_action :verify_resident!, except: :edit before_action :verify_phone!, except: :edit @@ -32,7 +32,7 @@ class Verification::LetterController < ApplicationController current_user.update(verified_at: Time.now) redirect_to account_path, notice: t('verification.letter.update.flash.success') else - Lock.increase_tries(@letter.user) + Lock.increase_tries(@letter.user) if @letter.user render :edit end end @@ -44,18 +44,17 @@ class Verification::LetterController < ApplicationController end def verify_phone! - unless current_user.confirmed_phone? + if current_user && !current_user.confirmed_phone? redirect_to verified_user_path, alert: t('verification.letter.alert.unconfirmed_code') end end - def check_credentials - user = User.where(email: letter_params[:email]).first + def login_via_form + user = User.find_by_email(letter_params[:email]) if user && user.valid_password?(letter_params[:password]) sign_in(user) - else - redirect_to edit_letter_path, alert: t('devise.failure.invalid', authentication_keys: 'email') end end -end \ No newline at end of file + +end diff --git a/app/models/verification/letter.rb b/app/models/verification/letter.rb index 2124e1664..897960a72 100644 --- a/app/models/verification/letter.rb +++ b/app/models/verification/letter.rb @@ -3,9 +3,12 @@ class Verification::Letter attr_accessor :user, :verification_code, :email, :password, :verify - validates :user, presence: true + validates :email, presence: true + validates :password, presence: true + validates :verification_code, presence: true - validate :correct_code, if: :verify? + validate :validate_existing_user + validate :validate_correct_code, if: :verify? def save valid? && @@ -16,9 +19,17 @@ class Verification::Letter user.update(letter_requested_at: Time.now, letter_verification_code: generate_verification_code) end - def correct_code - errors.add(:verification_code, I18n.t('verification.letter.errors.incorrect_code')) unless - user.letter_verification_code == verification_code + def validate_existing_user + unless user + errors.add(:email, I18n.t('devise.failure.invalid', authentication_keys: 'email')) + end + end + + def validate_correct_code + return if errors.include?(:verification_code) + if user.try(:letter_verification_code) != verification_code + errors.add(:verification_code, I18n.t('verification.letter.errors.incorrect_code')) + end end def verify? diff --git a/app/views/verification/letter/edit.html.erb b/app/views/verification/letter/edit.html.erb index 3f2084d26..bf847da5a 100644 --- a/app/views/verification/letter/edit.html.erb +++ b/app/views/verification/letter/edit.html.erb @@ -11,7 +11,6 @@
<%= form_for @letter, url: letter_path, method: :patch do |f| %> - <%= render "/shared/errors", resource: @letter %> <%= f.text_field :email, label: t("pages.verify.email") %> <%= f.password_field :password, label: t("pages.verify.password") %> <%= f.text_field :verification_code, label: t("pages.verify.code") %> @@ -20,4 +19,4 @@ <% end %>
-
\ No newline at end of file +
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 656f6708e..00baef12d 100644 --- a/spec/features/verification/letter_spec.rb +++ b/spec/features/verification/letter_spec.rb @@ -96,7 +96,7 @@ feature 'Verify Letter' do fill_in "verification_letter_password", with: user.password click_button "Verify my account" - expect(page).to have_content error_message + expect(page).to have_content "can't be blank" end scenario '6 tries allowed' do diff --git a/spec/models/letter_spec.rb b/spec/models/letter_spec.rb index 3b774b618..68d6afe5b 100644 --- a/spec/models/letter_spec.rb +++ b/spec/models/letter_spec.rb @@ -21,14 +21,10 @@ 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 @@ -39,7 +35,7 @@ describe 'Verification::Letter' do it "incorrect code" do letter.user.update(letter_verification_code: "123456") - letter.verification_code = nil + letter.verification_code = "5555" expect(letter.valid?).to eq(false) expect(letter.errors[:verification_code].first).to eq("Incorrect confirmation code") From 18db6482f96db635fcda4e4c17be764ecc886bb0 Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 20 Oct 2015 17:18:28 +0200 Subject: [PATCH 14/15] makes sure verifications only happen for signed in users when doing a letter verification --- app/controllers/application_controller.rb | 6 +++--- app/controllers/verification/letter_controller.rb | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 03b175e17..3ef1245e8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -52,7 +52,7 @@ class ApplicationController < ActionController::Base end def verify_lock - if current_user.try(:locked?) + if current_user.locked? redirect_to account_path, alert: t('verification.alert.lock') end end @@ -97,13 +97,13 @@ class ApplicationController < ActionController::Base end def verify_resident! - if current_user && !current_user.residence_verified? + unless current_user.residence_verified? redirect_to new_residence_path, alert: t('verification.residence.alert.unconfirmed_residency') end end def verify_verified! - if current_user.try(:level_three_verified?) + if current_user.level_three_verified? redirect_to(account_path, notice: t('verification.redirect_notices.already_verified')) end end diff --git a/app/controllers/verification/letter_controller.rb b/app/controllers/verification/letter_controller.rb index 8b8a19f55..ed5288a45 100644 --- a/app/controllers/verification/letter_controller.rb +++ b/app/controllers/verification/letter_controller.rb @@ -2,10 +2,10 @@ class Verification::LetterController < ApplicationController before_action :authenticate_user!, except: [:edit, :update] before_action :login_via_form, only: :update - before_action :verify_resident!, except: :edit - before_action :verify_phone!, except: :edit - before_action :verify_verified!, except: :edit - before_action :verify_lock, except: :edit + before_action :verify_resident!, except: :edit, if: :signed_in? + before_action :verify_phone!, except: :edit, if: :signed_in? + before_action :verify_verified!, except: :edit, if: :signed_in? + before_action :verify_lock, except: :edit, if: :signed_in? skip_authorization_check @@ -44,13 +44,13 @@ class Verification::LetterController < ApplicationController end def verify_phone! - if current_user && !current_user.confirmed_phone? + unless current_user.confirmed_phone? redirect_to verified_user_path, alert: t('verification.letter.alert.unconfirmed_code') end end def login_via_form - user = User.find_by_email(letter_params[:email]) + user = User.find_by email: letter_params[:email] if user && user.valid_password?(letter_params[:password]) sign_in(user) end From f596beaaf5147bf2414a3babb0d5a657eac5f722 Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 20 Oct 2015 17:33:16 +0200 Subject: [PATCH 15/15] removes unnecessary conditions from before_actions in verification/letter_controller --- app/controllers/verification/letter_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/verification/letter_controller.rb b/app/controllers/verification/letter_controller.rb index ed5288a45..bf5033b32 100644 --- a/app/controllers/verification/letter_controller.rb +++ b/app/controllers/verification/letter_controller.rb @@ -2,10 +2,10 @@ class Verification::LetterController < ApplicationController before_action :authenticate_user!, except: [:edit, :update] before_action :login_via_form, only: :update - before_action :verify_resident!, except: :edit, if: :signed_in? - before_action :verify_phone!, except: :edit, if: :signed_in? - before_action :verify_verified!, except: :edit, if: :signed_in? - before_action :verify_lock, except: :edit, if: :signed_in? + before_action :verify_resident!, if: :signed_in? + before_action :verify_phone!, if: :signed_in? + before_action :verify_verified!, if: :signed_in? + before_action :verify_lock, if: :signed_in? skip_authorization_check