Questions tagged [django-authentication]

django-authentication refers to the built-in auth module for authentication & authorization that can be extended.

django-authentication refers to the built-in auth module for authentication & authorization that can be extended. It handles user accounts, groups, permissions and cookie-based user sessions.

See documentation.

1888 questions
23
votes
3 answers

Allowing only single active session per user in Django app

I want to restrict logged-in users to only have one active session, i.e. if the user logs in with a new sessionid, the old session should be terminated. I found a lot of help on SO already: here and here I implemented the middleware solution, with a…
23
votes
3 answers

How to pass Django request object in user_passes_test decorator callable function

I am using Django user_passes_test decorator to check the User Permission. @user_passes_test(lambda u: has_add_permission(u, "project")) def create_project(request): ...... I am calling a callback function has_add_permission which takes two…
Raunak Agarwal
  • 7,117
  • 6
  • 38
  • 62
22
votes
4 answers

Django auth: increasing max username length

I need to increase the max username size in auth to exceed the 30 chars defined in the model. How can it be done? I' m not sure that just customizing the model is the right or safe way.
GabiMe
  • 18,105
  • 28
  • 76
  • 113
22
votes
14 answers

RelatedObjectDoesNotExist: User has no userprofile

So I've extended my user with the field score like this: models.py: class UserProfile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) score = models.IntegerField(default=0); which seemed to be along the lines of…
MrJalapeno
  • 1,532
  • 3
  • 18
  • 37
22
votes
3 answers

How can I logout a user in Django?

Our Django deployment checks every night which active users can still be found in out LDAP directory. If they cannot be found anymore, we set them to inactive. If they try to login next time, this will fail. Here is our code that does this: def…
Torsten Bronger
  • 9,899
  • 7
  • 34
  • 41
22
votes
5 answers

Best way to add convenience methods to a Django Auth User model?

I want to add a convenience/model method to the django.contrib.auth.models.User model. What is the best practice for doing this since, last time I checked, extending the User model was considered bad practice. I have a separate custom UserProfile…
Soviut
  • 88,194
  • 49
  • 192
  • 260
21
votes
5 answers

Difference between User.objects.create_user() vs User.objects.create() vs User().save() in django

In the Django documentation, it uses User.objects.create_user() to create a user. I am confused, what is the difference between that and User.objects.create() and User().save() which are the normal ways to create objects of other models
ahmed osama
  • 430
  • 1
  • 5
  • 16
21
votes
6 answers

Register custom user model with admin auth

In a Django project, I have a custom user model that adds one extra field: class User(AbstractUser): company = models.ForeignKey(Company, null=True, blank=True) This model is defined in my app, say MyApp.models. How can I get the new User…
gozzilli
  • 8,089
  • 11
  • 56
  • 87
20
votes
2 answers

login Page by using django forms

I am New beginner in python and django... i want to know how can i create a login form by using django forms(forms.py)
Nikhil Verma
  • 241
  • 2
  • 3
  • 10
20
votes
3 answers

Suppress "?next=blah" behavior in django's login_required decorator

I love django's @login_required decorator, but there's one thing I can't figure out how to make it do. If an unauthenticated user tries visits a @login_required page (e.g. "/private-stuff/"), I want to kick them back to the home page (e.g.…
Abe
  • 22,738
  • 26
  • 82
  • 111
17
votes
4 answers

Multiple USERNAME_FIELD in django user model

My custom user model: class MyUser(AbstractBaseUser): username = models.CharField(unique=True,max_length=30) email = models.EmailField(unique=True,max_length=75) is_staff = models.IntegerField(default=False) is_active =…
Saurabh Verma
  • 6,328
  • 12
  • 52
  • 84
17
votes
2 answers

Django: How to login user directly after registration using generic CreateView

With django generic CreateView I can create a new user account, but how can I login this user automatically after registration using this technique? urls.py ... url( r'^signup/$', SignUpView.as_view(), name = 'user_signup'…
17
votes
2 answers

django auth - has_perm returns True while list of permissions is empty

I'm wondering why this code section prints out the following: print "request.user.has_perm('bug_tracking.is_developer'): " + str(request.user.has_perm('bug_tracking.is_developer')) print…
Thomas Kremmel
  • 14,575
  • 26
  • 108
  • 177
17
votes
2 answers

django-allauth: how to properly use email_confirmed signal to set user to active

In another post, I mentioned that I was trying to use allauth's email_confirmed signal to change the is_active field on the confirmed user to true. However, the following code gave me the exception "User matching query does not exist." from…
Gravity Grave
  • 2,802
  • 1
  • 27
  • 39
17
votes
2 answers

How to test login process?

I am developing a web application using Django 1.6 where I require users to log in using my login form. I want to write a test case that tests the procedure of a user logging in. I did succeed to get a working login page, meaning I was able to log…
moooeeeep
  • 31,622
  • 22
  • 98
  • 187