Пример #1
0
    def post(self):
        username = self.request.get("username")
        password = self.request.get("password")
        verify = self.request.get("verify")
        email = self.request.get("email")

        username_error = ""
        password_error = ""
        verify_error = ""
        email_error = ""

        users = db.GqlQuery("select * from User where name='%s'" % escape(username))

        if users.count(1):
            username_error = "User with such name already exists"

        if not valid_username(username):
            username_error = "That's not valid username"

        if not valid_password(password):
            password_error = "That's not valid password"

        if password != verify:
            verify_error = "Your passwords didn't match"

        if email and not valid_email(email):
            email_error = "That's not valid email"

        if username_error or password_error or verify_error or email_error:
            self.render_form(
                username, password, verify, email, username_error, password_error, verify_error, email_error
            )
        else:
            hash_salt = make_hash_salt(username, password)
            user = User(name=username, email=email, hashpw=hash_salt[0], salt=hash_salt[1])
            user.put()

            cookie = "%s|%s" % (user.key().id(), user.hashpw)
            self.response.headers.add_header("Set-Cookie", "ikariblog_user=%s; Path=/" % cookie)
            self.redirect("/blog/welcome")
Пример #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')

        username_error = ""
        password_error = ""
        verify_error = ""
        email_error = ""
        
        users = db.GqlQuery("select * from User where name='%s'" % escape(username) )
        
        if users.count(1):
            username_error = "User with such name already exists"

        if not valid_username(username):
            username_error = "That's not valid username"
            
        if not valid_password(password):
            password_error = "That's not valid password"
        
        if password != verify:
            verify_error = "Your passwords didn't match"
            
        if email and not valid_email(email):
            email_error = "That's not valid email"

        if username_error or password_error or verify_error or email_error:
            self.render_form(username, password, verify, email, username_error, password_error, verify_error, email_error)            
        else:
            hash_salt = make_hash_salt(username, password)
            user = User(name = username, email = email, hashpw = hash_salt[0], salt = hash_salt[1])
            user.put()

            self.set_cookie(user)            
            self.redirect("/wiki/")