Skip to content
This repository has been archived by the owner on Mar 27, 2022. It is now read-only.

Commit

Permalink
Fix remaining issues with verification.
Browse files Browse the repository at this point in the history
  • Loading branch information
seven1m committed Mar 28, 2014
1 parent 314e666 commit 8c610c6
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 79 deletions.
25 changes: 12 additions & 13 deletions app/controllers/accounts_controller.rb
Expand Up @@ -12,20 +12,17 @@ def show
end

def new
# TODO pass in verification
@verification ||= Verification.new
if params[:email]
@verification = Verification.new
render action: 'new_by_email'
elsif params[:phone]
@verification = Verification.new
render action: 'new_by_mobile'
elsif params[:birthday]
@verification = Verification.new
render action: 'new_by_birthday'
elsif Setting.get(:features, :sign_up)
@signup = Signup.new
render action: 'new'
else
render action: 'new'
end
# render template 'new' by default
end

def create
Expand All @@ -44,12 +41,14 @@ def create
params.permit! # FIXME
@verification = Verification.new(params[:verification])
if @verification.save
# TODO appropriate message for type of verification
render text: t('accounts.verification_email_sent'), layout: true
#render text: t('accounts.verification_message_sent'), layout: true
#render text: t('accounts.submission_will_be_reviewed'), layout: true
if params[:phone]
flash[:notice] = t('accounts.verification_message_sent')
render action: 'verify_code'
else
render text: t('accounts.verification_email_sent'), layout: true
end
else
render action: 'new_by_email'
new
end
else
@signup = Signup.new
Expand All @@ -76,7 +75,7 @@ def verify_code
redirect_to edit_person_account_path(person)
end
else
render text: t('accounts.wrong_code'), layout: true, status: :bad_request
render text: t('accounts.wrong_code_html'), layout: true, status: :bad_request
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/verification.rb
Expand Up @@ -34,7 +34,7 @@ def validate_people_can_sign_in

def criteria
if mobile_phone
{mobile_phone: mobile_phone}
{mobile_phone: mobile_phone.scan(/\d/).join}
elsif email
{email: email}
end
Expand Down Expand Up @@ -62,7 +62,7 @@ def email

def mobile_gateway_email
if gateway = MOBILE_GATEWAYS[carrier]
gateway % mobile_phone
gateway % mobile_phone.scan(/\d/).join
end
end

Expand Down
5 changes: 0 additions & 5 deletions app/views/accounts/_how_to_verify.erb
Expand Up @@ -13,11 +13,6 @@
<li>
<%= link_to t('accounts.verify_by_phone'), new_account_path(phone: true) %><br/>
<%= t('accounts.verify_by_phone_message') %>
<span style="color:#f00;"><%= t('accounts.text_messaging_fees') %></span>
</li>
<li>
<%= link_to t('accounts.verify_by_birthday'), new_account_path(birthday: true) %><br/>
<%= t('accounts.verify_by_birthday_message') %>
</li>
<li>
<%= t('accounts.call_office', office_phone: Setting.get(:contact, :community_office_phone)) %>
Expand Down
18 changes: 0 additions & 18 deletions app/views/accounts/new_by_birthday.html.erb

This file was deleted.

5 changes: 3 additions & 2 deletions app/views/accounts/new_by_email.html.erb
Expand Up @@ -3,10 +3,11 @@
<%= t('accounts.enter_your_email') %>
</p>
<%= form_tag account_path, method: 'post' do %>
<%= hidden_field_tag :email, true %>
<%= error_messages_for(@verification) %>
<p>
<label for="email"><%= t('accounts.type_your_email') %>:</label>
<%= text_field_tag :email, params[:email] == 'true' ? '' : params[:email] %>
<label for="verification_email"><%= t('accounts.type_your_email') %>:</label>
<%= text_field_tag 'verification[email]', params[:email] == 'true' ? '' : params[:email] %>
</p>
<p><%= submit_tag t('accounts.verify_email') %></p>
<% end %>
Expand Down
11 changes: 6 additions & 5 deletions app/views/accounts/new_by_mobile.html.erb
Expand Up @@ -2,13 +2,14 @@
<p>
<%= t('accounts.verify_by_phone_description_html') %>
</p>
<%= form_tag account_path, method: 'post', onsubmit: "return confirm('" + t('accounts.your_carrier_will_charge') + "')" do %>
<%= form_tag account_path, method: 'post' do %>
<%= hidden_field_tag :phone, true %>
<%= error_messages_for(@verification) %>
<p>
<label for="phone"><%= t('accounts.type_your_mobile') %>:</label>
<%= text_field_tag :phone, params[:phone] == 'true' ? '' : params[:phone] %><br/>
<label for="carrier"><%= t('accounts.select_your_carrier') %>:</label>
<select id="carrier" name="carrier">
<label for="verification_mobile_phone"><%= t('accounts.type_your_mobile') %>:</label>
<%= text_field_tag 'verification[mobile_phone]', params[:phone] == 'true' ? '' : params[:phone] %><br/>
<label for="verification_carrier"><%= t('accounts.select_your_carrier') %>:</label>
<select id="verification_carrier" name="verification[carrier]">
<option value=""></option>
<%= options_for_select MOBILE_GATEWAYS.keys, params[:carrier] %>
</select>
Expand Down
8 changes: 4 additions & 4 deletions app/views/accounts/verify_code.html.erb
@@ -1,10 +1,10 @@
<p>
<%= t('accounts.code_be_careful') %>
<%= t('accounts.verify_code_intro') %>
</p>

<form method="post">
<%= hidden_field_tag :id, params[:id] %>
<%= form_tag verify_code_account_path do %>
<%= hidden_field_tag :id, @verification.id %>
<p><label for="code"><%= t('accounts.enter_code') %>:</label>
<%= text_field_tag :code, params[:code] %></p>
<p><%= submit_tag t('accounts.check_code') %></p>
</form>
<% end %>
6 changes: 3 additions & 3 deletions config/locales/en.yml
Expand Up @@ -768,7 +768,6 @@ en:
cannot_edit: You cannot edit this account.
change_email_warning: After this change, all email from this site will be sent to this address. It will also be the address %{person} to sign into this site.
check_code: Check Code
code_be_careful: Please be careful to enter the correct code. If you make a mistake, you will have to start over.
create: Create Account
date_format: MM/DD/YYYY
description: Description
Expand Down Expand Up @@ -800,16 +799,17 @@ en:
verification_max_attempts_reached: You have exceeded the daily limit for verification attempts.
verify: Verify Account
verify_email: Verify Email
verify_code_intro: Please enter the code you received on your mobile phone.
verify_by_email: Verify by email.
verify_by_email_message: We send you an email, you click the link inside, and you're done. Use this to reset your password.
verify_by_phone: Verify by mobile phone.
verify_by_phone_description_html: Enter your mobile phone number, select your carrier, then click the button below. If we have the number on file, a text message will be sent to it allowing you to verify yourself and gain access to this site. <strong>Text messaging rates may be charged by your carrier. <span class="very-strong">Do not start this verification process until you know what you will be charged to receive a text message!</span></strong>
verify_by_phone_description_html: Enter your mobile phone number, select your carrier, then click the button below. If we have the number on file, a text message will be sent to it allowing you to verify yourself and gain access to this site. <strong>Text messaging fees may apply.</strong>
verify_by_phone_message: We send you a text message, you type the code it contains, and you're done.
verify_by_birthday: Verify by birthday.
verify_by_birthday_message: These submissions are reviewed by a real person and may take a few days to be approved.
verify_mobile: Verify Mobile
verify_who_you_are: First, we need to verify you are who you say you are. Please choose one of the following options to verify your identity. You only have to do this once, and it only takes a few minutes.
wrong_code: You entered the wrong code.
wrong_code_html: You entered the wrong code. <a href="/account/new?phone=true">Try again.</a>
you_use: you use
your_birthday: Birthday with Year (required)
your_carrier_will_charge: Your mobile carrier may and probably will charge you to receive this text message. Click OK to continue.
Expand Down
1 change: 0 additions & 1 deletion config/routes.rb
Expand Up @@ -4,7 +4,6 @@

resource :account do
member do
get :verify_code
post :verify_code
get :select
post :select
Expand Down
29 changes: 3 additions & 26 deletions test/functional/accounts_controller_test.rb
Expand Up @@ -63,16 +63,6 @@ def setup
assert_template :new_by_mobile
end
end

context 'by birthday' do
setup do
get :new, {birthday: 'true'}
end

should 'render new_by_birthday template' do
assert_template :new_by_birthday
end
end
end

context 'sign up feature enabled' do
Expand Down Expand Up @@ -256,7 +246,7 @@ def setup
context 'verify email' do
context 'non-existent email' do
setup do
post :create, verification: {email: 'rick@example.com'}
post :create, verification: {email: 'rick@example.com'}, email: true
end

should 'indicate record not found' do
Expand Down Expand Up @@ -297,10 +287,11 @@ def setup
context 'verify mobile phone' do
context 'non-existent mobile phone' do
setup do
post :create, verification: {mobile_phone: '1234567899', carrier: 'AT&T'}
post :create, verification: {mobile_phone: '1234567899', carrier: 'AT&T'}, phone: true
end

should 'indicate record not found' do
assert_template 'new_by_mobile'
assert_select 'body', /mobile number could not be found in our system/i
end
end
Expand Down Expand Up @@ -335,20 +326,6 @@ def setup
end
end
end

#context 'verify birthday' do
#setup do
#post :create, verification: {name: 'Rick Smith', email: 'rick@example.com', phone: '1234567899', birthday: '4/1/1980', notes: 'let me in!'}
#end

#should 'send email to administrator' do
#assert_equal 'Birthday Verification', ActionMailer::Base.deliveries.last.subject
#end

#should 'indicate submission was sent' do
#assert_select '#main', /submission.*reviewed/i
#end
#end
end

context '#edit' do
Expand Down

0 comments on commit 8c610c6

Please sign in to comment.