Friday, May 29, 2015

Re: Help with customizing Django authentication

Hi,

Try this views.py 

from django.contrib.auth import authenticate  user = authenticate(username='', password='secret')  if user is not None:      # the password verified for the user      if user.is_active:          print("User is valid, active and authenticated")      else:          print("The password is valid, but the account has been disabled!")  else:      # the authentication system was unable to verify the username and password      print("The username and password were incorrect.")

On Wednesday, May 27, 2015 at 9:24:59 PM UTC+5:30, Carlos Ribas wrote:
Hello All,

I am currently extending the existing User model to store additional information. So, basically I have:

# models.py
class Person(models.Model):
    user = models.OneToOneField(User, verbose_name=_('User'))
    zipcode = models.CharField(_('Zip Code'), max_length=9, blank=True, null=True)
    street = models.CharField(_('Address'), max_length=255, blank=True, null=True)
    ...

#admin.py
class PersonAdmin(admin.StackedInline):
    model = Person
    ...

class UserAdmin(UserAdmin):
    inlines = (PersonAdmin, )
    ...

admin.site.unregister(User)
admin.site.register(User, UserAdmin)   


The problem is that my system should be able to register a new person, but this person may not need an account on the system (I just need to have his/her information). Right now, I can not create a person without an account. Besides that, first_name and last_name fields are not in the person class. 

I am wondering what is the best solution for my case. Probably, I will need to move the first_name and last_name fields to the Person class, and to do that, I will have to create custom users, is that right? 

If that is the case, may I just copy and paste the lines shown here (https://github.com/django/django/blob/master/django/contrib/auth/models.py) and remove the lines about first_name and last_name? 

Well, any help will be appreciated.  


Confidentiality Notice: The above information contained in this email is intended for the confidential use of the above-named recipient(s). If a reader of this message is not the intended recipient or person responsible for delivering it to the intended recipient, you are hereby notified that you have received this communication in error, and that any review, dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this in error, please notify the sender immediately and destroy this message.**

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/14654226-722c-45c2-9692-997293f4dcf2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment