Ejemplo n.º 1
0
  def post(self):
    user_username = self.request.get('username')
    user_password = self.request.get('password')

    # UGLY, FIX SO FORMUTILS EXPOSES NO PUBLIC VARIABLES
    invalid_username_format = not form_utils.username_re.match(user_username)
    invalid_password_format = not form_utils.password_re.match(user_password)
    invalid_user = not self.valid_user(user_username, user_password)

    if invalid_username_format or invalid_password_format or invalid_user:       
      self.render_login(error="Invalid login.")
    else:
      secure_username = sec_utils.make_secure_val(str(user_username))
      signed_username_cookie = "user_id=%s; Path=/" % secure_username
      self.response.headers.add("Set-Cookie", str(signed_username_cookie))
      self.redirect("/blog/welcome")
Ejemplo n.º 2
0
  def get(self):
    self.response.headers["Content-Type"] = "text/plain"

    visits = 0
    visits_cookie_str = self.request.cookies.get("visits")

    if visits_cookie_str != None:
      visits_val = sec_utils.extract_secure_val(visits_cookie_str)
      if visits_val:
        visits = int(visits_val)
    
    visits += 1
    new_visits_cookie_str = sec_utils.make_secure_val(str(visits))
    self.response.headers.add("Set-Cookie", "visits=%s" % new_visits_cookie_str)
        
    if visits > 20:
      self.write("You've been here %s times. WOOHOO!" % visits)
    else:
      self.write("You've been here %s times" % visits)
Ejemplo n.º 3
0
  def post(self):
    user_username = self.request.get('username')
    user_password = self.request.get('password')
    user_verify = self.request.get('verify')
    user_email = self.request.get('email')

    username_error = form_utils.check_username(user_username, "That's not a valid username.")    
    password_error = form_utils.check_password(user_password, "That wasn't a valid password.")
    verify_error = "" if ((user_password == user_verify) or (not password_error == "")) else "Your passwords didn't match."
    email_error = form_utils.check_email(user_email, "That's not a valid email.") 
    
    if (not username_error) and (not self.new_user(user_username, user_password, user_email)):
      username_error = "That user already exists."
    
    if (not username_error) and (not password_error) and (not verify_error) and (not email_error):
      secure_username = sec_utils.make_secure_val(str(user_username)) 
      signed_username_cookie = "user_id=%s; Path=/" % secure_username 
      self.response.headers.add("Set-Cookie", str(signed_username_cookie))
      self.redirect("/blog/welcome")
    else:
      self.render_signup(user_username, username_error, password_error,
                         verify_error, user_email, email_error)