On Tue, Nov 4, 2008 at 11:39 AM, Gabriel Rossetti < [EMAIL PROTECTED]> wrote:
> > Gabriel Rossetti wrote: > > Hello everyone, > > > > I'm trying to get a custom auth handler to work but I keep on getting > > this error when accessing request.user.get_profile() : > > > > DoesNotExist: User matching query does not exist. > > > > I followed the following tutorials : > > > > http://garage.pimentech.net/mdm_src_dj_auth_documentation/ > > > http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/ > > > > Here is my auth handler : > > > > from proj.app.models import User as MyUser > > from django.contrib.auth.models import User, check_password > > > > def authenticate(self, username=None, password=None): > > try: > > myUser = MyUser.objects.get(email=username) > > except MyUser.DoesNotExist: > > return None > > pwdValid = check_password(password, myUser.password) > > if(pwdValid): > > try: > > user = User.objects.get(username=username) > > except User.DoesNotExist: > > user = User(username=username, > > email=username, > > first_name=myUser.firstName, > > last_name=myUser.lastName, > > password="none") > > user.is_staff = False > > user.is_superuser = False > > user.save() > > myUser.user = user # Not sure if this is really needed, > > I tried it since it didn't work and it still doesn't > > myUser.save() # Not sure if this is really needed, I > > tried it since it didn't work and it still doesn't > > return user > > return None > > > > def get_user(self, userId): > > try: > > return User.objects.get(pk=userId) > > except User.DoesNotExist: > > return None > > > > here is my model : > > > > from django.db import models > > from django.contrib.auth.models import User as DjangoUser > > > > class User(models.Model): > > id = models.AutoField(primary_key=True) > > firstname = models.CharField(maxlength=20) > > lastname = models.CharField(maxlength=20) > > email = models.CharField(maxlength=50) > > password = models.CharField(maxlength=20) > > user = models.ForeignKey(DjangoUser, unique=True) > > #user = models.OneToOneField(DjangoUser, core=True) # This doesn't > > work either > > > > I really don't see why it doesn't work...does anyone have a clue? > > > > Thank you, > > Gabriel > > > > PS I've already looked at past posts on the subject but the common > > answer is to create the profile, but in my case it's already created, > > maybe I'm linking it wrong? > > > > > Am I getting no responses because : > > 1) I missing something obvious > 2) I said something wrong > 3) The answer is so simple that no one wants to take the time to write it > 4) No one has a clue > 5) No on has the time > 6) Another reason not listed here > > It's a pretty safe bet that mostly people don't have the time for a question that is sufficiently complicated/confusing to require more than a simple answer. From a high level it isn't immediately obvious how a custom authenticate method can cause get_profile() to fail -- get_profile knows nothing of custom authentication. The error you are getting means that for whatever user ID you are attempting get_profile() on, there is no record in your custom User table (btw I find it confusing to name more than one model the same thing and I think you are asking for trouble when you forget the "as <whatever>User" on your import of User somewhere) with that ID. Looking at your custom authenticate, however, does provide some clues as to what might have gone wrong -- you are doing more in authenticate than just authenticating. It appears you are auto-creating django.contrib.auth.models.User objects to match your existing custom User objects. The lines you have that set the 'user' field in a custom User object and save it are necessary to link your custom User to the associated Django user model, but from the comments it appears you did not have them there initially. Thus you may have created some number of Django user objects without having set the appropriate value in the associated custom user model. Adding those lines after-the-fact won't fix the existing custom User models that don't have the proper values set in the user field, since on a 2nd run through of the same code you won't fall into the except UserDoesNotExist case since you created the User on the first go-round. So, check the values for the user column in your custom user table. Based on the error you are getting they don't appear to be correct and the code as you have it won't fix that. Karen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---