Skip to content

Commit

Permalink
Merge pull request #55 from AyuntamientoPuertoReal/DEV
Browse files Browse the repository at this point in the history
Update Version 9 de octubre Apr-ireina
  • Loading branch information
IvanReinaGalvez committed Oct 5, 2017
2 parents 394ba70 + 667d322 commit 4fbfa2c
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 5 deletions.
58 changes: 58 additions & 0 deletions app/controllers/custom/verification/letter_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
class Verification::LetterController < ApplicationController
before_action :authenticate_user!, except: [:edit, :update]
before_action :login_via_form, only: :update

before_action :verify_resident!, if: :signed_in?
before_action :verify_verified!, if: :signed_in?
before_action :verify_lock, if: :signed_in?

skip_authorization_check

def new
@letter = Verification::Letter.new(user: current_user)
end

def create
@letter = Verification::Letter.new(user: current_user)
@letter.save
redirect_to letter_path
end

def show
end

def edit
@letter = Verification::Letter.new
end

def update
@letter = Verification::Letter.new(letter_params.merge(user: current_user, verify: true))
if @letter.valid?
current_user.update(verified_at: Time.current)
redirect_to account_path, notice: t('verification.letter.update.flash.success')
else
Lock.increase_tries(@letter.user) if @letter.user
render :edit
end
end

private

def letter_params
params.require(:verification_letter).permit(:verification_code, :email, :password)
end

def verify_phone!
unless current_user.sms_verified?
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]
if user && user.valid_password?(letter_params[:password])
sign_in(user)
end
end

end
24 changes: 24 additions & 0 deletions app/controllers/custom/verification/verified_user_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Verification::VerifiedUserController < ApplicationController
before_action :authenticate_user!
before_action :verify_verified!
skip_authorization_check

def show
@verified_users = VerifiedUser.by_user(current_user)
redirect_to account_path unless user_data_present?
end

private

def user_data_present?
return false if @verified_users.blank?

data = false
@verified_users.each do |vu|
data = true if vu.phone.present? || vu.email.present?
end

data
end

end
27 changes: 27 additions & 0 deletions app/controllers/custom/verification_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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.organization?
{ path: account_path }
elsif user.level_three_verified?
{ path: account_path, notice: t('verification.redirect_notices.already_verified') }
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
6 changes: 3 additions & 3 deletions app/models/concerns/verification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def residence_verified?
end

def sms_verified?
confirmed_phone.present?
true
end

def level_two_verified?
level_two_verified_at.present? || (residence_verified? && sms_verified?)
level_two_verified_at.present? || residence_verified?
end

def level_three_verified?
verified_at.present?
level_two_verified?
end

def level_two_or_three_verified?
Expand Down
3 changes: 1 addition & 2 deletions app/models/custom/verification/residence.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

require_dependency Rails.root.join('app', 'models', 'verification', 'residence').to_s

class Verification::Residence
Expand All @@ -23,7 +22,7 @@ def residence_in_madrid
private

def valid_postal_code?
postal_code =~ /^280/
postal_code =~ /^1151/
end

end
173 changes: 173 additions & 0 deletions app/views/custom/account/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<div class="row account">
<div class="small-12 column">
<div class="float-right text-right">
<%= link_to t("account.show.change_credentials_link"), edit_user_registration_path, class: "button hollow" %>
<br>
<%= link_to t("account.show.erase_account_link"), users_registrations_delete_form_path, class: "delete" %>
</div>

<%= avatar_image(@account, seed: @account.id, size: 100, class: "margin-bottom") %>

<h1 class="inline-block"><%= t("account.show.title") %></h1>

<%= form_for @account, as: :account, url: account_path do |f| %>
<%= render "shared/errors", resource: @account %>

<div class="row">
<div class="small-12 medium-6 column">

<h2><%= t("account.show.personal")%></h2>

<div class="small-12 medium-10">
<% if @account.organization? %>
<%= f.fields_for :organization do |fo| %>
<%= fo.text_field :name, autofocus: true, maxlength: Organization.name_max_length, placeholder: t("account.show.organization_name_label") %>
<%= fo.text_field :responsible_name, autofocus: true, maxlength: Organization.responsible_name_max_length, placeholder: t("account.show.organization_responsible_name_placeholder") %>
<% end %>
<%= f.text_field :phone_number, placeholder: t("account.show.phone_number_label") %>
<% else %>
<%= f.text_field :username, maxlength: User.username_max_length, placeholder: t("account.show.username_label") %>
<% end %>
</div>

<div>
<%= f.label :public_activity do %>
<%= f.check_box :public_activity, title: t('account.show.public_activity_label'), label: false %>
<span class="checkbox">
<%= t("account.show.public_activity_label") %>
</span>
<% end %>
</div>

<div>
<%= f.label :public_interests do %>
<%= f.check_box :public_interests, title: t('account.show.public_interests_label'), label: false %>
<span class="checkbox">
<%= t("account.show.public_interests_label") %>
</span>
<% end %>
</div>


<% if @account.email.present? %>
<h2><%= t("account.show.notifications")%></h2>

<div>
<%= f.label :email_on_comment do %>
<%= f.check_box :email_on_comment, title: t('account.show.email_on_comment_label'), label: false %>
<span class="checkbox">
<%= t("account.show.email_on_comment_label") %>
</span>
<% end %>
</div>

<div>
<%= f.label :email_on_comment_reply do %>
<%= f.check_box :email_on_comment_reply, title: t('account.show.email_on_comment_reply_label'), label: false %>
<span class="checkbox">
<%= t("account.show.email_on_comment_reply_label") %>
</span>
<% end %>
</div>

<div>
<%= f.label :email_newsletter_subscribed do %>
<%= f.check_box :newsletter, title: t('account.show.subscription_to_website_newsletter_label'), label: false %>
<span class="checkbox">
<%= t("account.show.subscription_to_website_newsletter_label") %>
</span>
<% end %>
</div>

<div>
<%= f.label :email_digest do %>
<%= f.check_box :email_digest, title: t('account.show.email_digest_label'), label: false %>
<span class="checkbox">
<%= t("account.show.email_digest_label") %>
</span>
<% end %>
</div>

<div>
<%= f.label :email_on_direct_message do %>
<%= f.check_box :email_on_direct_message, title: t('account.show.email_on_direct_message_label'), label: false %>
<span class="checkbox">
<%= t("account.show.email_on_direct_message_label") %>
</span>
<% end %>
</div>
<% end %>
<% if @account.official_level == 1 %>
<div>
<%= f.label :official_position_badge do %>
<%= f.check_box :official_position_badge,
title: t('account.show.official_position_badge_label'),
label: false %>
<span class="checkbox">
<%= t("account.show.official_position_badge_label") %>
</span>
<% end %>
</div>
<% end %>
<%= f.submit t("account.show.save_changes_submit"), class: "button" %>
</div>

<div class="user-permissions small-12 medium-6 column">
<h2><%= t("account.show.user_permission_title") %></h2>

<p><%= t("account.show.user_permission_info") %></p>

<ul>
<li><span class="icon-check"></span>&nbsp;<%= t("account.show.user_permission_debates") %></li>
<li><span class="icon-check"></span>&nbsp;<%= t("account.show.user_permission_proposal") %></li>
<li>
<% if current_user.level_two_or_three_verified? %>
<span class="icon-check"></span>
<% else %>
<span class="icon-x"></span>
<% end %>
<%= t("account.show.user_permission_support_proposal") %>
</li>
<li>
<% if current_user.level_three_verified? %>
<span class="icon-check"></span>
<% else %>
<span class="icon-x"></span>
<% end %>
<%= t("account.show.user_permission_votes") %>
</li>
</ul>

<p>
<span><%= t("account.show.user_permission_verify_info") %></span>
<br>
<% unless current_user.level_three_verified? %>
<%= t("account.show.user_permission_verify") %>
<% end %>
</p>

<% unless @account.organization? %>
<div>
<span class="verify-account">
<% if current_user.level_three_verified? %>
<p class="already-verified">
<span class="icon-check"></span>
<%= t("account.show.verified_account") %>
</p>
<% elsif current_user.level_two_verified? %>
<%= link_to t("account.show.finish_verification"), verification_path, class: "button success" %>
<% else %>
<%= link_to t("account.show.verify_my_account"), verification_path, class: "button success" %>
<% end %>
</span>
</div>
<% end %>
</div>
</div>
<% end %>

</div>
</div>
6 changes: 6 additions & 0 deletions lib/custom/census_caller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class CensusCaller

def call(document_type, document_number)
LocalCensus.new.call(document_type, document_number)
end
end

0 comments on commit 4fbfa2c

Please sign in to comment.