Re: [Catalyst] Accessing arbitrary session data of a given ID - Store::DBI
Thanks Adam, I'll look into that! 2016-11-23 21:14 GMT-02:00 Adam Herzog: > On Oct 23, 2016, at 14:55, Hector Azpurua wrote: >> Is there a recommended way to access or modify session data stored in >> database with Store::DBI ? > > The session data is typically a hashref of data, serialized using Storable, > and converted to Base64 for storage in the database. Look at the > get_session_data() and store_session_data() in > Catalyst::Plugin::Session::Store::DBI to see how the data is retrieved and > stored: https://metacpan.org/source/Catalyst::Plugin::Session::Store::DBI#L24 > > You can do the same thing. From code outside Catalyst you can use DBI or > DBIx::Class or whatever to SELECT the data from the database, decode/thaw it, > work with it however you'd like, then freeze/encode it and UPDATE the db > record. You'll probably want to wrap that in a transaction. > > A separate problem is that the session data is keyed on the session id, not > the username, so you won't be able to directly SELECT the session data for a > particular username. You'd need to select and examine each session to find > the username in $session_data->{'__user'}. Or maybe create a subclass of > Catalyst::Plugin::Session::Store::DBI and store the username as a separate > column in the sessions table. I have no idea how difficult that would be, but > I bet it's manageable. > > -A > > > ___ > List: Catalyst@lists.scsys.co.uk > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst > Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ > Dev site: http://dev.catalyst.perl.org/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Accessing arbitrary session data of a given ID - Store::DBI
On Oct 23, 2016, at 14:55, Hector Azpuruawrote: > Is there a recommended way to access or modify session data stored in > database with Store::DBI ? The session data is typically a hashref of data, serialized using Storable, and converted to Base64 for storage in the database. Look at the get_session_data() and store_session_data() in Catalyst::Plugin::Session::Store::DBI to see how the data is retrieved and stored: https://metacpan.org/source/Catalyst::Plugin::Session::Store::DBI#L24 You can do the same thing. From code outside Catalyst you can use DBI or DBIx::Class or whatever to SELECT the data from the database, decode/thaw it, work with it however you'd like, then freeze/encode it and UPDATE the db record. You'll probably want to wrap that in a transaction. A separate problem is that the session data is keyed on the session id, not the username, so you won't be able to directly SELECT the session data for a particular username. You'd need to select and examine each session to find the username in $session_data->{'__user'}. Or maybe create a subclass of Catalyst::Plugin::Session::Store::DBI and store the username as a separate column in the sessions table. I have no idea how difficult that would be, but I bet it's manageable. -A ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Accessing arbitrary session data of a given ID - Store::DBI
Thank you Tony, I believe a didn't explain myself correctly: I was trying to access and modify *arbitrary users sessions stored in the database*. For example: On a background process I would like to update the cart of the users X and Y but no the cart of the Z user. Is there a clean way to do that? Sorry about the delay in the response, the email went to the spam folder! 2016-10-25 12:34 GMT-02:00: > Hector > you can access session data via $c->session just like you would the > stash ($c->stash) > except that any data you save in the session is available across requests > until the session expires. > > > > Thanks > > Tony B. Okusanya > > > > From:Hector Azpurua > To:catalyst@lists.scsys.co.uk > Date:10/23/2016 04:55 PM > Subject:[Catalyst] Accessing arbitrary session data of a given ID - > Store::DBI > > > > > Hi, > > Is there a recommended way to access or modify session data stored in > database with Store::DBI ? > > In my particular case, I wanted to update the product 'cart', which is > stored in the user session, to add or remove products/elements. I > ended up using a new table for the cart, but nevertheless, I'm still > wondering if there is a nice way to do it editing the session on the > DB. > > Thanks! > > ___ > List: Catalyst@lists.scsys.co.uk > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst > Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ > Dev site: http://dev.catalyst.perl.org/ > > > > > U.S. BANCORP made the following annotations > - > Electronic Privacy Notice. This e-mail, and any attachments, contains > information that is, or may be, covered by electronic communications privacy > laws, and is also confidential and proprietary in nature. If you are not the > intended recipient, please be advised that you are legally prohibited from > retaining, using, copying, distributing, or otherwise disclosing this > information in any manner. Instead, please reply to the sender that you have > received this communication in error, and then immediately delete it. Thank > you in advance for your cooperation. > > - > ___ > List: Catalyst@lists.scsys.co.uk > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst > Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ > Dev site: http://dev.catalyst.perl.org/ > ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Accessing arbitrary session data of a given ID - Store::DBI
Hector you can access session data via $c->session just like you would the stash ($c->stash) except that any data you save in the session is available across requests until the session expires. Thanks Tony B. Okusanya From: Hector AzpuruaTo: catalyst@lists.scsys.co.uk Date: 10/23/2016 04:55 PM Subject:[Catalyst] Accessing arbitrary session data of a given ID - Store::DBI Hi, Is there a recommended way to access or modify session data stored in database with Store::DBI ? In my particular case, I wanted to update the product 'cart', which is stored in the user session, to add or remove products/elements. I ended up using a new table for the cart, but nevertheless, I'm still wondering if there is a nice way to do it editing the session on the DB. Thanks! ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ U.S. BANCORP made the following annotations - Electronic Privacy Notice. This e-mail, and any attachments, contains information that is, or may be, covered by electronic communications privacy laws, and is also confidential and proprietary in nature. If you are not the intended recipient, please be advised that you are legally prohibited from retaining, using, copying, distributing, or otherwise disclosing this information in any manner. Instead, please reply to the sender that you have received this communication in error, and then immediately delete it. Thank you in advance for your cooperation. - ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/