Make user#confirm_resend require a valid token in the session
that matches the requested user, and ensure trying to login as
an unconfirmed user sets such a token.
Fixes #1010
else
user = User.find_by_display_name(params[:display_name])
else
user = User.find_by_display_name(params[:display_name])
- redirect_to root_path if !user || user.active?
+ redirect_to root_path if user.nil? || user.active?
end
end
def confirm_resend
end
end
def confirm_resend
- if user = User.find_by_display_name(params[:display_name])
- Notifier.signup_confirm(user, user.tokens.create).deliver_now
- flash[:notice] = t "user.confirm_resend.success", :email => "your email" # user.email
- else
+ user = User.find_by_display_name(params[:display_name])
+ token = UserToken.find_by_token(session[:token])
+
+ if user.nil? || token.nil? || token.user != user
flash[:error] = t "user.confirm_resend.failure", :name => params[:display_name]
flash[:error] = t "user.confirm_resend.failure", :name => params[:display_name]
+ else
+ Notifier.signup_confirm(user, user.tokens.create).deliver_now
+ flash[:notice] = t "user.confirm_resend.success", :email => user.email
end
redirect_to :action => "login"
end
redirect_to :action => "login"
##
#
def unconfirmed_login(user)
##
#
def unconfirmed_login(user)
+ session[:token] = user.tokens.create.token
+
redirect_to :action => "confirm", :display_name => user.display_name
session.delete(:remember_me)
redirect_to :action => "confirm", :display_name => user.display_name
session.delete(:remember_me)
end
def test_confirm_resend_success
end
def test_confirm_resend_success
+ session[:token] = users(:inactive_user).tokens.create.token
+
assert_difference "ActionMailer::Base.deliveries.size", 1 do
get :confirm_resend, :display_name => users(:inactive_user).display_name
end
assert_difference "ActionMailer::Base.deliveries.size", 1 do
get :confirm_resend, :display_name => users(:inactive_user).display_name
end
ActionMailer::Base.deliveries.clear
end
ActionMailer::Base.deliveries.clear
end
- def test_confirm_resend_failure
+ def test_confirm_resend_no_token
+ assert_no_difference "ActionMailer::Base.deliveries.size" do
+ get :confirm_resend, :display_name => users(:inactive_user).display_name
+ end
+
+ assert_response :redirect
+ assert_redirected_to login_path
+ assert_match "User Inactive User not found.", flash[:error]
+ end
+
+ def test_confirm_resend_unknown_user
assert_no_difference "ActionMailer::Base.deliveries.size" do
get :confirm_resend, :display_name => "No Such User"
end
assert_no_difference "ActionMailer::Base.deliveries.size" do
get :confirm_resend, :display_name => "No Such User"
end