Skip to content

Commit

Permalink
Remove email confirmations
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Burns and Harold Giménez authored and Harold Giménez committed Dec 22, 2010
1 parent 0a86872 commit f8ec9a9
Show file tree
Hide file tree
Showing 23 changed files with 42 additions and 432 deletions.
74 changes: 0 additions & 74 deletions app/controllers/clearance/confirmations_controller.rb

This file was deleted.

1 change: 0 additions & 1 deletion app/controllers/clearance/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def update

if @user.update_password(params[:user][:password],
params[:user][:password_confirmation])
@user.confirm_email!
sign_in(@user)
flash_success_after_update
redirect_to(url_after_update)
Expand Down
19 changes: 3 additions & 16 deletions app/controllers/clearance/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,9 @@ def create
flash_failure_after_create
render :template => 'sessions/new', :status => :unauthorized
else
if @user.email_confirmed?
sign_in(@user)
flash_success_after_create
redirect_back_or(url_after_create)
else
::ClearanceMailer.confirmation(@user).deliver
flash_notice_after_create
redirect_to(sign_in_url)
end
sign_in(@user)
flash_success_after_create
redirect_back_or(url_after_create)
end
end

Expand All @@ -45,13 +39,6 @@ def flash_success_after_create
flash[:success] = translate(:signed_in, :default => "Signed in.")
end

def flash_notice_after_create
flash[:notice] = translate(:unconfirmed_email,
:scope => [:clearance, :controllers, :sessions],
:default => "User has not confirmed email. " <<
"Confirmation email will be resent.")
end

def url_after_create
'/'
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/clearance/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def create
@user = ::User.new params[:user]
if @user.save
flash_notice_after_create
sign_in(@user)
redirect_to(url_after_create)
else
render :template => 'users/new'
Expand All @@ -24,8 +25,7 @@ def create
def flash_notice_after_create
flash[:notice] = translate(:deliver_confirmation,
:scope => [:clearance, :controllers, :users],
:default => "You will receive an email within the next few minutes. " <<
"It contains instructions for confirming your account.")
:default => "You are now signed up.")
end

def url_after_create
Expand Down
11 changes: 0 additions & 11 deletions app/models/clearance_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class ClearanceMailer < ActionMailer::Base

def change_password(user)
@user = user
from Clearance.configuration.mailer_sender
Expand All @@ -8,14 +7,4 @@ def change_password(user)
:scope => [:clearance, :models, :clearance_mailer],
:default => "Change your password")
end

def confirmation(user)
@user = user
from Clearance.configuration.mailer_sender
recipients @user.email
subject I18n.t(:confirmation,
:scope => [:clearance, :models, :clearance_mailer],
:default => "Account confirmation")
end

end
5 changes: 0 additions & 5 deletions app/views/clearance_mailer/confirmation.html.erb

This file was deleted.

4 changes: 0 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
resource :password,
:controller => 'clearance/passwords',
:only => [:create, :edit, :update]

resource :confirmation,
:controller => 'clearance/confirmations',
:only => [:new, :create]
end

match 'sign_up' => 'clearance/users#new', :as => 'sign_up'
Expand Down
10 changes: 1 addition & 9 deletions lib/clearance/shoulda_macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,8 @@ def should_be_signed_in_as(&block)
end

def should_be_signed_in_and_email_confirmed_as(&block)
warn "[DEPRECATION] should_be_signed_in_and_email_confirmed_as: questionable usefulness"
warn "[DEPRECATION] should_be_signed_in_and_email_confirmed_as: email confirmation is gone"
should_be_signed_in_as &block

should "have confirmed email" do
user = block.bind(self).call

assert_not_nil user
assert_equal user, assigns(:user)
assert assigns(:user).email_confirmed?
end
end

def should_not_be_signed_in
Expand Down
18 changes: 1 addition & 17 deletions lib/clearance/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ def self.included(model)
model.class_eval do
before_save :initialize_salt,
:encrypt_password
before_create :generate_confirmation_token,
:generate_remember_token
after_create :send_confirmation_email, :unless => :email_confirmed?
before_create :generate_remember_token
end
end
end
Expand Down Expand Up @@ -101,16 +99,6 @@ def reset_remember_token!
save(:validate => false)
end

# Confirm my email.
#
# @example
# user.confirm_email!
def confirm_email!
self.email_confirmed = true
self.confirmation_token = nil
save(:validate => false)
end

# Mark my account as forgotten password.
#
# @example
Expand Down Expand Up @@ -183,10 +171,6 @@ def password_required?
# warn "[DEPRECATION] password_required?: use !password_optional? instead"
!password_optional?
end

def send_confirmation_email
ClearanceMailer.confirmation(self).deliver
end
end

module ClassMethods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ Feature: Password reset

Scenario: User is signed up updated his password and types wrong confirmation
Given I signed up with "email@person.com/password"
And I go to the password reset request page
And I fill in "Email address" with "email@person.com"
And I press "Reset password"
When I follow the password reset link sent to "email@person.com"
And I update my password with "newpassword/wrongconfirmation"
Then I should see an error message
And I should be signed out

Scenario: User is signed up and updates his password
Given I signed up with "email@person.com/password"
And I go to the password reset request page
And I fill in "Email address" with "email@person.com"
And I press "Reset password"
When I follow the password reset link sent to "email@person.com"
And I update my password with "newpassword/newpassword"
Then I should be signed in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,18 @@ Feature: Sign in
Then I should see "Bad email or password"
And I should be signed out

Scenario: User is not confirmed
Given I signed up with "email@person.com/password"
When I go to the sign in page
And I sign in as "email@person.com/password"
Then I should see "User has not confirmed email"
And I should be signed out

Scenario: User enters wrong password
Given I am signed up and confirmed as "email@person.com/password"
Given I am signed up as "email@person.com/password"
When I go to the sign in page
And I sign in as "email@person.com/wrongpassword"
Then I should see "Bad email or password"
And I should be signed out

Scenario: User signs in successfully
Given I am signed up and confirmed as "email@person.com/password"
Given I am signed up as "email@person.com/password"
When I go to the sign in page
And I sign in as "email@person.com/password"
Then I should see "Signed in"
And I should be signed in
When I return next time
Then I should be signed in

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Feature: Sign out
Should be able to sign out

Scenario: User signs out
Given I am signed up and confirmed as "email@person.com/password"
Given I am signed up as "email@person.com/password"
When I sign in as "email@person.com/password"
Then I should be signed in
And I sign out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,4 @@ Feature: Sign up
And I fill in "Password" with "password"
And I fill in "Confirm password" with "password"
And I press "Sign up"
Then I should see "instructions for confirming"
And a confirmation message should be sent to "email@person.com"

Scenario: User confirms his account
Given I signed up with "email@person.com/password"
When I follow the confirmation link sent to "email@person.com"
Then I should see "Confirmed email and signed in"
And I should be signed in

Scenario: Signed in user clicks confirmation link again
Given I signed up with "email@person.com/password"
When I follow the confirmation link sent to "email@person.com"
Then I should be signed in
When I follow the confirmation link sent to "email@person.com"
Then I should see "Confirmed email and signed in"
And I should be signed in

Scenario: Signed out user clicks confirmation link again
Given I signed up with "email@person.com/password"
When I follow the confirmation link sent to "email@person.com"
Then I should be signed in
When I sign out
And I follow the confirmation link sent to "email@person.com"
Then I should see "Already confirmed email. Please sign in."
And I should be signed out

Then I should see "signed up"
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@
end

Given /^I signed up with "(.*)\/(.*)"$/ do |email, password|
user = Factory :user,
:email => email,
:password => password,
:password_confirmation => password
Factory(:user,
:email => email,
:password => password,
:password_confirmation => password)
end

Given /^I am signed up and confirmed as "(.*)\/(.*)"$/ do |email, password|
user = Factory :email_confirmed_user,
:email => email,
:password => password,
:password_confirmation => password
Given /^I am signed up as "([^"]+)"$/ do |email_password|
Given %{I signed up with "#{email_password}"}
end

# Session
Expand Down Expand Up @@ -59,24 +56,6 @@

# Emails

Then /^a confirmation message should be sent to "(.*)"$/ do |email|
user = User.find_by_email(email)
assert !user.confirmation_token.blank?
assert !ActionMailer::Base.deliveries.empty?
result = ActionMailer::Base.deliveries.any? do |email|
email.to == [user.email] &&
email.subject =~ /confirm/i &&
email.body =~ /#{user.confirmation_token}/
end
assert result
end

When /^I follow the confirmation link sent to "(.*)"$/ do |email|
user = User.find_by_email(email)
visit new_user_confirmation_path(:user_id => user,
:token => user.confirmation_token)
end

Then /^a password reset message should be sent to "(.*)"$/ do |email|
user = User.find_by_email(email)
assert !user.confirmation_token.blank?
Expand Down
2 changes: 1 addition & 1 deletion lib/rails/generators/clearance_templates/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
end

Factory.define :email_confirmed_user, :parent => :user do |user|
user.email_confirmed { true }
user.after_build { warn "[DEPRECATION] The :email_confirmed_user factory is deprecated, please use the :user factory instead." }
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ def self.up
t.string :salt, :limit => 128
t.string :confirmation_token, :limit => 128
t.string :remember_token, :limit => 128
t.boolean :email_confirmed, :default => false, :null => false
t.timestamps
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ def self.up
[:encrypted_password, 't.string :encrypted_password, :limit => 128'],
[:salt, 't.string :salt, :limit => 128'],
[:confirmation_token, 't.string :confirmation_token, :limit => 128'],
[:remember_token, 't.string :remember_token, :limit => 128'],
[:email_confirmed, 't.boolean :email_confirmed, :default => false, :null => false']
[:remember_token, 't.string :remember_token, :limit => 128']
].delete_if {|c| existing_columns.include?(c.first.to_s)}
-%>
change_table(:users) do |t|
Expand Down
Loading

0 comments on commit f8ec9a9

Please sign in to comment.