Merge pull request #472 from AyuntamientoMadrid/verification-path
Verification path
This commit is contained in:
@@ -96,4 +96,8 @@ class ApplicationController < ActionController::Base
|
||||
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?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class Verification::EmailController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
before_action :verify_verified!
|
||||
before_action :set_verified_user, only: :create
|
||||
skip_authorization_check
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ class Verification::LetterController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
before_action :verify_resident!
|
||||
before_action :verify_phone!
|
||||
before_action :verify_verified!
|
||||
before_action :verify_lock
|
||||
skip_authorization_check
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class Verification::ResidenceController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
before_action :verify_verified!
|
||||
before_action :verify_lock, only: [:new, :create]
|
||||
skip_authorization_check
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class Verification::SmsController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
before_action :verify_resident!
|
||||
before_action :verify_verified!
|
||||
before_action :verify_lock, only: [:new, :create]
|
||||
before_action :set_phone, only: :create
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class Verification::VerifiedUserController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
before_action :verify_verified!
|
||||
skip_authorization_check
|
||||
|
||||
def show
|
||||
|
||||
31
app/controllers/verification_controller.rb
Normal file
31
app/controllers/verification_controller.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
class VerificationController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
before_action :verify_lock
|
||||
|
||||
skip_authorization_check
|
||||
|
||||
def show
|
||||
redirect_to next_step_path[:path], notice: next_step_path[:notice]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def next_step_path(user = current_user)
|
||||
if user.level_three_verified?
|
||||
{ path: account_path, notice: t('verification.redirect_notices.already_verified') }
|
||||
elsif user.verification_letter_sent?
|
||||
{ path: edit_letter_path }
|
||||
elsif user.level_two_verified?
|
||||
{ path: new_letter_path }
|
||||
elsif user.verification_sms_sent?
|
||||
{ path: edit_sms_path }
|
||||
elsif user.verification_email_sent?
|
||||
{ path: verified_user_path, notice: t('verification.redirect_notices.email_already_sent') }
|
||||
elsif user.residence_verified?
|
||||
{ path: verified_user_path }
|
||||
else
|
||||
{ path: new_residence_path }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -10,9 +10,9 @@
|
||||
<%= t("account.show.verified_account") %>
|
||||
</p>
|
||||
<% elsif current_user.level_two_verified? %>
|
||||
<%= link_to t("account.show.finish_verification"), new_letter_path, class: "button radius small success right" %>
|
||||
<%= link_to t("account.show.finish_verification"), verification_path, class: "button radius small success right" %>
|
||||
<% else %>
|
||||
<%= link_to t("account.show.verify_my_account"), new_residence_path, class: "button radius small success right" %>
|
||||
<%= link_to t("account.show.verify_my_account"), verification_path, class: "button radius small success right" %>
|
||||
<% end %>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<div class="anonymous-votes" style='display:none'>
|
||||
<p>
|
||||
<%= t("votes.anonymous",
|
||||
verify_account: link_to(t("votes.verify_account"), new_residence_path )).html_safe %>
|
||||
verify_account: link_to(t("votes.verify_account"), verification_path )).html_safe %>
|
||||
</p>
|
||||
</div>
|
||||
<% elsif !user_signed_in? %>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<p><%= t("welcome.welcome.instructions_3_html") %></p>
|
||||
<p>
|
||||
<%= link_to t("welcome.welcome.verify_account"),
|
||||
new_residence_path, class: "button large success radius margin-top expand" %>
|
||||
verification_path, class: "button large success radius margin-top expand" %>
|
||||
</p>
|
||||
<p class="text-center">
|
||||
<%= link_to t("welcome.welcome.go_to_index"),
|
||||
|
||||
@@ -211,7 +211,7 @@ es:
|
||||
welcome:
|
||||
title: Verificación de cuenta
|
||||
instructions_1_html: "Bienvenido a la página de participación ciudadana"
|
||||
instructions_2_html: "Hemos detectado que <b>tu email está confirmada pero no hemos verificado tus datos todavía</b>."
|
||||
instructions_2_html: "Hemos detectado que <b>tu dirección de email está confirmada pero no hemos verificado tus datos todavía</b>."
|
||||
instructions_3_html: "Sin verificar tus datos <b>el acceso que tienes es limitado</b>. Verificarlos ahora te permitirá, por ejemplo, apoyar propuestas ciudadanas."
|
||||
verify_account: "Verificar mi cuenta"
|
||||
go_to_index: "Quiero entrar como un usuario no verificado (acceso limitado)"
|
||||
|
||||
@@ -93,4 +93,7 @@ en:
|
||||
phone_title: "Phones"
|
||||
use_another_phone: "Use another phone"
|
||||
form:
|
||||
submit_button: "Send code"
|
||||
submit_button: "Send code"
|
||||
redirect_notices:
|
||||
email_already_sent: "We already sent you a confirmation email, if you have not received it you can try resend it here"
|
||||
already_verified: "You are a verified user!"
|
||||
|
||||
@@ -94,3 +94,6 @@ es:
|
||||
use_another_phone: "Utilizar otro teléfono"
|
||||
form:
|
||||
submit_button: "Enviar código"
|
||||
redirect_notices:
|
||||
email_already_sent: "Ya te enviamos un email con un enlace de confirmación, si no lo encuentras puedes solicitar aquí que te lo reenviemos"
|
||||
already_verified: "Tu cuenta ya está verificada"
|
||||
|
||||
@@ -46,6 +46,7 @@ Rails.application.routes.draw do
|
||||
end
|
||||
|
||||
resource :account, controller: "account", only: [:show, :update]
|
||||
resource :verification, controller: "verification", only: [:show]
|
||||
|
||||
scope module: :verification do
|
||||
resource :residence, controller: "residence", only: [:new, :create]
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
module Verification
|
||||
|
||||
def verification_email_sent?
|
||||
email_verification_token.present?
|
||||
end
|
||||
|
||||
def verification_sms_sent?
|
||||
unconfirmed_phone.present? && sms_confirmation_code.present?
|
||||
end
|
||||
|
||||
def verification_letter_sent?
|
||||
letter_requested_at.present? && letter_verification_code.present?
|
||||
end
|
||||
|
||||
def residence_verified?
|
||||
residence_verified_at.present?
|
||||
end
|
||||
|
||||
91
spec/features/verification/verification_path_spec.rb
Normal file
91
spec/features/verification/verification_path_spec.rb
Normal file
@@ -0,0 +1,91 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Verification path' do
|
||||
|
||||
scenario "User is verified" do
|
||||
user = create(:user, verified_at: Time.now)
|
||||
|
||||
login_as(user)
|
||||
visit verification_path
|
||||
|
||||
expect(current_path).to eq account_path
|
||||
expect(page).to have_content 'You are a verified user!'
|
||||
end
|
||||
|
||||
scenario "User requested a letter" do
|
||||
user = create(:user, confirmed_phone: "623456789", residence_verified_at: Time.now,
|
||||
letter_requested_at: Time.now, letter_verification_code: "666")
|
||||
|
||||
login_as(user)
|
||||
visit verification_path
|
||||
|
||||
expect(current_path).to eq edit_letter_path
|
||||
end
|
||||
|
||||
scenario "User is level two verified" do
|
||||
user = create(:user, residence_verified_at: Time.now, confirmed_phone: "666666666")
|
||||
|
||||
login_as(user)
|
||||
visit verification_path
|
||||
|
||||
expect(current_path).to eq new_letter_path
|
||||
end
|
||||
|
||||
scenario "User received a verification sms" do
|
||||
user = create(:user, residence_verified_at: Time.now, unconfirmed_phone: "666666666", sms_confirmation_code: "666")
|
||||
|
||||
login_as(user)
|
||||
visit verification_path
|
||||
|
||||
expect(current_path).to eq edit_sms_path
|
||||
end
|
||||
|
||||
scenario "User received verification email" do
|
||||
user = create(:user, letter_requested_at: Time.now, letter_verification_code: "666")
|
||||
|
||||
login_as(user)
|
||||
visit verification_path
|
||||
|
||||
verification_redirect = current_path
|
||||
|
||||
visit verified_user_path
|
||||
|
||||
expect(current_path).to eq verification_redirect
|
||||
end
|
||||
|
||||
scenario "User has verified residence" do
|
||||
user = create(:user, residence_verified_at: Time.now)
|
||||
|
||||
login_as(user)
|
||||
visit verification_path
|
||||
|
||||
verification_redirect = current_path
|
||||
|
||||
visit verified_user_path
|
||||
|
||||
expect(current_path).to eq verification_redirect
|
||||
end
|
||||
|
||||
scenario "User has not started verification process" do
|
||||
user = create(:user)
|
||||
|
||||
login_as(user)
|
||||
visit verification_path
|
||||
|
||||
expect(current_path).to eq new_residence_path
|
||||
end
|
||||
|
||||
scenario "A verified user can not access verification pages" do
|
||||
user = create(:user, verified_at: Time.now)
|
||||
|
||||
login_as(user)
|
||||
|
||||
verification_paths = [new_residence_path, verified_user_path, edit_sms_path, new_letter_path, edit_letter_path]
|
||||
verification_paths.each do |step_path|
|
||||
visit step_path
|
||||
|
||||
expect(current_path).to eq account_path
|
||||
expect(page).to have_content 'You are a verified user!'
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -304,6 +304,42 @@ describe User do
|
||||
user = create(:user, verified_at: Time.now, confirmed_phone: "123456789", residence_verified_at: Time.now)
|
||||
expect(user.unverified?).to eq(false)
|
||||
end
|
||||
|
||||
it "verification_email_sent? is true only if user has email_verification_token" do
|
||||
user = create(:user, email_verification_token: "xxxxxxx")
|
||||
expect(user.verification_email_sent?).to eq(true)
|
||||
|
||||
user = create(:user, email_verification_token: nil)
|
||||
expect(user.verification_email_sent?).to eq(false)
|
||||
end
|
||||
|
||||
it "verification_sms_sent? is true only if user has unconfirmed_phone and sms_confirmation_code" do
|
||||
user = create(:user, unconfirmed_phone: "666666666", sms_confirmation_code: "666")
|
||||
expect(user.verification_sms_sent?).to eq(true)
|
||||
|
||||
user = create(:user, unconfirmed_phone: nil, sms_confirmation_code: "666")
|
||||
expect(user.verification_sms_sent?).to eq(false)
|
||||
|
||||
user = create(:user, unconfirmed_phone: "666666666", sms_confirmation_code: nil)
|
||||
expect(user.verification_sms_sent?).to eq(false)
|
||||
|
||||
user = create(:user, unconfirmed_phone: nil, sms_confirmation_code: nil)
|
||||
expect(user.verification_sms_sent?).to eq(false)
|
||||
end
|
||||
|
||||
it "verification_letter_sent? is true only if user has letter_requested_at and letter_verification_code" do
|
||||
user = create(:user, letter_requested_at: Time.now, letter_verification_code: "666")
|
||||
expect(user.verification_letter_sent?).to eq(true)
|
||||
|
||||
user = create(:user, letter_requested_at: nil, letter_verification_code: "666")
|
||||
expect(user.verification_letter_sent?).to eq(false)
|
||||
|
||||
user = create(:user, letter_requested_at: Time.now, letter_verification_code: nil)
|
||||
expect(user.verification_letter_sent?).to eq(false)
|
||||
|
||||
user = create(:user, letter_requested_at: nil, letter_verification_code: nil)
|
||||
expect(user.verification_letter_sent?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe "cache" do
|
||||
|
||||
Reference in New Issue
Block a user