diff --git a/app/controllers/verification/letter_controller.rb b/app/controllers/verification/letter_controller.rb index e302a1bc6..da2491e4c 100644 --- a/app/controllers/verification/letter_controller.rb +++ b/app/controllers/verification/letter_controller.rb @@ -2,6 +2,7 @@ class Verification::LetterController < ApplicationController before_action :authenticate_user! before_action :verify_resident! before_action :verify_phone! + before_action :verify_attemps_left! skip_authorization_check def new @@ -28,6 +29,7 @@ class Verification::LetterController < ApplicationController current_user.update(verified_at: Time.now) redirect_to account_path, notice: t('verification.letter.update.flash.success') else + @letter.increase_letter_verification_tries @error = t('verification.letter.update.error') render :edit end @@ -44,4 +46,10 @@ class Verification::LetterController < ApplicationController redirect_to verified_user_path, alert: t('verification.letter.alert.unconfirmed_code') end end + + def verify_attemps_left! + if current_user.letter_verification_tries >= 2 + redirect_to account_path, alert: t('verification.letter.alert.verify_attemps_left') + end + end end \ No newline at end of file diff --git a/app/models/verification/letter.rb b/app/models/verification/letter.rb index 077890600..16ca83a43 100644 --- a/app/models/verification/letter.rb +++ b/app/models/verification/letter.rb @@ -25,6 +25,10 @@ class Verification::Letter user.letter_verification_code == verification_code end + def increase_letter_verification_tries + user.update(letter_verification_tries: user.letter_verification_tries += 1) + end + def update_user_address user.address = Address.new(parsed_address) user.save diff --git a/config/locales/verification.en.yml b/config/locales/verification.en.yml index bcc818d97..3480d5a4c 100644 --- a/config/locales/verification.en.yml +++ b/config/locales/verification.en.yml @@ -83,6 +83,7 @@ en: success: "Correct code. Your account is verified" alert: unconfirmed_code: "You have not yet enter the confirmation code" + verify_attemps_left: "You have reached the maximum number of letter verification tries" verified_user: show: title: "Available information" diff --git a/config/locales/verification.es.yml b/config/locales/verification.es.yml index 75442af5d..e500bc33d 100644 --- a/config/locales/verification.es.yml +++ b/config/locales/verification.es.yml @@ -83,6 +83,7 @@ es: success: "Código correcto. Tu cuenta ya está verificada" alert: unconfirmed_code: "Todavía no has introducido el código de confirmación" + verify_attemps_left: "Has llegado al máximo número de intentos de verificar tu carta." verified_user: show: title: "Información disponible" diff --git a/db/migrate/20150910092713_add_letter_verification_tries_to_users.rb b/db/migrate/20150910092713_add_letter_verification_tries_to_users.rb new file mode 100644 index 000000000..622ce6b2d --- /dev/null +++ b/db/migrate/20150910092713_add_letter_verification_tries_to_users.rb @@ -0,0 +1,5 @@ +class AddLetterVerificationTriesToUsers < ActiveRecord::Migration + def change + add_column :users, :letter_verification_tries, :integer, default: 0 + end +end