If I set a property inside a handler how long is i...
# box-products
o
If I set a property inside a handler how long is it's lifetime? Specifically does it last between 2 different actions in a single handler?
b
@Ookma-Kyi ColdBox handlers are effectively singletons in production mode. For development, if you have handler reload active, they are re-created each request.
Storing state in a handler is possible, but also isn't common. Can you share what your goal is here?
o
@bdw429s In my password reset handler I have 2 actions:
index
- verifies the
userid
and
token
are correct for that user and shows the form to enter a new password.
new
- verifies the form data and changes the users password if correct. Otherwise redirects the user to the previous action where the form is shown again and the error is displayed. The issue is the
index
action reverifies the
userid
and
token
passed in via query string. I am using flash storage at the moment but, the issue is if the user refreshes the page before the password is changed the query string is lost which creates a weird situation where the app doesn't know what to do next. Snipplet: https://gist.github.com/ookma-kyi/26486c7c2fc53600ac3afabbc7ad9e61 Reset Email: You have requested to have your password reset. If this was you click on the link below to reset your password. Otherwise, you can ignore this email. http://127.0.0.1:8080/resetpassword?user=1&token=HIQuMhCWLfgCW7k7
b
Yes, flash storage is a one-time use sort of thing, but that doesn't speak to what you were planning to store in the handler.
It also doesn't sound like you need flash storage. if you are wanting to confirm the token again in the second action, then pass it in a hidden field
A valid user already knows what the token is, so it's not like you need to hide it
o
Yes, flash storage is a one-time use sort of thing, but that doesn't speak to what you were planning to store in the handler.
the userid and token in case the user makes an error.
Copy code
Otherwise redirects the user to the previous action where the form is shown again and the error is displayed. The issue is the index action reverifies the userid and token passed in via query string. I am using flash storage at the moment but, the issue is if the user refreshes the page before the password is changed the query string is lost which creates a weird situation where the app doesn't know what to do next.
b
Do not under any circumstances store data for a specific user in your handler
This will cause you many problem. Imagine if two users are trying to reset their password at the same time on your server. They will be overwriting shared variables in the handler!
Forget flash and forget the handler-- just pass what you need as part of your redirect back to the first action.
o
Issue is it only persists in the first action
index
. Once the form is submitted it's gone ( we're in the
new
action now ) so I have to store it somewhere in case I have to pass it back to the first action
index
cause it is expecting it. A hidden field seems like a good idea. Let me try to figure it out and I'll let you know how it goes.