Hi,
I am stuck on this problem of getting username in all classes( the
username with which I used to login). i am logging in from my 'login'
class of main.py program and need the username in some other classes.
I tried with session and experimented with it for a long time. I have
implemented session like below.

* I used sqlite3 database  and users.db is my database which store the
users detail.

app = web.application(urls, globals(), True)
store = web.session.DiskStore('sessions')
session = web.session.Session(app,store,initializer={'login':
0,'privilege': 0})
render = web.template.render('templates/', globals={'context':
session})

class login:
        def GET(self):
                return render.login()

        def POST(self):
                i = web.input(form_submit="Login")
                authdb = sqlite3.connect('database/users.db')
                conn = authdb.cursor()
                if i.form_submit=='Login':
                        check = conn.execute('select * from user_details
where username=? and password=?', (i.username, i.password))
                        n=check.fetchall()
                        if len(n)!=0:
                                session.loggedin = True
                                session.username = i.username
                                return render.home('Home')
                        else: return render.test1('Wrong username or
password !')
                else:
                        conn.execute('''insert into user_details 
values(?,?,?,?,?,?,?,?)''',
(i.name, i.fname, i.lname, i.country, i.location, i.website, i.uname,
i.passwd))
                        authdb.commit()
                        return render.test1('you are signed up')



I need the username in my display_file class. Because I want to
display different files for different users. I tried to access the
username with 'session.username' but it shows the following
error :AttributeError: 'ThreadedDict' object has no attribute
'username' .
Please suggest any solution for this problem.

-- 
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