First, create a new application as in SchevoGearsNewProject, but answer "yes" to the "Do you need Identity in this project?" question.

The following other changes will be necessary.

Update schema

Add the following to the myapp/schema/schema_001.py file. You can alter this schema, but this is the minimum required implementation for out-of-the-box use of the Schevo identity provider:

# All Schevo schema modules must have these lines.
from schevo.schema import *
schevo.schema.prep(locals())

import datetime

class IdentityVisit(E.Entity):

    key = f.string()
    expires = f.datetime()

    _key(key)

    @extentmethod
    def t_update_queued_visits(extent, queue_items=None):
        return E.IdentityVisit._UpdateQueuedVisits(queue_items)

    class _UpdateQueuedVisits(T.Transaction):

        def __init__(self, queue_items):
            T.Transaction.__init__(self)
            self.x.queue_items = queue_items

        def _execute(self, db):
            for visit_key, expires in self.x.queue_items:
                visit = db.IdentityVisit.findone(key=visit_key)
                if visit is not None:
                    tx = visit.t.update(expires=expires)
                    db.execute(tx)

class IdentityVisitUser(E.Entity):

    visit = f.entity('IdentityVisit')
    user = f.entity('IdentityUser')

    _key(visit)

class IdentityGroup(E.Entity):

    name = f.unicode()
    description = f.unicode()

    _key(name)

    _initial = [
        (u'admin', u'Administrators'),
        ]

    def x_permissions(self):
        """Return list of all permissions for this group."""
        return [gp.permission for gp in self.m.identity_group_permissions()]

    def x_users(self):
        """Return list of all users belonging to this group."""
        return [ug.user for ug in self.m.identity_user_groups()]

class IdentityGroupPermission(E.Entity):

    group = f.entity('IdentityGroup')
    permission = f.entity('IdentityPermission')

    _key(group, permission)

    _initial = [
        ((u'admin', ), (u'superuser', )),
        ]

    def __unicode__(self):
        return u'%s :: %s' % (self.group, self.permission)

class IdentityPermission(E.Entity):

    name = f.unicode()
    description = f.unicode()

    _key(name)

    _initial = [
        (u'superuser', u'Perform any task.'),
        ]

    def x_groups(self):
        return [gp.group for gp in self.m.identity_group_permissions()]

class IdentityUser(E.Entity):

    name = f.unicode()
    password = f.password()
    enabled = f.boolean(default=True)

    # This field is not required, but is used by the example templates
    # that TurboGears uses when you use 'tg-admin quickstart
    # --identity'. Here, we define it as a simple calculated field
    # that just returns the user name.
    @f.unicode()
    def display_name(self):
        return self.name

    _key(name)

    _initial = [
        (u'admin', u'admin', DEFAULT),
        ]

    def x_groups(self):
        return [ug.group for ug in self.m.identity_user_groups()]

    def x_permissions(self):
        permissions = set()
        for group in self.x.groups():
            permissions.update(group.x.permissions())
        return permissions

class IdentityUserGroup(E.Entity):

    user = f.entity('IdentityUser')
    group = f.entity('IdentityGroup')

    _key(user, group)

    def __str__(self):
        return u'%s :: %s' % (self.user, self.group)

    _initial = [
        ((u'admin', ), (u'admin', )),
        ]

Remove SQLObject schema

Edit the myapp/model.py and remove all of the SQLObject classes for identity.

Edit app configuration

Edit the myapp/config/app.cfg file and make the following changes.

  1. Change the visit.manager setting to "schevo".

  2. Change the visit.soprovider.model setting to visit.schevomanager.extent and change its value to "IdentityVisit".

  3. Uncomment the identity.provider setting and change it to "schevo".

  4. Change the identity.soprovider settings and their values to the following:

    identity.schevoprovider.extent.user="IdentityUser"
    identity.schevoprovider.extent.group="IdentityGroup"
    identity.schevoprovider.extent.permission="IdentityPermission"
    

Edit jsonify functions

Edit the myapp/json.py file and make the following changes.

  1. Remove the from myapp.model import ... line.

  2. Remove all of the jsonify functions defined.

  3. Add the following line:

    import schevogears.jsonify
    

Edit start script

Edit the start-myapp.py file. Above the last line (the call to start_server), add these two lines:

import schevogears.extension
schevogears.extension.install()

Test

Run the app and browse to http://localhost:8080/. You should now be able to log in as admin/admin.