---------- Forwarded message ----------
Date: Mon, 16 Oct 2006 14:19:53 -0700 (PDT)
From: anil maran <[EMAIL PROTECTED]>
To: Danny Yoo <[EMAIL PROTECTED]>
Subject: followup on python cookies/sessions

Dear Danny

My login code looks like this for session and cookie i dont know how to combine 
both and save session id in cookie,


SESSION CODE


class login:


     @checkaccess()


     def GET(self):


         web.render('login.html')





     @checkaccess()


     def POST(self):


         user = web.storify({


         'id':1,


         'username':'mark',


         'password':'userss',


         'groups':'admin'


         })


         inp = web.input()


         if inp.username == user.username and inp.password == user.password:


             dologin(user)


             web.redirect('/')


         else:


             web.render('login.html')





class logout:


     @checkaccess()


     def GET(self):


         dologout()


         web.redirect('/')





class login:


     @checkaccess()


     def GET(self):


         web.render('login.html')





     @checkaccess()


     def POST(self):


         user = web.storify({


         'id':1,


         'username':'anil',


         'password':'toper',


         'groups':'admin'


         })


         inp = web.input()


         if inp.username == user.username and inp.password == user.password:


             dologin(user)


             web.redirect('/')


         else:


             web.render('login.html')





class logout:


     @checkaccess()


     def GET(self):


         dologout()


         web.redirect('/')


COOKIE CODE

def check_password(raw_password, enc_password):


     """


     Returns a boolean of whether the raw_password was correct. Handles


     encryption formats behind the scenes.


     """


     algo, salt, hsh = enc_password.split('$')


     if algo == 'sha1':


         return hsh == sha.new(salt+raw_password).hexdigest()


     elif algo == 'md5':


         import md5


         return hsh == md5.new(salt+raw_password).hexdigest()


     raise ValueError, "Got unknown password algorithm type in password."





class login:


   def POST(self):


     login = web.input()


     thisuser = web.query('select * from users where email = $login.email', 
vars=locals())





     if thisuser:


       thisuser = thisuser[0]


       if login.email== thisuser.email and check_password(login.passwd, 
thisuser.password):


         web.setcookie('username', thisuser.email)


     else:


       web.setcookie('rss_flash_message', 'Please try again with correct email 
and password')


     web.redirect('/')





class logout:


   def GET(self):


     web.setcookie('username', '')


     web.redirect('/')

Please help me out thanks

Anil 
Anil
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to