from beaker.session import SessionMiddleware
import web
from web import form

log_in = form.Form(
            form.Textbox("login", form.notnull, description="User
name"),
            form.Password("password", form.notnull,
description="Password")
        )

def logged(session):
    if "logeddin" in session:
        if session["logeddin"] == 1:
            return True
    return False

urls = (
    '/', 'index',
    '/logout', 'logout',)

users = {"sl": "123"}

class index:
    def GET(self):
        web.header("Content-Type","text/html; charset=utf-8")
        session = web.ctx.environ['beaker.session']
        if logged(session):
            print "U logged as <b>%s</b>"%session["username"]
            print "<a href='/logout'>logout</a>"
        else:
            print "<form name='main' method='post'> "+ log_in.render()
+ "<input type='submit' />"

    def POST(self):
        session = web.ctx.environ['beaker.session']
        i = web.input()
        if i.login in users and users[i.login] == i.password:
            session['logeddin'] = 1
            session['username'] = i.login
            session.save()
        web.seeother("/")

class logout:
    def GET(self):
        session = web.ctx.environ['beaker.session']
        session.invalidate()
        web.seeother("/")
        """
        or
        session.delete()
        session.save()
        """
def session_mw(app):
    return SessionMiddleware(app, key = "sid")

if __name__ == "__main__":
    web.run(urls, globals(), *(web.reloader, session_mw))


On Jun 24, 9:29 pm, Bibby <[EMAIL PROTECTED]> wrote:
> Hi, all.
>
> I try to write a simple app with webpy 0.3. but i havn't wrote any
> code about auth/session before, Any snippet? link?
>
> Thanks very much.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to