Re: Who is logged in??
Christopher Clarke <cclarke-wYfHrJ5eQDBWk0Htik3J/[email protected]> Wed, 27 Jun 2007 12:12:24 -0400
| Newsgroups | gmane.comp.python.spyce.general |
|---|---|
| Message-ID | <[email protected]> |
Hi Jonathan
I've gotten it back working as before
Here's what i did
As i say i using an class called sec_auth
that i have since the pre-spyce days of cgi and cookies (it has the
salt and the encryption method etc. for each project)
the login method performs the select on the user attributes table
select * from user_attributes where
user_name=login and password=password
this puts results in in the dictionary called auth
My config.py file looks likes
----
#my_auth is an instance of the sec_auth
udata=None
def validator(login,password):
global udata
try:
udata = myauth.login(login,password)
except sec_auth.BadUserName,sec_auth.BadCredentialsError:
udata=None
if udata:
return login
else:
return None
--------------
in parent.spi i have
--
[[.import name=session]]
<f:form>
<spy:login />
[[\
from spyceConfig import udata
if not session.get('udata') and udata:
session['udata'] = udata
]]
<div id="banner">
You are logged in to SMW as [[=session['udata']['name'] ]]
<spy:logout>
</div>
</form>
------
I realize that i have to put the udata in the session since if the
server restarts and i am logged in already then udata is none
The advantage of the login_tags is that think i can easily implement
functionality like
who's on line,user active count etc.
since i can store the session_id and the associated id in my sessions
table
One potential problem?
If i logout of one site do i logout of all sites (cookie.delete
(__spy_login'))??
Regards
Chris
On 26 Jun 2007, at 13:23, Jonathan Ellis wrote:
> On Tue, 26 Jun 2007 12:45:27 -0400, "Christopher Clarke"
> <cclarke-wYfHrJ5eQDBWk0Htik3J/[email protected]> said:
>> In switching to the login tag i was attempting to access the session
>> from the config.py
>> But i just colud not get a handle on it (the session that is).
>> I've tried
>> session['user_data'] = udata #udata is a dict of user attributes
>> It appears to work but when i try to access this from the page i get
>> an invalid key error
>> I've used the session in my active handlers by using api.session
>> how do i and set session variable from config.py>>
>
> You can't, there's no active session there, sessions are per request.
> What is the active request in config.py? There is none.
>
>> In any case is this the best way to achieve what i am trying to do???
>
> Most frameworks do this by putting session data in a database and
> querying that. So you could either write a DB session backend and do
> that, or you could use os.stat on the session files generated by the
> existing FS-based backend to get the mtimes.
>
> -Jonathan
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/