Oct 17, 2014; 20:58
Jolle Carlestam
A more modern version of a session handler
So, on popular demand. I have published a session handler that can replace the worn out, old session handler that comes with Lasso 9.
You can find it here:
https://gist.github.com/jolle-c/02b247b2468073608e17
Some examples on how to use it:
On wherever you handle user logins place this code after you have successfully verified that it is a legit user logging in.
jc_session -> addsession(
'user_id', // this is NOT a hardcoded value, instead use the proper user id as established by the login process
map(// here you set the permissions this user is trusted with, one item in the map for each permission. Permissions can later be expanded or revoked if need be
'some_permission' = true,
'another_permission' = true
),
map(// here you set possible data you want to store in this users session. Could be for example the users name, email etc. Data can later be added to or removed if need be
'some_data' = 'Some Value',
'another_data' = 'Another Value'
),
30 // this is the expire value in minutes
)
To add some session data to the session
jc_session -> data('one_more_key', 'More Data')
Note that whatever session data you add must be compatible with the json format. Complex data types are not allowed
To remove a data item
jc_session -> removedata('the_key')
To add a permission
jc_session -> permission('permission_key', true)
To revoke a permission
jc_session -> permission('permission_key', false)
To retrieve some data stored in the session
jc_session -> data('a_key')
This will return the value stored for the key. If there's no matching key it will return void
To check for a specific permission
jc_session -> permission('permission_key')
Will return true or false
To check if the user has any of a set of permissions use a staticarray
jc_session -> permission((:'a_permission', 'another_permission'))
Will return true if one of the keys match a permission or else false
To expire a session
jc_session -> expire
To get an array of all available keys for data stored in a session
jc_session -> keys
To get the session status
jc_session -> status
Can return any of 'not initiated', 'new', 'load', 'expired', 'not found=92
Have fun!
HDB
Jolle
#############################################################
This message is sent to you because you are subscribed to
the mailing list Lasso Lasso@lists.lassosoft.com
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <Lasso-unsubscribe@lists.lassosoft.com>
Send administrative queries to <Lasso-request@lists.lassosoft.com>