If, on the verification page, the user clicks the "Resend" button,
a new email is sent to their account.
Signed-off-by: Darryl L. Pierce <mcpierce(a)gmail.com>
---
app/controllers/users_controller.rb | 32 ++++++++++++--------
app/views/users/verify.html.erb | 45 ++++++++++++++++++-----------
public/stylesheets/forms.css | 3 +-
test/functional/users_controller_test.rb | 17 ++++++++++-
4 files changed, 64 insertions(+), 33 deletions(-)
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 15c7894..3837436 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -124,22 +124,28 @@ class UsersController < ApplicationController
respond_to do |format|
if @this_user.id == @user.id
if !(a)user.verified?
- @token = params[:token]
+ if params[:resend]
+ flash[:message] = "Sent another verification email to
#{(a)this_user.email}."
+
UserMailer.deliver_email_verification(@this_user,(a)this_user.verification.token)
+ format.html
+ else
+ @token = params[:token]
- if @token && @user.verify(@token)
- User.transaction do
- @user.verification.destroy
+ if @token && @user.verify(@token)
+ User.transaction do
+ @user.verification.destroy
- flash[:message] = "#{(a)user.email} is now verified."
- format.html { redirect_to user_path(@user) }
+ flash[:message] = "#{(a)user.email} is now verified."
+ format.html { redirect_to user_path(@user) }
+ end
+ else
+ @title = "Email Verification For #{(a)user.email}"
+ flash[:error] = "Missing or invalid verification token."
+ format.html
end
- else
- @title = "Email Verification For #{(a)user.email}"
- flash[:error] = "Missing or invalid verification token."
- format.html
end
else
- flash[:error] = "Your account has already been validated."
+ flash[:error] = "Your account has already been verified."
format.html { redirect_to user_path(@user) }
end
else
diff --git a/app/views/users/verify.html.erb b/app/views/users/verify.html.erb
index e7426ff..5a5df04 100644
--- a/app/views/users/verify.html.erb
+++ b/app/views/users/verify.html.erb
@@ -1,19 +1,30 @@
-<% form_for :user, :url => email_verification_path(:id => @user, :token =>
nil) do |form| %>
- <table class="edit">
- <tr>
- <td class="label-required">Email address:</td>
- <td class="value"><%= @user.email %></td>
- </tr>
+<fieldset id="verify">
+ <legend>Verify Your Account</legend>
+ <% form_for :user, :url => email_verification_path(:id => @user, :token =>
nil) do |form| %>
+ <table class="edit">
+ <colgroup>
+ <col class="label" />
+ <col class="value" />
+ </colgroup>
- <tr>
- <td class="label-required">Token</td>
- <td class="value"><%= text_field_tag :token, @token %>
- </tr>
+ <tbody>
+ <tr>
+ <td class="label-required">Email address</td>
+ <td class="value"><%= @user.email %></td>
+ </tr>
- <tr>
- <td class="buttons" colspan="2">
- <%= submit_tag "Submit" %>
- </td>
- </tr>
- </table>
-<% end %>
+ <tr>
+ <td class="label-required">Token</td>
+ <td class="value"><%= text_field_tag :token, @token %>
+ </tr>
+
+ <tr>
+ <td class="buttons" colspan="2">
+ <%= submit_tag "Submit", :name => :submit %>
+ <%= submit_tag "Resend", :name => :resend %>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ <% end %>
+</fieldset>
diff --git a/public/stylesheets/forms.css b/public/stylesheets/forms.css
index ce9b21d..07dc248 100644
--- a/public/stylesheets/forms.css
+++ b/public/stylesheets/forms.css
@@ -4,8 +4,7 @@
}
fieldset {
- margin-top: 10px;
- margin-bottom: 10px;
+ margin: 10px 0px 10px 15px;
background-color: #fffffe;
max-width: 100%;
width: 2em;
diff --git a/test/functional/users_controller_test.rb
b/test/functional/users_controller_test.rb
index 0207fdd..af4fb7e 100644
--- a/test/functional/users_controller_test.rb
+++ b/test/functional/users_controller_test.rb
@@ -288,9 +288,24 @@ class UsersControllerTest < ActionController::TestCase
"User should not be verified."
end
+ # Ensures that a user can properly resend a verification token.
+ def test_verify_with_resend_request
+ post :verify,
+ {:id => @unverified_user.id, :resend => true},
+ {:user_id => @unverified_user.id}
+
+ assert_response :success
+ assert !User.find_by_id((a)unverified_user.id).verified?,
+ "User should not be verified."
+
+ email = @emails.first
+ assert email, "No email was generated."
+ assert_equal @unverified_user[:email], email.to[0], "Email sent to wrong
user."
+ end
+
# Ensures that verification works as expected.
def test_verify
- get :verify,
+ post :verify,
{:id => @unverified_user.id, :token => @unverified_user.verification.token},
{:user_id => @unverified_user.id}
--
1.6.0.2