Search code examples
pythongoogle-app-enginewsgiweb2pyweb2py-modules

How can I create new auth_user and auth_group on Web2py running on Google App Engine (GAE)?


I've created an app on my local computer with Web2py and it is running via WSGI with SQLite. I can successfully deploy my app to Google App Engine, using my own domain and doing all url rewrites I need.

Now I need a way to create specific administrative users that will be responsible for update some tables.

Specific questions:

  1. Is there a way I can use Web2py admin interface when my appliation is running on GAE ?
  2. Even if I do not want create news applications nor edit files, is it possible to use Web2py admin interface just to manage the database of an application running on Google App engine?
  3. If not, how this kind of user management is done when using Web2py on GAE?

Solution

  • I've never used GAE before, but I usually do something like this in my db.py to create an initial administrative user:

    def check_initialize():
        if not db().select(db.auth_user.ALL).first():        
            db.auth_user.insert(
                username = 'administrator',
                password = db.auth_user.password.validate('admin1234')[0],
                email = '[email protected]',
                first_name = 'System',
                last_name = 'Administrator',
                is_admin = True,
            )
    
    # do initialization check
    cache.ram('db_initialized', lambda: check_initialize(), time_expire=None)
    

    Note that "is_admin" is a field I added to the auth_user table, but I could have just as easily added a new auth_group record called "administrators", and then added the new user to the "administrators" group using "auth.add_membership(1, 1)".

    For administrative functions, if you can't get the web2py admin working (which should be possible if you set up web2py to run over HTTPS), then you can always create your own editor using something like this:

    def users():
        form = SQLFORM.grid(db.auth_user)
        return dict(form=form)
    

    That will create a grid control listing all users, and allowing you to add and remove users. You could do the same thing for db.auth_group and db.auth_membership. You may need to tweak it a bit though. Alternatively, you could always use something like this: Instant Admin or Badmin