How to create simple login form without using Google Users API ?

16 views
Skip to first unread message

sart

unread,
Apr 16, 2008, 7:27:06 AM4/16/08
to Google App Engine
Hello!
I'm new to Python and GAE. I wrote this simple login form but it's not
working...

import cgi
import wsgiref.handlers

from google.appengine.ext import webapp
from google.appengine.ext import db

class User(db.Model):
lastname = db.StringProperty(required=False)
firstname = db.StringProperty(required=False)
login = db.StringProperty(required=False)
password = db.StringProperty(required=False)


class MainPage(webapp.RequestHandler):
def get(self):
self.response.out.write('<html><body>')
userlastname = db.GqlQuery("SELECT lastname FROM User WHERE login
= :login AND password = :password")
if userlastname ('smith'):
self.response.out.write(userlastname)

self.response.out.write("""
<form action="/" method="post">
<div><input name="login" type="text"></div>
<div><input name="password" type="text"></div>
<div><input type="submit" value="Login"></div>
</form>
</body>
</html>""")


def main():
application = webapp.WSGIApplication(
[('/', MainPage)],
debug=True)
wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
main()

Traceback (most recent call last):
File "D:\Program Files\Google\google_appengine\google\appengine\ext
\webapp\__init__.py", line 484, in __call__
handler.get(*groups)
File "D:\Program Files\Google\google_appengine\reg\login.py", line
18, in get
userlastname = db.GqlQuery("SELECT lastname FROM User WHERE login
= :login AND password = :password")
File "D:\Program Files\Google\google_appengine\google\appengine\ext
\db\__init__.py", line 1498, in __init__
self._proto_query = gql.GQL(query_string, _app=app)
File "D:\Program Files\Google\google_appengine\google\appengine\ext
\gql\__init__.py", line 148, in __init__
if not self.__Select():
File "D:\Program Files\Google\google_appengine\google\appengine\ext
\gql\__init__.py", line 385, in __Select
self.__Expect('*')
File "D:\Program Files\Google\google_appengine\google\appengine\ext
\gql\__init__.py", line 335, in __Expect
self.__Error('Unexpected Symbol: %s' % symbol_string)
File "D:\Program Files\Google\google_appengine\google\appengine\ext
\gql\__init__.py", line 311, in __Error
(error_message, self.__symbols[self.__next_symbol]))
BadQueryError: Parse Error: Unexpected Symbol: * at symbol lastname

Can anyone help me ?

Joscha Feth

unread,
Apr 16, 2008, 8:27:38 AM4/16/08
to Google App Engine
Hi sart,

> userlastname = db.GqlQuery("SELECT lastname FROM User WHERE login
> = :login AND password = :password")

GQL is not SQL - there is currently no way to just get a single field
from an entity like you are trying above - you can only select
complete entities - so the GQL you wrote must read:

db.GqlQuery("SELECT * FROM User WHERE login = :login AND password
= :password",login="X",password="Y")

also you need to pass bound variables (like :login and :password) to
the GqlQuery method.
In your example this should work:

user = User.gql("WHERE login = :login AND password
= :password",login=self.request.get('login'),password=self.request.get('password')).get()

if user is not None:
lastname = user.lastname

sart

unread,
Apr 16, 2008, 8:47:44 AM4/16/08
to Google App Engine
thank you very much =)
Reply all
Reply to author
Forward
0 new messages