Пример #1
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:
        cookie_val = hashutil.check_secure_val(visits_cookie_str)
        if cookie_val:
            visits = int(cookie_val)
    
    visits += 1

    self.response.headers.add_header('Set-Cookie', 'visits=%s' % hashutil.make_secure_val(str(visits)))

    if visits > 10:
        self.write("You are the best ever!")
    else:
        self.write("You've been here %s times!" % visits)
Пример #2
0
    def post(self):
        input_username = self.request.get("username")
        input_password = self.request.get("password")

        err_username = ""
        err_password = ""
        err_signin = ""

        output_username = html_util.escape_html(input_username)
        output_password = input_password

        if not signuputil.is_username_valid(input_username):
            err_username = "******"

        if not signuputil.is_password_valid(input_password):
            err_password = "******"
            output_password = ""

        if err_username == "" and err_password == "":
            query = (
                "SELECT * FROM User \
               WHERE username = '******'"
            )
            users = db.GqlQuery(query)

            err_signin = "User does not exists or password does not match. Try again."

            if users.count() > 0 and hashutil.valid_pw(users[0].username, output_password, users[0].password_hash):
                user_id = users[0].key().id()
                self.response.headers.add_header("Set-Cookie", "user_id=%s" % hashutil.make_secure_val(str(user_id)))
                self.redirect(APP_PATH + CORE_PATH)
            else:
                self.render_page(err_signin, output_username, err_username, output_password, err_password)
        else:
            self.render_page(err_signin, output_username, err_username, output_password, err_password)
Пример #3
0
  def set_secure_cookie(self, name, val):

    self.response.headers.add_header('Set-Cookie', 
      '%(name)s=%(val)s' % {'name': name,
                            'val': hashutil.make_secure_val(val)})
Пример #4
0
    def post(self):
        input_username = self.request.get("username")
        input_password = self.request.get("password")
        input_verify = self.request.get("verify")
        input_email = self.request.get("email")

        err_username = ""
        err_password = ""
        err_verify = ""
        err_email = ""

        output_username = html_util.escape_html(input_username)
        output_password = input_password
        output_verify = input_verify
        output_email = html_util.escape_html(input_email)

        if not signuputil.is_username_valid(input_username):
            err_username = "******"

        query = (
            "SELECT * FROM User \
               WHERE username = '******'"
        )
        users = db.GqlQuery(query)
        if users.count() > 0:
            err_username = "******"

        if not signuputil.is_password_valid(input_password):
            err_password = "******"
            output_password = ""
            output_verify = ""

        if input_password != input_verify:
            err_verify = "Does not match the password you entered"

        if not signuputil.is_email_valid(input_email):
            err_email = "Invalid email"

        if err_username == "" and err_password == "" and err_verify == "" and err_email == "":

            if output_email == "":
                output_email = None
            user = User(
                username=output_username,
                password_hash=hashutil.make_pw_hash(output_username, output_password),
                email=output_email,
            )
            user.put()
            user_id = user.key().id()
            self.response.headers.add_header("Set-Cookie", "user_id=%s" % hashutil.make_secure_val(str(user_id)))
            self.redirect(APP_PATH + CORE_PATH)
        else:
            self.render_page(
                output_username,
                err_username,
                output_password,
                err_password,
                output_verify,
                err_verify,
                output_email,
                err_email,
            )