If you use CAS you must change: auth = Auth(db)
into auth = Auth(db, username=True) CAS requires a username. On Friday, 5 April 2013 11:26:50 UTC-5, joe smith wrote: > > I am writing a number of Web2py applications. The base CAS application is > an administration system to keep track of users, organizations, groups, > etc. That part is working fine, but now I want to add additional > applications that use this administration system as a CAS provider. I have > been trying to get things to work properly for a week or so without having > a "nice" solution. I am using a single Postgres database and trying to use > the CAS to authenticate. It seems that when I try to use the CAS provider > from one of the applications I get an error: > > <class 'gluon.contrib.pg8000.errors.ProgrammingError'> ('ERROR', '42703', > 'column auth_user.username does not exist') Version web2py™ (2, 3, 2, > datetime.datetime(2012, 12, 17, 15, 3, 30), 'stable') Python Python > 2.7.3: C:\Python27\python.exe Traceback > > 1. > 2. > 3. > 4. > 5. > 6. > 7. > 8. > 9. > 10. > 11. > 12. > 13. > 14. > 15. > 16. > 17. > 18. > 19. > 20. > 21. > 22. > 23. > 24. > 25. > 26. > 27. > 28. > 29. > 30. > 31. > 32. > 33. > 34. > 35. > 36. > 37. > 38. > 39. > 40. > 41. > 42. > 43. > 44. > > Traceback (most recent call last): > File "C:\wrk\PD\admingui\trunk\gluon\restricted.py", line 212, in restricted > exec ccode in environment > File "C:/wrk/PD/admingui/trunk/applications/app1/controllers/default.py" > <http://127.0.0.1:8000/admin/default/edit/app1/controllers/default.py>, line > 77, in <module> > File "C:\wrk\PD\admingui\trunk\gluon\globals.py", line 193, in <lambda> > self._caller = lambda f: f() > File "C:/wrk/PD/admingui/trunk/applications/app1/controllers/default.py" > <http://127.0.0.1:8000/admin/default/edit/app1/controllers/default.py>, line > 39, in user > return dict(form=auth()) > File "C:\wrk\PD\admingui\trunk\gluon\tools.py", line 1240, in __call__ > return getattr(self, args[0])() > File "C:\wrk\PD\admingui\trunk\gluon\tools.py", line 2090, in login > table_user._filter_fields(cas_user)) > File "C:\wrk\PD\admingui\trunk\gluon\tools.py", line 1714, in > get_or_create_user > user = table_user(**{fieldname: value}) > File "C:\wrk\PD\admingui\trunk\gluon\dal.py", line 7769, in __call__ > return self._db(query).select(limitby=(0,1),for_update=for_update, > orderby=orderby).first() > File "C:\wrk\PD\admingui\trunk\gluon\dal.py", line 8905, in select > return adapter.select(self.query,fields,attributes) > File "C:\wrk\PD\admingui\trunk\gluon\dal.py", line 1631, in select > return self._select_aux(sql,fields,attributes) > File "C:\wrk\PD\admingui\trunk\gluon\dal.py", line 1596, in _select_aux > self.execute(sql) > File "C:\wrk\PD\admingui\trunk\gluon\dal.py", line 1709, in execute > return self.log_execute(*a, **b) > File "C:\wrk\PD\admingui\trunk\gluon\dal.py", line 1703, in log_execute > ret = self.cursor.execute(*a, **b) > File "C:\wrk\PD\admingui\trunk\gluon\contrib\pg8000\dbapi.py", line 246, in > _fn > return fn(self, *args, **kwargs) > File "C:\wrk\PD\admingui\trunk\gluon\contrib\pg8000\dbapi.py", line 317, in > execute > self._execute(operation, args) > File "C:\wrk\PD\admingui\trunk\gluon\contrib\pg8000\dbapi.py", line 322, in > _execute > self.cursor.execute(new_query, *new_args) > File "C:\wrk\PD\admingui\trunk\gluon\contrib\pg8000\interface.py", line > 398, in execute > self._stmt = PreparedStatement(self.connection, query, statement_name="", > *[{"type": type(x), "value": x} for x in args]) > File "C:\wrk\PD\admingui\trunk\gluon\contrib\pg8000\interface.py", line > 138, in __init__ > self._parse_row_desc = self.c.parse(self._statement_name, statement, > types) > File "C:\wrk\PD\admingui\trunk\gluon\contrib\pg8000\protocol.py", line 943, > in _fn > return fn(self, *args, **kwargs) > File "C:\wrk\PD\admingui\trunk\gluon\contrib\pg8000\protocol.py", line > 1104, in parse > return reader.handle_messages() > File "C:\wrk\PD\admingui\trunk\gluon\contrib\pg8000\protocol.py", line 929, > in handle_messages > raise exc > ProgrammingError: ('ERROR', '42703', 'column auth_user.username does not > exist') > > Can anyone tell me the correct way of integrating multiple applications to > use a single CAS provider. I have been through all the forum posts and book > examples. I am always getting table conflicts. In this case it is looking > for auth.username. But in all applications including this one I have > auth.define_tables(username=False), but it still looks for it. > > Here is my db.py file for cas_provider: > > > # -*- coding: utf-8 -*- > > ######################################################################### > ## This scaffolding model makes your app work on Google App Engine too > ## File is released under public domain and you can use without limitations > ######################################################################### > > if not request.env.web2py_runtime_gae: > ## if NOT running on Google App Engine use SQLite or other DB > #db = DAL('sqlite://storage.sqlite',pool_size=1,check_reserved=['all']) > db = DAL('postgres://postgres:password@localhost/mydatabase', pool_size=1, > check_reserved=['all']) > session.connect(request, response, db = db, masterapp = None) > else: > ## connect to Google BigTable (optional 'google:datastore://namespace') > db = DAL('google:datastore') > ## store sessions and tickets there > session.connect(request, response, db=db) > > ## by default give a view/generic.extension to all actions from localhost > ## none otherwise. a pattern can be 'controller/function.extension' > response.generic_patterns = ['*'] if request.is_local else [] > > _migrate=True > _fake_migrate=False > > from gluon.tools import Auth, Crud, Service, PluginManager, prettydate > auth = Auth(db) > crud, service, plugins = Crud(db), Service(), PluginManager() > > # Object Types table > db.define_table('object_types', > Field('name', 'string', length=32), > format='%(name)s', migrate=_migrate) > > # Objects table > db.define_table('objects', > Field('name','string',length=64), > Field('object_type_id', 'reference object_types'), > format='%(name)s', migrate=_migrate) > > #Parent_id's must be existing object_id's > objects_table = db[db.object_types] # get the custom_auth_table > objects_table.name.requires = > IS_NOT_EMPTY(error_message=auth.messages.is_empty) > > ####### Custom Auth Field Definitions: ####### > auth.settings.extra_fields['auth_user']=[ > Field('work_phone','string',length=32), > Field('home_phone','string',length=32), > Field('cell_phone','string',length=32), > Field('photo','upload',autodelete=True), > Field('object_id', 'reference objects')] > > ## create all tables needed by auth if not custom tables > auth.define_tables(migrate=_migrate, fake_migrate=_fake_migrate, > username=False, signature=False) > > ## configure email > mail = auth.settings.mailer > mail.settings.server = 'logging' or 'smtp.gmail.com:587' > mail.settings.sender = 'y...@gmail.com <javascript:>' > mail.settings.login = 'username:password' > > ## configure auth policy > auth.settings.registration_requires_verification = False > auth.settings.registration_requires_approval = False > auth.settings.reset_password_requires_verification = True > > ## if you need to use OpenID, Facebook, MySpace, Twitter, Linkedin, etc. > ## register with janrain.com, write your domain:api_key in > private/janrain.key > from gluon.contrib.login_methods.rpx_account import use_janrain > use_janrain(auth, filename='private/janrain.key') > > > Here is the model db.py file for the cas consumer (app1): > > > # -*- coding: utf-8 -*- > > ######################################################################### > ## This scaffolding model makes your app work on Google App Engine too > ## File is released under public domain and you can use without limitations > ######################################################################### > > ## if SSL/HTTPS is properly configured and you want all HTTP requests to > ## be redirected to HTTPS, uncomment the line below: > # request.requires_https() > _migrate=False > > if not request.env.web2py_runtime_gae: > ## if NOT running on Google App Engine use SQLite or other DB > db = DAL('postgres://postgres:password@localhost/mydatabase', pool_size=1, > check_reserved=['all'], auto_import=True) > session.connect(request, response, db = db, masterapp = 'cas_provider') > else: > ## connect to Google BigTable (optional 'google:datastore://namespace') > db = DAL('google:datastore') > ## store sessions and tickets there > session.connect(request, response, db=db) > ## or store session in Memcache, Redis, etc. > ## from gluon.contrib.memdb import MEMDB > ## from google.appengine.api.memcache import Client > ## session.connect(request, response, db = MEMDB(Client())) > > ## by default give a view/generic.extension to all actions from localhost > ## none otherwise. a pattern can be 'controller/function.extension' > response.generic_patterns = ['*'] if request.is_local else [] > ## (optional) optimize handling of static files > # response.optimize_css = 'concat,minify,inline' > # response.optimize_js = 'concat,minify,inline' > > ######################################################################### > ## Here is sample code if you need for > ## - email capabilities > ## - authentication (registration, login, logout, ... ) > ## - authorization (role based authorization) > ## - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss) > ## - old style crud actions > ## (more options discussed in gluon/tools.py) > ######################################################################### > > from gluon.tools import Auth, Crud, Service, PluginManager, prettydate > auth = Auth(db,cas_provider = ' > http://127.0.0.1:8000/cas_provider/default/user/cas') > crud, service, plugins = Crud(db), Service(), PluginManager() > > > ## create all tables needed by auth if not custom tables > auth.define_tables(migrate=_migrate, fake_migrate=False, username=False) > > ## configure email > mail = auth.settings.mailer > mail.settings.server = 'logging' or 'smtp.gmail.com:587' > mail.settings.sender = 'y...@gmail.com <javascript:>' > mail.settings.login = 'username:password' > > ## configure auth policy > auth.settings.registration_requires_verification = False > auth.settings.registration_requires_approval = False > auth.settings.reset_password_requires_verification = True > > ## if you need to use OpenID, Facebook, MySpace, Twitter, Linkedin, etc. > ## register with janrain.com, write your domain:api_key in > private/janrain.key > from gluon.contrib.login_methods.rpx_account import use_janrain > use_janrain(auth, filename='private/janrain.key') > > ######################################################################### > ## Define your tables below (or better in another model file) for example > ## > ## >>> db.define_table('mytable',Field('myfield','string')) > ## > ## Fields can be 'string','text','password','integer','double','boolean' > ## 'date','time','datetime','blob','upload', 'reference TABLENAME' > ## There is an implicit 'id integer autoincrement' field > ## Consult manual for more options, validators, etc. > ## > ## More API examples for controllers: > ## > ## >>> db.mytable.insert(myfield='value') > ## >>> rows=db(db.mytable.myfield=='value').select(db.mytable.ALL) > ## >>> for row in rows: print row.id, row.myfield > ######################################################################### > > ## after defining tables, uncomment below to enable auditing > # auth.enable_record_versioning(db) > > -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.