diff --git a/.ruby-version b/.ruby-version
index 7e541aec6..585940699 100644
--- a/.ruby-version
+++ b/.ruby-version
@@ -1 +1 @@
-2.2.2
\ No newline at end of file
+2.2.3
diff --git a/.travis.yml b/.travis.yml
index cb294ec9c..a45f36990 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,9 +2,9 @@ language: ruby
addons:
postgresql: "9.4"
rvm:
- - "2.2.2"
+ - "2.2.3"
cache: bundler
before_script:
- "for i in config/*.example; do cp \"$i\" \"${i/.example}\"; done"
- bundle exec rake db:setup
-script: bundle exec rake
\ No newline at end of file
+script: bundle exec rake
diff --git a/Gemfile b/Gemfile
index e381bc516..21929a806 100644
--- a/Gemfile
+++ b/Gemfile
@@ -40,6 +40,7 @@ gem 'social-share-button'
gem 'initialjs-rails', '0.2.0'
gem 'unicorn'
gem 'paranoia'
+gem 'savon'
gem 'ahoy_matey', '~> 1.2.1'
gem 'groupdate' # group temporary data
diff --git a/Gemfile.lock b/Gemfile.lock
index cd2ae196d..60af34f06 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -54,6 +54,9 @@ GEM
request_store
user_agent_parser
uuidtools
+ akami (1.3.1)
+ gyoku (>= 0.4.0)
+ nokogiri
arel (6.0.3)
awesome_nested_set (3.0.2)
activerecord (>= 4.0.0, < 5)
@@ -155,10 +158,14 @@ GEM
activesupport (>= 4.1.0)
groupdate (2.4.0)
activesupport (>= 3)
+ gyoku (1.3.1)
+ builder (>= 2.1.2)
hashie (3.4.2)
highline (1.7.3)
http-cookie (1.0.2)
domain_name (~> 0.5)
+ httpi (2.4.1)
+ rack
i18n (0.7.0)
i18n-tasks (0.8.7)
activesupport (>= 2.3.18)
@@ -204,6 +211,7 @@ GEM
netrc (0.10.3)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
+ nori (2.6.0)
oauth (0.4.7)
oauth2 (1.0.0)
faraday (>= 0.8, < 0.10)
@@ -305,6 +313,14 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (~> 1.1)
+ savon (2.11.1)
+ akami (~> 1.2)
+ builder (>= 2.1.2)
+ gyoku (~> 1.2)
+ httpi (~> 2.3)
+ nokogiri (>= 1.4.0)
+ nori (~> 2.4)
+ wasabi (~> 3.4)
simple_captcha2 (0.3.4)
rails (>= 4.1)
simplecov (0.10.0)
@@ -353,6 +369,9 @@ GEM
uuidtools (2.1.5)
warden (1.2.3)
rack (>= 1.0)
+ wasabi (3.5.0)
+ httpi (~> 2.0)
+ nokogiri (>= 1.4.2)
web-console (2.2.1)
activemodel (>= 4.0)
binding_of_caller (>= 0.7.2)
@@ -409,6 +428,7 @@ DEPENDENCIES
responders
rspec-rails (~> 3.0)
sass-rails (~> 5.0)
+ savon
simple_captcha2
social-share-button
spring
diff --git a/README.md b/README.md
index a3433df9d..4ca913bf2 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ Las herramientas utilizadas para el frontend no están cerradas aún. Los estilo
## Configuración para desarrollo y tests
-Prerequisitos: tener instalado git, ImageMagick, Ruby 2.2.2, la gema `bundler`, ghostscript y PostgreSQL (9.4 o superior).
+Prerequisitos: tener instalado git, ImageMagick, Ruby 2.2.3, la gema `bundler`, ghostscript y PostgreSQL (9.4 o superior).
```
cd participacion
diff --git a/README_EN.md b/README_EN.md
index a3dd63106..cc11c531c 100644
--- a/README_EN.md
+++ b/README_EN.md
@@ -21,7 +21,7 @@ Frontend tools used include [SCSS](http://sass-lang.com/) over [Foundation](http
## Configuration for development and test environments
-Prerequisites: install git, ImageMagick, Ruby 2.2.2, bundler gem, ghostscript and PostgreSQL (>=9.4).
+Prerequisites: install git, ImageMagick, Ruby 2.2.3, bundler gem, ghostscript and PostgreSQL (>=9.4).
```
cd participacion
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 6e5b1df3d..c4134468a 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -33,6 +33,7 @@ var initialize_modules = function() {
App.Stats.initialize();
App.LocaleSwitcher.initialize();
App.DebatesOrderSelector.initialize();
+ App.DebatesTagFilter.initialize();
};
$(function(){
diff --git a/app/assets/javascripts/debates_tag_filter.js.coffee b/app/assets/javascripts/debates_tag_filter.js.coffee
new file mode 100644
index 000000000..08b8c7712
--- /dev/null
+++ b/app/assets/javascripts/debates_tag_filter.js.coffee
@@ -0,0 +1,17 @@
+App.DebatesTagFilter =
+
+ href_with_params: (query_params) ->
+ loc = window.location
+
+ loc.protocol + "//" + loc.hostname +
+ (if loc.port then ':' + loc.port else '') +
+ loc.pathname +
+ loc.hash +
+ '?' + $.param(query_params)
+
+ initialize: ->
+ $('.js-tag-filter').on 'change', ->
+ query_params = window.getQueryParameters()
+ query_params['tag'] = $(this).val()
+ window.location.assign(App.DebatesTagFilter.href_with_params(query_params))
+
diff --git a/app/assets/stylesheets/debates.scss b/app/assets/stylesheets/debates.scss
index c2355d95b..f928c457c 100644
--- a/app/assets/stylesheets/debates.scss
+++ b/app/assets/stylesheets/debates.scss
@@ -596,6 +596,8 @@
padding: rem-calc(6) rem-calc(12);
}
+
+
&.is-admin {
background: $comment-admin;
padding: rem-calc(6) rem-calc(12);
@@ -607,6 +609,12 @@
}
}
+ .is-deleted {
+ background: $deleted;
+ margin-left: rem-calc(42);
+ padding: rem-calc(6) rem-calc(12);
+ }
+
.comment-children {
border-left: 1px dashed $border;
margin-left: rem-calc(42);
diff --git a/app/assets/stylesheets/participacion.scss b/app/assets/stylesheets/participacion.scss
index 1ec402781..88a8a412b 100644
--- a/app/assets/stylesheets/participacion.scss
+++ b/app/assets/stylesheets/participacion.scss
@@ -639,7 +639,7 @@ form.locale-form {
position: relative;
select {
- background-image: url("language_select.png");
+ background-image: image-url("language_select.png");
&.js-locale-switcher {
background-color: transparent;
@@ -880,6 +880,10 @@ img.initialjs-avatar {
background: $association;
}
+.is-deleted {
+ background: $deleted;
+}
+
.level-1 {
background: $level-1;
}
diff --git a/app/assets/stylesheets/variables.scss b/app/assets/stylesheets/variables.scss
index 6240702d2..1954de5bd 100644
--- a/app/assets/stylesheets/variables.scss
+++ b/app/assets/stylesheets/variables.scss
@@ -76,6 +76,7 @@ $level-5: #F08A24;
$author: #008CCF;
$association: #C0392B;
+$deleted: #E7E7E7;
$comment-author: rgba(45,144,248,.15);
$comment-level-5: rgba(255,241,204,1);
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 802dda3bc..9df8c4874 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,6 +1,7 @@
require "application_responder"
class ApplicationController < ActionController::Base
+ before_filter :authenticate
check_authorization unless: :devise_controller?
include SimpleCaptcha::ControllerHelpers
self.responder = ApplicationResponder
@@ -15,6 +16,14 @@ class ApplicationController < ActionController::Base
before_action :ensure_signup_complete
+ def authenticate
+ if Rails.env.staging? || Rails.env.production?
+ authenticate_or_request_with_http_basic do |username, password|
+ username == Rails.application.secrets.username && password == Rails.application.secrets.password
+ end
+ end
+ end
+
rescue_from CanCan::AccessDenied do |exception|
redirect_to main_app.root_url, alert: exception.message
end
@@ -51,4 +60,10 @@ class ApplicationController < ActionController::Base
redirect_to finish_signup_path
end
end
+
+ def verify_resident!
+ unless current_user.residence_verified?
+ redirect_to new_residence_path, alert: t('verification.residence.alert.unconfirmed_residency')
+ end
+ end
end
diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb
index 60819fcf6..084bfc1f0 100644
--- a/app/controllers/debates_controller.rb
+++ b/app/controllers/debates_controller.rb
@@ -1,5 +1,5 @@
class DebatesController < ApplicationController
- before_action :parse_order, only: :index
+ before_action :parse_order, :parse_tag_filter, only: :index
before_action :authenticate_user!, except: [:index, :show]
load_and_authorize_resource
@@ -77,4 +77,9 @@ class DebatesController < ApplicationController
@order = @valid_orders.include?(params[:order]) ? params[:order] : 'created_at'
end
+ def parse_tag_filter
+ valid_tags = ActsAsTaggableOn::Tag.all.map(&:name)
+ @tag_filter = params[:tag] if valid_tags.include?(params[:tag])
+ end
+
end
diff --git a/app/controllers/verification/email_controller.rb b/app/controllers/verification/email_controller.rb
new file mode 100644
index 000000000..ebcbf68ab
--- /dev/null
+++ b/app/controllers/verification/email_controller.rb
@@ -0,0 +1,31 @@
+class Verification::EmailController < ApplicationController
+ before_action :authenticate_user!
+ before_action :set_verified_user
+ skip_authorization_check
+
+ def show
+ if Email.find(current_user, params[:email_verification_token])
+ current_user.update(verified_at: Time.now)
+ redirect_to account_path, notice: t('verification.email.show.flash.success')
+ else
+ redirect_to verified_user_path, alert: t('verification.email.show.alert.failure')
+ end
+ end
+
+ def create
+ @email = Email.new(@verified_user)
+ if @email.save
+ current_user.reload
+ Mailer.email_verification(current_user, @email.recipient, @email.encrypted_token).deliver_now
+ redirect_to account_path, notice: t('verification.email.create.flash.success', email: @verified_user.email)
+ else
+ redirect_to verified_user_path, alert: t('verification.email.create.alert.failure')
+ end
+ end
+
+ private
+
+ def set_verified_user
+ @verified_user = VerifiedUser.by_user(current_user).by_email(params[:recipient]).first
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/verification/letter_controller.rb b/app/controllers/verification/letter_controller.rb
new file mode 100644
index 000000000..eb91ebe6f
--- /dev/null
+++ b/app/controllers/verification/letter_controller.rb
@@ -0,0 +1,32 @@
+class Verification::LetterController < ApplicationController
+ before_action :authenticate_user!
+ before_action :verify_resident!
+ before_action :verify_phone_or_email!
+ skip_authorization_check
+
+ def new
+ @letter = Letter.new(user: current_user)
+ end
+
+ def create
+ @letter = Letter.new(user: current_user)
+ if @letter.save
+ redirect_to account_path, notice: t('verification.letter.create.flash.success')
+ else
+ flash.now.alert = t('verification.letter.create.alert.failure')
+ render :new
+ end
+ end
+
+ private
+
+ def letter_params
+ params.require(:letter).permit()
+ end
+
+ def verify_phone_or_email!
+ unless current_user.confirmed_phone?
+ redirect_to verified_user_path, alert: t('verification.letter.alert.unconfirmed_personal_data')
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/verification/residence_controller.rb b/app/controllers/verification/residence_controller.rb
new file mode 100644
index 000000000..107e0a1e0
--- /dev/null
+++ b/app/controllers/verification/residence_controller.rb
@@ -0,0 +1,31 @@
+class Verification::ResidenceController < ApplicationController
+ before_action :authenticate_user!
+ before_action :verify_attemps_left!, only: [:new, :create]
+ skip_authorization_check
+
+ def new
+ @residence = Residence.new
+ end
+
+ def create
+ @residence = Residence.new(residence_params.merge(user: current_user))
+ if @residence.save
+ redirect_to verified_user_path, notice: t('verification.residence.create.flash.success')
+ else
+ current_user.update(residence_verification_tries: current_user.residence_verification_tries += 1)
+ render :new
+ end
+ end
+
+ private
+
+ def residence_params
+ params.require(:residence).permit(:document_number, :document_type, :date_of_birth, :postal_code)
+ end
+
+ def verify_attemps_left!
+ if current_user.residence_verification_tries >= 5
+ redirect_to account_path, alert: t('verification.residence.alert.verify_attemps_left')
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/verification/sms_controller.rb b/app/controllers/verification/sms_controller.rb
new file mode 100644
index 000000000..e0080753e
--- /dev/null
+++ b/app/controllers/verification/sms_controller.rb
@@ -0,0 +1,62 @@
+class Verification::SmsController < ApplicationController
+ before_action :authenticate_user!
+ before_action :verify_resident!
+ before_action :verify_attemps_left!, only: [:new, :create]
+
+ skip_authorization_check
+
+ def new
+ @sms = Sms.new(phone: params[:phone])
+ end
+
+ def create
+ @sms = Sms.new(sms_params.merge(user: current_user))
+ if @sms.save
+ redirect_to edit_sms_path, notice: t('verification.sms.create.flash.success')
+ else
+ render :new
+ end
+ end
+
+ def edit
+ @sms = Sms.new
+ end
+
+ def update
+ @sms = Sms.new(sms_params.merge(user: current_user))
+ if @sms.verify?
+ current_user.update(confirmed_phone: current_user.unconfirmed_phone)
+
+ if VerifiedUser.phone?(current_user)
+ current_user.update(verified_at: Time.now)
+ end
+
+ redirect_to_next_path
+ else
+ @error = t('verification.sms.update.error')
+ render :edit
+ end
+ end
+
+ private
+
+ def sms_params
+ params.require(:sms).permit(:phone, :confirmation_code)
+ end
+
+ def redirect_to_next_path
+ current_user.reload
+ if current_user.level_three_verified?
+ redirect_to account_path, notice: t('verification.sms.update.flash.level_three.success')
+ else
+ redirect_to new_letter_path, notice: t('verification.sms.update.flash.level_two.success')
+ end
+ end
+
+ def verify_attemps_left!
+ if current_user.sms_confirmation_tries >= 3
+ redirect_to account_path, notice: t('verification.sms.alert.verify_attemps_left')
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/app/controllers/verification/verified_user_controller.rb b/app/controllers/verification/verified_user_controller.rb
new file mode 100644
index 000000000..bf2bc65fb
--- /dev/null
+++ b/app/controllers/verification/verified_user_controller.rb
@@ -0,0 +1,9 @@
+class Verification::VerifiedUserController < ApplicationController
+ before_action :authenticate_user!
+ skip_authorization_check
+
+ def show
+ @verified_users = VerifiedUser.by_user(current_user)
+ redirect_to new_sms_path if @verified_users.blank?
+ end
+end
\ No newline at end of file
diff --git a/app/helpers/verification_helper.rb b/app/helpers/verification_helper.rb
new file mode 100644
index 000000000..a7615801e
--- /dev/null
+++ b/app/helpers/verification_helper.rb
@@ -0,0 +1,9 @@
+module VerificationHelper
+
+ def document_types
+ [[t('verification.residence.new.document_type.spanish_id'), 1],
+ [t('verification.residence.new.document_type.passport'), 2],
+ [t('verification.residence.new.document_type.residence_card'), 3]]
+ end
+
+end
\ No newline at end of file
diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb
index 04160022e..a3db690a8 100644
--- a/app/mailers/mailer.rb
+++ b/app/mailers/mailer.rb
@@ -14,4 +14,11 @@ class Mailer < ApplicationMailer
mail(to: @recipient.email, subject: t('mailer.reply.subject'))
end
+ def email_verification(user, recipient, token)
+ @user = user
+ @recipient = recipient
+ @token = token
+ mail(to: @recipient, subject: "Verifica tu email")
+ end
+
end
diff --git a/app/models/address.rb b/app/models/address.rb
new file mode 100644
index 000000000..2c0c20b88
--- /dev/null
+++ b/app/models/address.rb
@@ -0,0 +1,3 @@
+class Address < ActiveRecord::Base
+ belongs_to :user
+end
diff --git a/app/models/comment.rb b/app/models/comment.rb
index fa5f72164..c23c5c993 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -61,10 +61,6 @@ class Comment < ActiveRecord::Base
cached_votes_down
end
- def not_visible?
- hidden? || user.hidden?
- end
-
def ignored_flag?
ignored_flag_at.present?
end
diff --git a/app/models/email.rb b/app/models/email.rb
new file mode 100644
index 000000000..e5e15c49f
--- /dev/null
+++ b/app/models/email.rb
@@ -0,0 +1,34 @@
+class Email
+ include ActiveModel::Model
+
+ attr_accessor :verified_user, :recipient, :plain_token, :encrypted_token
+
+ validates :verified_user, presence: true
+ validates :recipient, presence: true
+
+ def initialize(verified_user)
+ @verified_user = verified_user
+ @recipient = @verified_user.try(:email)
+ end
+
+ def save
+ return false unless valid?
+
+ generate_token
+ user = User.where(document_number: verified_user.document_number).first
+ user.update(email_verification_token: @plain_token)
+ end
+
+ def generate_token
+ @plain_token, @encrypted_token = Devise.token_generator.generate(User, :email_verification_token)
+ end
+
+ def self.find(user, token)
+ self.valid_token?(user, token)
+ end
+
+ def self.valid_token?(user, token)
+ Devise.token_generator.digest(User, :email_verification_token, user.email_verification_token) == token
+ end
+
+end
diff --git a/app/models/letter.rb b/app/models/letter.rb
new file mode 100644
index 000000000..75b5a5437
--- /dev/null
+++ b/app/models/letter.rb
@@ -0,0 +1,53 @@
+class Letter
+ include ActiveModel::Model
+
+ attr_accessor :user, :address
+
+ validates :user, presence: true
+ validates :address, presence: true
+ validate :correct_address
+
+ def initialize(attrs={})
+ @user = attrs[:user]
+ end
+
+ def save
+ valid? &&
+ letter_requested! &&
+ update_user_address
+ end
+
+ def address
+ @address ||= CensusApi.new(user).address
+ end
+
+ def letter_requested!
+ user.update(letter_requested_at: Time.now)
+ end
+
+ def update_user_address
+ user.address = Address.new(parsed_address)
+ user.save
+ end
+
+ def correct_address
+ errors.add(:address, "Address not found") unless address.present?
+ end
+
+ def parsed_address
+ { postal_code: address[:codigo_postal],
+ street: address[:nombre_via],
+ street_type: address[:sigla_via],
+ number: address[:numero_via],
+ number_type: address[:nominal_via],
+ letter: address[:letra_via],
+ portal: address[:portal],
+ stairway: address[:escalera],
+ floor: address[:planta],
+ door: address[:puerta],
+ km: address[:km],
+ neighbourhood: address[:nombre_barrio],
+ district: address[:nombre_distrito] }
+ end
+
+end
diff --git a/app/models/organization.rb b/app/models/organization.rb
index de120de9e..20c74d31c 100644
--- a/app/models/organization.rb
+++ b/app/models/organization.rb
@@ -6,9 +6,9 @@ class Organization < ActiveRecord::Base
delegate :email, :phone_number, to: :user
- scope :pending, -> { where(verified_at: nil, rejected_at: nil) }
- scope :verified, -> { where("verified_at is not null and (rejected_at is null or rejected_at < verified_at)") }
- scope :rejected, -> { where("rejected_at is not null and (verified_at is null or verified_at < rejected_at)") }
+ scope :pending, -> { where('organizations.verified_at is null and rejected_at is null') }
+ scope :verified, -> { where("organizations.verified_at is not null and (rejected_at is null or rejected_at < organizations.verified_at)") }
+ scope :rejected, -> { where("rejected_at is not null and (organizations.verified_at is null or organizations.verified_at < rejected_at)") }
def verify
update(verified_at: Time.now)
diff --git a/app/models/residence.rb b/app/models/residence.rb
new file mode 100644
index 000000000..511f1cb0c
--- /dev/null
+++ b/app/models/residence.rb
@@ -0,0 +1,45 @@
+class Residence
+ include ActiveModel::Model
+ include ActiveModel::Dates
+
+ attr_accessor :user, :document_number, :document_type, :date_of_birth, :postal_code
+
+ validates_presence_of :document_number
+ validates_presence_of :document_type
+ validates_presence_of :date_of_birth
+ validates_presence_of :postal_code
+
+ validates :postal_code, length: { is: 5 }
+
+ validate :residence_in_madrid
+ validate :document_number_uniqueness
+
+ def initialize(attrs={})
+ self.date_of_birth = parse_date('date_of_birth', attrs)
+ attrs = remove_date('date_of_birth', attrs)
+ super
+ end
+
+ def save
+ return false unless valid?
+ user.update(document_number: document_number,
+ document_type: document_type,
+ residence_verified_at: Time.now)
+ end
+
+ def document_number_uniqueness
+ errors.add(:document_number, "Already in use") if User.where(document_number: document_number).any?
+ end
+
+ def residence_in_madrid
+ return if errors.any?
+
+ self.date_of_birth = date_to_string(date_of_birth)
+
+ residency = CensusApi.new(self)
+ errors.add(:residence_in_madrid, false) unless residency.valid?
+
+ self.date_of_birth = string_to_date(date_of_birth)
+ end
+
+end
diff --git a/app/models/sms.rb b/app/models/sms.rb
new file mode 100644
index 000000000..61b06a091
--- /dev/null
+++ b/app/models/sms.rb
@@ -0,0 +1,47 @@
+class Sms
+ include ActiveModel::Model
+
+ attr_accessor :user, :phone, :confirmation_code
+
+ validates_presence_of :phone
+ validates :phone, length: { is: 9 }
+ validate :spanish_phone
+ validate :uniqness_phone
+
+ def spanish_phone
+ errors.add(:phone, :invalid) unless phone.start_with?('6', '7')
+ end
+
+ def uniqness_phone
+ errors.add(:phone, :taken) if User.where(confirmed_phone: phone).any?
+ end
+
+ def save
+ return false unless self.valid?
+ update_user_phone_information
+ send_sms
+ increase_sms_tries
+ end
+
+ def update_user_phone_information
+ user.update(unconfirmed_phone: phone, sms_confirmation_code: four_digit_code)
+ end
+
+ def send_sms
+ SMSApi.new.sms_deliver(user.unconfirmed_phone, user.sms_confirmation_code)
+ end
+
+ def increase_sms_tries
+ user.update(sms_confirmation_tries: user.sms_confirmation_tries += 1)
+ end
+
+ def verify?
+ user.sms_confirmation_code == confirmation_code
+ end
+
+ private
+
+ def four_digit_code
+ rand.to_s[2..5]
+ end
+end
\ No newline at end of file
diff --git a/app/models/user.rb b/app/models/user.rb
index 6941e6d17..d415d7fcd 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,4 +1,5 @@
class User < ActiveRecord::Base
+ include Verification
OMNIAUTH_EMAIL_PREFIX = 'omniauth@participacion'
OMNIAUTH_EMAIL_REGEX = /\A#{OMNIAUTH_EMAIL_PREFIX}/
@@ -11,6 +12,7 @@ class User < ActiveRecord::Base
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
+ has_one :address
has_one :administrator
has_one :moderator
has_one :organization
diff --git a/app/models/verified_user.rb b/app/models/verified_user.rb
new file mode 100644
index 000000000..ca32eea5c
--- /dev/null
+++ b/app/models/verified_user.rb
@@ -0,0 +1,12 @@
+# make sure document_type is being stored and queried in the correct format (Is it DNI? a number, a string?)
+class VerifiedUser < ActiveRecord::Base
+ scope :by_user, -> (user) { where(document_number: user.document_number,
+ document_type: user.document_type) }
+
+ scope :by_email, -> (email) { where(email: email) }
+ scope :by_phone, -> (phone) { where(phone: phone) }
+
+ def self.phone?(user)
+ by_user(user).by_phone(user.unconfirmed_phone).first.present?
+ end
+end
diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb
index fa9ccdd04..ad118d118 100644
--- a/app/views/account/show.html.erb
+++ b/app/views/account/show.html.erb
@@ -2,6 +2,16 @@
<%= link_to t("account.show.change_credentials_link"), edit_user_registration_path, class: 'button radius small secondary right' %>
+
+ <% if current_user.level_three_verified? %>
+ <%= t("account.show.level_three_user") %>
+ <% elsif current_user.level_two_verified? %>
+ <%= t("account.show.level_two_user") %>
+ <% else %>
+ <%= link_to t("account.show.verify_my_account"), new_residence_path, class: 'button radius small secondary right' %>
+ <% end %>
+
+
<%= t("account.show.title") %>
<%= form_for @account, as: :account, url: account_path do |f| %>
diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb
index 5ffff4a85..e21b148bc 100644
--- a/app/views/comments/_comment.html.erb
+++ b/app/views/comments/_comment.html.erb
@@ -1,16 +1,18 @@
diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb
index b73023c7a..71735eaaa 100644
--- a/app/views/comments/_form.html.erb
+++ b/app/views/comments/_form.html.erb
@@ -1,6 +1,7 @@
<%= t("debates.comment.deleted") %>
+