confused about extending file
lovekc opened this issue · 4 comments
on the page http://www.thesoftwarestudio.com/apex/extending_profile.html
auth_user_profile.user_id references the AuthID.id when using a local authentication database, but auth_user_profile.user_id references AuthUser.id. when using OpenID providers.
is this correct? where they are different? can I have both ways to extend the profile at the same time? Thank you!
That is another case of documentation being missed.
The way it works is:
auth_id -----> extended profile
|----> local auth
|----> openID provider.
the extended profile is a parallel table to the authentication table, and the user table actually allows multiple authentication methods to be associated with a single authentication id. This way, a user on your system could have a local auth and attach a Facebook auth to it. They would have two different ways to log into the same Auth ID.
I've cleaned up the docs slightly, but, need to document things a little better as that was written before the main rewrite of Apex.
so right now if I want to add the first name and last name fields I can do something like this?
in models/init.py
from apex.models import AuthID
class ForeignKeyProfile(Base):
tablename = 'auth_user_profile'
id = Column(types.BigInteger, primary_key=True)
auth_id = Column(types.BigInteger, ForeignKey(AuthID.id), index=True)
""" Add your locally defined options here
"""
first_name = Column(Unicode(80))
last_name = Column(Unicode(80))
user = relationship(AuthID, backref=backref('profile', uselist=False))
def __int__(self,auth_id, first_name, last_name);
self.auth_id = auth_id
self.first_name = first_name
self.last_name = last_name
in project/models/profile.py
from apex.forms import RegisterForm
from project.models import DBSession
from project.models import ForeignKeyProfile
class NewRegisterForm(RegisterForm):
first_name = TextField(u'First Name', [validators.length(max=10)])
last_name = TextField(u'Last Name', [validators.length(max=10)])
def after_signup(self, user):
profile = ForeignKeyProfile(auth_id=user.auth_id,first_name=self.data['first_name'], last_name=self.data['last_name']) # is this correct???????
DBSession.add(profile)
DBSession.flush()
by the way ,under the "If you are using OpenID providers: section". why there is
project/profile.py and project/models/profile.py ? there should be only one file, right?
and class openid_after(object): should be class openid_after(RegisterForm): , right ???
also what is the usage of the ExtendedProfile class in apex_example/models.py ?
Thank you ! sorry to ask you so many questions. I'm a newbie
shouldn't be AuthID = relationship(AuthID, backref=backref('profile', uselist=False)) rather than
user = relationship(AuthID, backref=backref('profile', uselist=False)) ? Thank you!
I need to remove one of those sections. The early version of Apex made the distinction between a locally created user and an OpenID created user. The one on the top of that page is the most accurate.
project/profile.py and project/models/profile.py is a typo, it should be in models.
openid_after(object): should be class openid_after(RegisterForm):
You're sending an object through, not the form. However, the documentation is again out of date here. Here's a sample from some code using the current version of Apex.
class openid_after:
def after_signup(self, **kwargs):
request = kwargs.pop('request', False)
if kwargs.has_key('user'):
user = kwargs.pop('user', False)
profile = get_or_create(DBSession, User_Profile, auth_id=user.id)
DBSession.flush()
return request
user = relationship(AuthID, backref=backref('profile', uselist=False))
You are correct, overactive search and replace when fixing the docs.
Leaving this open until I get a chance to fix the docs and update the example