Exemple #1
0
 def valid_username_cookie(username):
     # DB lookup here for user
     username = username.split('|')
     if (not len(username) == 2):
         return None
     user = User.lookup_user(username[0])
     if (user and user.pw_hash == username[1]):
         return user
     else:
         return None
Exemple #2
0
    def post(self):
        username = self.request.get('username')
        password = self.request.get('password')
        verify = self.request.get('verify')
        email = self.request.get('email')
        invalid_username = ""
        invalid_password = ""
        invalid_verify = ""
        invalid_email = ""

        if (not chk_username(username)):
            invalid_username = "******"
        if (not chk_password(password)):
            invalid_password = "******"
        if (password != verify):
            invalid_verify = "Your passwords didn't match."
        if (email and not chk_email(email)):
            invalid_email = "That's not a valid email."

        if (not (invalid_username or invalid_password or invalid_verify
                 or invalid_email)):
            if (User.lookup_user(username)):
                invalid_username = "******"

        if (invalid_username or invalid_password or invalid_verify
                or invalid_email):
            self.render("signup.html",
                        username=username,
                        email=email,
                        invalid_username=invalid_username,
                        invalid_password=invalid_password,
                        invalid_verify=invalid_verify,
                        invalid_email=invalid_email)
        else:
            a = User.make_user(username, password, email)
            a.put()
            self.redirect("/welcome")
            self.response.headers.add_header(
                'Set-Cookie',
                str('username=%s|%s; Path=/' % (a.username, a.pw_hash)))