-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Simplifying ConfirmationsController show behavior #1075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplifying ConfirmationsController show behavior #1075
Conversation
Hey @dks17 , perhaps you're right that we shouldn't depend on trackable here. In that case, are you suggesting we set no expiry on the sign in token instead? |
@zachfeldman I am suggesting do less than more. expiry ||= (Time.now + token_lifespan).to_i I just slimplified it much as were possible. Of course we could leave only expiry = (Time.now + 1.second).to_i
client_id, token = @resource.create_token expiry: expiry I think conditional block should be cleaned up anyway. |
Ok, I think this change makes sense then. If another maintainer approves this pull request, I will merge it. |
I would like implement TokenFactory to generate token in one place with opportunity of tuning token and I have almost done it. expiry = nil
if defined?(@resource.sign_in_count) && @resource.sign_in_count > 0
expiry = (Time.now + 1.second).to_i
end
client_id, token = @resource.create_token expiry: expiry @lynndylanhurley, @MaicolBen |
I don't quite understand why you're removing the code, it was added by #519 (I remade the PR in #1001). |
The idea of #519 is to allow only one confirmation, it expires the token with |
Where is place I could turn trackable off in the gem? Is it there? Devise implementation doesn't use trackable sign_in_count. Of course I can be mistaken. |
I have removed :trackable from here included do
# Hack to check if devise is already enabled
unless self.method_defined?(:devise_modules)
devise :database_authenticatable, :registerable,
:recoverable, :validatable, :confirmable
else and got bunch of 9 failures: FAIL["test_User_shoud_have_the_Last_checkin_filled", Minitest::Result, 16.495720947001246]
test_User_shoud_have_the_Last_checkin_filled#Minitest::Result (16.50s)
Expected false to be truthy.
FAIL["test_User_shoud_have_the_signed_in_info_filled", Minitest::Result, 16.618372673998238]
test_User_shoud_have_the_signed_in_info_filled#Minitest::Result (16.62s)
Expected false to be truthy.
FAIL["test_user_already_confirmed", Minitest::Result, 16.850464181996358]
test_user_already_confirmed#Minitest::Result (16.85s)
Expected false to be truthy.
FAIL["test_the_sign_in_count_should_be_1", Minitest::Result, 17.10246518799977]
test_the_sign_in_count_should_be_1#Minitest::Result (17.10s)
Expected false to be truthy.
FAIL["test_sign_in_count_incrementns", Minitest::Result, 29.07351241700235]
test_sign_in_count_incrementns#Minitest::Result (29.07s)
Expected: 1
Actual: 0
FAIL["test_current_sign_in_at_is_updated", Minitest::Result, 29.27919944599853]
test_current_sign_in_at_is_updated#Minitest::Result (29.28s)
Expected nil to be truthy.
FAIL["test_last_sign_in_ip_is_updated", Minitest::Result, 29.481255300001067]
test_last_sign_in_ip_is_updated#Minitest::Result (29.48s)
Expected: "0.0.0.0"
Actual: nil
FAIL["test_sign_in_ip_is_updated", Minitest::Result, 29.64863184800197]
test_sign_in_ip_is_updated#Minitest::Result (29.65s)
Expected: "0.0.0.0"
Actual: nil
FAIL["test_last_sign_in_at_is_updated", Minitest::Result, 29.857282397002564]
test_last_sign_in_at_is_updated#Minitest::Result (29.86s)
Expected nil to be truthy.
409 tests, 562 assertions, 9 failures, 0 errors, 0 skips |
I don't know why you pointed confirmations controller, of course, devise doesn't use it there, but we use it here to avoid double confirmation. So we can't turn off the module, because we use it. You have to turn it off in your code, but seems you have |
DeviseTokenAuth includes modules if devise macro(?) with modules is not defined. class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :validatable, :confirmable
include DeviseTokenAuth::Concerns::User This is the same I have done above. I think we should pay attention to the failures. I think Trackable module is should be optional, for statistics gathering only. And implementation should be independent of the module. What will happen if Trackable was been off? Should 'If' statement computing thousand/million times even if user didn't include Trackable module? |
Sorry if I wasn't clear but in this case
I think
In this part I can agree, how would you achieve that? |
Devise confirmed? method? # expiry = nil
# if defined?(@resource.sign_in_count) && @resource.sign_in_count > 0
# expiry = (Time.now + 1.second).to_i
# end
expiry = @resource.confirmed? ? (Time.now + 1.second).to_i : nil
client_id, token = @resource.create_token expiry: expiry |
@dks17 Sounds good! Can you change that in the PR? It shouldn't break any test |
I have caught: ERROR["test_yield_resource_to_block_on_show_success", Minitest::Result, 26.821582222997677]
test_yield_resource_to_block_on_show_success#Minitest::Result (26.82s)
NoMethodError: NoMethodError: undefined method `[]' for nil:NilClass
app/controllers/custom/confirmations_controller.rb:4:in `show'
ERROR["test_should_redirect_to_success_url", Minitest::Result, 34.8219258479985]
test_should_redirect_to_success_url#Minitest::Result (34.82s)
NoMethodError: NoMethodError: undefined method `[]' for nil:NilClass
ERROR["test_user_should_now_be_confirmed", Minitest::Result, 38.842425470997114]
test_user_should_now_be_confirmed#Minitest::Result (38.84s)
NoMethodError: NoMethodError: undefined method `[]' for nil:NilClass Tests is running randomly. You can catch more errors. |
@dks17: I've run into this same issue while working on a PR for #1123. I have rewritten These errors appear to be the result of a race-condition! Using the Essentially, since the expiry is hard-coded to I've reviewed the changes added in #519 (and #1001), and noticed two things:
@MaicolBen: What is not clear to me is: if the short expiration is conditionally set when a As I've mentioned in #1123, the confirmations controller should check for the |
@MaicolBen: I'm already on it. 👍 However, I've run into a few side effects of that change, and I wanted to ascertain the specifics of the intended behavior when a user clicks on an email confirmation link for a user with an already confirmed email. |
Just wanted to add one more thing regarding
In my case I have the default token lifespan (2 weeks) and max number of devices (10). If a user reaches the max number of devices in less than 2 weeks (not at all impossible), the token that is generated on |
def9671
to
52a0b0e
Compare
Updated. Please see top message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you are using signed_in?
(I had to remind the history of this PR), good work and thanks for bringing back this PR!
Is this snippet is really needed there?
Should behavior of show action depends on including Trackable module or not?
What if Trackable module is off?
Should that behavior be covered with some tests?
UPDATE
-Trackable module extract and removed totally. Now
:trackable
is optional and functionality does not depend on it.@resource
andsigned_in_resource
are not the same.signed_in_resource
is current session user, and@resource
just user which email is confirmed.Signed in user:
Signed out user:
raise routing error
. I think that theshow
action should returnjson
with errors (it brings small api changes). It looks like an issue for another PR.