I need solution for allowing only one session for one username (not relying 
on IPs, just one username == one session). This is my quick solution, maybe 
it helps someone :)

So in models/db.py:

auth.settings.login_onvalidation.append(lambda form: 
delete_user_sessions(form.vars.username))

Somewhere in modules (borrowed from 
applications/admin/cron/expire_sessions.py):

def delete_user_sessions(username):
    DIGITS = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
    import os, cPickle
    from gluon import current
    request = current.request
    path = os.path.join(request.folder, 'sessions')
    if not os.path.exists(path):
        return
    for filename in os.listdir(path):
        fullpath = os.path.join(path, filename)
        if os.path.isfile(fullpath) and filename.startswith(DIGITS):
            try:
                session_data = cPickle.load(open(fullpath, 'rb+'))
                session_username = session_data.auth.user.username
                if session_username == username:
                    os.unlink(fullpath)
            except:
                pass

2014 m. vasaris 4 d., antradienis 08:41:52 UTC+2, DeanK rašė:
>
> I've been searching around trying to figure out how to do this without 
> success.  I need to enforce only a single login per user.  Out of the box 
> you can login using the same credentials from different computers, but I 
> need logging in on a different computer to terminate the session of the 
> first log in.  Is this possible?  I found some posts that hinted at using 
> session.connect, but then i couldn't find "check_client" in the ebook...and 
> it didn't seem to work when i tested it.
>
>
> ## Limit single user sessions
> session.connect(request,response,check_client=True) 
>
> Any tips would be appreciated.  Thanks,
>
> Dean
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to