예제 #1
0
    def get(self):
        # Setting content type to text/plain, for visibility
        self.response.headers['Content-Type'] = 'text/plain'

        visits = 0  # Settings default value

        # Looking up cookie
        visit_cookie_str = self.request.cookies.get('visits')  # Treats cookies like a python dict

        # If we have a cookie
        if visit_cookie_str:
            # We validate it
            cookie_val = security.check_secure_val(visit_cookie_str)
            # If validated
            if cookie_val:
                visits = int(cookie_val)

        # Incrementing cookie value
        visits += 1

        new_cookie_val = security.make_secure_val(str(visits))

        # Writing the cookie down
        # We are using add_header here
        # because we do not want to over
        # -write any other headers with
        # the same name
        self.response.headers.add_header('Set-Cookie', 'visits=%s' % new_cookie_val)

        if visits > 10000:
            self.write("You are the best evvaahh! :D")
        else:
            self.write("You have visited this page %s times" % visits)
예제 #2
0
    def post(self, wikipage_address):
        logging.error(wikipage_address)
        user_id_check = (security.check_secure_val
                         (self.request.cookies.get('user_id')))
        if user_id_check:
            params["username"] = user_id_check
        else:
            self.redirect("/login")
        page_content = self.request.get("content")
        if get_data(wikipage_address):
            parent_p = params["wikipage_query"].key
        else:
            parent_p = None
        page_data = WikiData(
            id=wikipage_address,
            parent=parent_p,
            content=page_content,
            author=user_id_check)
        page_data.put()
        memcache.set(page_data.key.id(), page_data)

        # next few lines reset params
        params["content_err"] = ""
        params["content"] = ""

        self.redirect(wikipage_address)
        return
예제 #3
0
 def get(self):
     username = self.request.cookies.get('name')
     checked_username = security.check_secure_val(username)
     if utility.valid_username(checked_username):
         self.render('welcome.html', username = checked_username)
     else:
         self.redirect('/signup')
예제 #4
0
	def get(self):
		gravatar_url = gravatar()
		username_cookie = self.request.cookies.get('name')
		user = security.check_secure_val(username_cookie)
		if user == None:
			self.redirect('/')
		else:
			self.render("blog_new.html", username = user, gravatar = gravatar_url)
예제 #5
0
 def get(self):
     user_id_check = (security.check_secure_val
                      (self.request.cookies.get('user_id')))
     if user_id_check:
         login_params["username"] = user_id_check
         self.render('welcome.html', **login_params)
     else:
         self.redirect("/signup")
예제 #6
0
파일: blog.py 프로젝트: cavealix/Udacity
 def get(self):
     uid_cookie = self.request.cookies.get('uid', '')
     if uid_cookie and security.check_secure_val(uid_cookie):
         self.response.set_cookie('uid', None)
         #set global template variable
         jinja_env.globals['user'] = None
         self.redirect("/blog/login")
     else:
         self.redirect("/blog/signup")
예제 #7
0
 def get(self, wikipage_address):
     cookie_p = self.request.cookies.get('user_id')
     if cookie_p:
         user_id_check = (security.check_secure_val(cookie_p))
         if user_id_check:
             params["username"] = user_id_check
             self.get_history(wikipage_address)
     else:
         self.redirect("/signup")
예제 #8
0
 def get(self, wikipage_address):
     cookie_p = self.request.cookies.get('user_id')
     if cookie_p:
         user_id_check = (security.check_secure_val
                          (cookie_p))
         if user_id_check:
             params["username"] = user_id_check
             get_data(wikipage_address)
             self.render("editpage.html", **params)
     else:
         self.redirect("/signup")
예제 #9
0
 def __call__(self, environ, start_response):
     cookie = SimpleCookie()
     try:
         cookie.load(environ['HTTP_COOKIE'])
         user_hash = cookie['user_id'].value
     except KeyError:
         # Not logged in, return to the login page
         return self.redirect_to_login(environ, start_response)
     else:
         user_id = security.check_secure_val(user_hash)
         if user_id and user_id in self.authorized_users:
             # valid user, continue
             # include user_id in the environ variable
             environ['app.user_id'] = user_id
             return self.app(environ, start_response)
         else:
             return self.redirect_to_login(environ, start_response)
예제 #10
0
파일: blog.py 프로젝트: cavealix/Udacity
def user_from_cookie(self):
    uid_cookie = self.request.cookies.get('uid', '')
    if uid_cookie and security.check_secure_val(uid_cookie):
        uid = uid_cookie.split('|')[0]
        return User.get_by_id(int(uid))
예제 #11
0
 def read_secure_cookie(self, name):
     cookie_val = self.request.cookies.get(name)
     return cookie_val and check_secure_val(cookie_val)
예제 #12
0
 def check_secure_cookie(self, key):
     """Checks a cookie against a hash."""
     cookie_val = self.request.cookies.get(key)
     return cookie_val and check_secure_val(cookie_val)
예제 #13
0
 def read_secure_cookie(self, name):
     cookie_id = self.request.cookies.get(name)
     return cookie_id and security.check_secure_val(cookie_id)