Example #1
0
 def testCookie(self, name):
     '''tests a cookie against it's hash and return value if valid'''
     #create the cookie with setCookie
     cookie = self.request.cookies.get(name)
     if cookie and cookie.find(":") != -1:
         value, t_hash = cookie.split(':')
         if testCookieHash(t_hash, value):
             return value
     return False
Example #2
0
    def testCookie(self):
        cookie = self.request.cookies.get('user')

        if cookie and cookie.find(":") != -1:
            username, t_hash = cookie.split(':')
            if testCookieHash(t_hash, username):
                return username
            else:
                return False
        else:
            return False
Example #3
0
File: envdef.py Project: Mb01/yasai
 def testCookie(self):
     cookie = self.request.cookies.get('user')
     
     if cookie and cookie.find(":") != -1:
         username, t_hash = cookie.split(':')
         if testCookieHash(t_hash, username):
             return username
         else:
             return False
     else:
         return False
Example #4
0
 def post(self):
     ######################################
     #case: create question
     q = self.request.get('q')
     a = self.request.get('a')
     c1= self.request.get('c1')
     c2= self.request.get('c2')
     c3= self.request.get('c3')
     genre= self.request.get('genreSet')
     logging.info("genre is: " + genre)
     if q and a and c1 and c2 and c3 and genre:
         createQuestion(q,a,c1,c2,c3, genre)
         return
     ######################################
     #case: grade question
     ans = self.request.get('ans')
     hashed = self.request.get('hashed')
     if ans and hashed:
         if testCookieHash(hashed,ans):
             self.response.out.write('<div style="color:green">That\'s correct!</div>')
             score = 1
         else:
             self.response.out.write('<div style="color:red">Nope sorry.</div>')
             score = 0
         userName = self.testCookie('user')
         userRating = str(self.testCookie('rating'))[len(userName):]
         qK = self.testCookie('qK')
         qRating = self.testCookie('qRating')
         userRating = updateRating(userName, float(userRating), qK, float(qRating), score)
         self.setCookie('rating', userName + userRating)
         return
     #case: good question vote
     good = self.request.get('good')
     if good:
         qK = self.testCookie('qK')
         voteQuestion(1,qK)
         return
     bad = self.request.get('bad')
     if bad:
         qK = self.testCookie('qK')
         voteQuestion(0,qK)
         return