mirror of
https://github.com/discourse/discourse.git
synced 2025-03-20 14:29:20 +08:00
FEATURE: remove email_token_grace_period_hours
The site setting email_token_grace_period_hours just causes confusion and should not be used anyway. Out of the box, tokens stop working once confirmed, no need to add complexity here
This commit is contained in:
parent
7918d99a2e
commit
eb2db23b40
@ -23,10 +23,6 @@ class EmailToken < ActiveRecord::Base
|
|||||||
SiteSetting.email_token_valid_hours.hours.ago
|
SiteSetting.email_token_valid_hours.hours.ago
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.confirm_valid_after
|
|
||||||
SiteSetting.email_token_grace_period_hours.hours.ago
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.unconfirmed
|
def self.unconfirmed
|
||||||
where(confirmed: false)
|
where(confirmed: false)
|
||||||
end
|
end
|
||||||
@ -52,7 +48,7 @@ class EmailToken < ActiveRecord::Base
|
|||||||
|
|
||||||
user = email_token.user
|
user = email_token.user
|
||||||
failure[:user] = user
|
failure[:user] = user
|
||||||
row_count = EmailToken.where(id: email_token.id, expired: false).update_all 'confirmed = true'
|
row_count = EmailToken.where(confirmed: false, id: email_token.id, expired: false).update_all 'confirmed = true'
|
||||||
|
|
||||||
if row_count == 1
|
if row_count == 1
|
||||||
{ success: true, user: user, email_token: email_token }
|
{ success: true, user: user, email_token: email_token }
|
||||||
@ -85,8 +81,8 @@ class EmailToken < ActiveRecord::Base
|
|||||||
|
|
||||||
def self.confirmable(token)
|
def self.confirmable(token)
|
||||||
EmailToken.where(token: token)
|
EmailToken.where(token: token)
|
||||||
.where(expired: false)
|
.where(expired: false, confirmed: false)
|
||||||
.where("(NOT confirmed AND created_at >= ?) OR (confirmed AND created_at >= ?)", EmailToken.valid_after, EmailToken.confirm_valid_after)
|
.where("created_at >= ?", EmailToken.valid_after)
|
||||||
.includes(:user)
|
.includes(:user)
|
||||||
.first
|
.first
|
||||||
end
|
end
|
||||||
|
@ -977,7 +977,6 @@ en:
|
|||||||
prioritize_username_in_ux: "Show username first on user page, user card and posts (when disabled name is shown first)"
|
prioritize_username_in_ux: "Show username first on user page, user card and posts (when disabled name is shown first)"
|
||||||
|
|
||||||
email_token_valid_hours: "Forgot password / activate account tokens are valid for (n) hours."
|
email_token_valid_hours: "Forgot password / activate account tokens are valid for (n) hours."
|
||||||
email_token_grace_period_hours: "Forgot password / activate account tokens are still valid for a grace period of (n) hours after being redeemed."
|
|
||||||
|
|
||||||
enable_badges: "Enable the badge system"
|
enable_badges: "Enable the badge system"
|
||||||
enable_whispers: "Allow staff private communication within topics."
|
enable_whispers: "Allow staff private communication within topics."
|
||||||
|
@ -389,7 +389,6 @@ users:
|
|||||||
email_token_valid_hours:
|
email_token_valid_hours:
|
||||||
default: 48
|
default: 48
|
||||||
min: 1
|
min: 1
|
||||||
email_token_grace_period_hours: 0
|
|
||||||
purge_unactivated_users_grace_period_days: 14
|
purge_unactivated_users_grace_period_days: 14
|
||||||
public_user_custom_fields:
|
public_user_custom_fields:
|
||||||
type: list
|
type: list
|
||||||
|
@ -266,6 +266,19 @@ describe UsersController do
|
|||||||
expect(session["password-#{token}"]).to be_blank
|
expect(session["password-#{token}"]).to be_blank
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'disallows double password reset' do
|
||||||
|
|
||||||
|
user = Fabricate(:user, auth_token: SecureRandom.hex(16))
|
||||||
|
token = user.email_tokens.create(email: user.email).token
|
||||||
|
|
||||||
|
get :password_reset, token: token
|
||||||
|
put :password_reset, token: token, password: 'hg9ow8yhg98o'
|
||||||
|
put :password_reset, token: token, password: 'test123123Asdfsdf'
|
||||||
|
|
||||||
|
user.reload
|
||||||
|
expect(user.confirm_password?('hg9ow8yhg98o')).to eq(true)
|
||||||
|
end
|
||||||
|
|
||||||
it "redirects to the wizard if you're the first admin" do
|
it "redirects to the wizard if you're the first admin" do
|
||||||
user = Fabricate(:admin, auth_token: SecureRandom.hex(16), auth_token_updated_at: Time.now)
|
user = Fabricate(:admin, auth_token: SecureRandom.hex(16), auth_token_updated_at: Time.now)
|
||||||
token = user.email_tokens.create(email: user.email).token
|
token = user.email_tokens.create(email: user.email).token
|
||||||
|
@ -90,16 +90,6 @@ describe EmailToken do
|
|||||||
expect(user.send_welcome_message).to eq true
|
expect(user.send_welcome_message).to eq true
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when using the code a second time" do
|
|
||||||
|
|
||||||
it "doesn't send the welcome message" do
|
|
||||||
SiteSetting.email_token_grace_period_hours = 1
|
|
||||||
EmailToken.confirm(email_token.token)
|
|
||||||
user = EmailToken.confirm(email_token.token)
|
|
||||||
expect(user.send_welcome_message).to eq false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'success' do
|
context 'success' do
|
||||||
@ -120,13 +110,7 @@ describe EmailToken do
|
|||||||
expect(email_token).to be_confirmed
|
expect(email_token).to be_confirmed
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can be confirmed again" do
|
it "will not confirm again" do
|
||||||
EmailToken.stubs(:confirm_valid_after).returns(1.hour.ago)
|
|
||||||
|
|
||||||
expect(EmailToken.confirm(email_token.token)).to eq user
|
|
||||||
|
|
||||||
# Unless `confirm_valid_after` has passed
|
|
||||||
EmailToken.stubs(:confirm_valid_after).returns(1.hour.from_now)
|
|
||||||
expect(EmailToken.confirm(email_token.token)).to be_blank
|
expect(EmailToken.confirm(email_token.token)).to be_blank
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user