django-authentication

Enforcing password strength requirements with django.contrib.auth.views.password_change

拈花ヽ惹草 提交于 2019-11-28 15:18:39
问题 We have a Django application that requires a specific level of password complexity. We currently enforce this via client-side JavaScript which can easily be defeated by someone who is appropriately motivated. I cannot seem to find any specific information about setting up server-side password strength validation using the django contrib built in views. Before I go about re-inventing the wheel, is there a proper way to handle this requirement? 回答1: I also went with a custom form for this. In

NoReverseMatch Error

淺唱寂寞╮ 提交于 2019-11-28 08:54:35
I keep getting this error for the django login system. Here is part of my urls.py: (r'^contractManagement/login', 'django.contrib.auth.views.login', {'template_name': 'login.html'}), The exact error I am getting: Exception Type: NoReverseMatch Exception Value: Reverse for ''django.contrib.auth.views.login'' with arguments '()' and keyword arguments '{}' not found. I can't understand why i am getting this error. If you need anything else let me know. You don't show where you are trying to reverse this URL, but it looks like you have double-quoted it. If you're using the url tag, note that you

Get user information in django templates

落爺英雄遲暮 提交于 2019-11-28 06:44:40
What's the best way to get user information from a django template? For example, if I just want to: If the user is logged in, display "Welcome [username]" Otherwise, display the login button. I'm using django-registration/authentication An alternate method for current Django versions: {% if user.is_authenticated %} <p>Welcome, {{ user.get_username }}. Thanks for logging in.</p> {% else %} <p>Welcome, new user. Please log in.</p> {% endif %} Note: Use request.user.get_username() in views & user.get_username in templates. Preferred over referring username attribute directly. Source This template

Django: Why create a OneToOne to UserProfile instead of subclassing auth.User?

删除回忆录丶 提交于 2019-11-27 20:50:20
Note: If you are tempted to 'answer' this question by telling me that you don't like django.contrib.auth, please move on. That will not be helpful. I am well aware of the range and strength of opinions on this matter. Now, the question: The convention is to create a model, UserProfile, with a OneToOne to User. In every way I can think of, a more efficient and effective approach is to subclass User to a class that one intends to use for every human in the system - a class called, say, Person(User). I have not seen a coherent explanation of why the former is conventional and the latter is

decide where to go to after connecting with django-allauth

巧了我就是萌 提交于 2019-11-27 18:51:59
问题 After connecting an account with a social app using django-allauth the user is redirected to accounts/social/connections . How can I change this behavior? 回答1: If the user is adding more social accounts to his existing (local) account, then the most logical default would be indeed to redirect to the social account connections management screen. However, you can easily override the default by passing along a next parameter. Have a look here: https://github.com/pennersr/django-allauth/blob

Django How to prevent multiple users login using the same credentials

こ雲淡風輕ζ 提交于 2019-11-27 18:23:03
问题 I am developing an Django application using django auth module and would like to prevent multiple login using the same user name and password. It should prevent multiple logins on different machines using the same user name and password. How do I achieve this in Django? We have to keep following things in mind: If user close the browser without logging out If the session times out 回答1: You may try this, it logs out the first user and logs in the second. Add middleware.py in your app directory

Django's self.client.login(…) does not work in unit tests

℡╲_俬逩灬. 提交于 2019-11-27 17:47:21
I have created users for my unit tests in two ways: 1) Create a fixture for "auth.user" that looks roughly like this: { "pk": 1, "model": "auth.user", "fields": { "username": "homer", "is_active": 1, "password": "sha1$72cd3$4935449e2cd7efb8b3723fb9958fe3bb100a30f2", ... } } I've left out the seemingly unimportant parts. 2) Use 'create_user' in the setUp function (although I'd rather keep everything in my fixtures class): def setUp(self): User.objects.create_user('homer', 'ho...@simpson.net', 'simpson') Note that the password is simpson in both cases. I've verified that this info is correctly

Django Authenticate Backend Multiple Databases

可紊 提交于 2019-11-27 17:00:05
问题 I am rewriting a legacy application that has a database for each customer. Each customer has its own authentication and user set. Thus, I'll need a custom authentication backend because django's auth is set to only use default. I have written middleware that examines the url upon every request and extracts information there to set a database_name on the request. If I had access to the request during processing of my custom authencation backend, I could easily perform database calls as user =

AttributeError: 'Manager' object has no attribute 'get_by_natural_key' error in Django?

≯℡__Kan透↙ 提交于 2019-11-27 13:58:47
问题 I am using Django '1.5c1' . I have this line in my settings.py: AUTH_USER_MODEL = 'fileupload.galaxyuser' Here's my Galaxyuser model: class GalaxyUser(models.Model): id = models.IntegerField(primary_key=True) create_time = models.DateTimeField(null=True, blank=True) update_time = models.DateTimeField(null=True, blank=True) email = models.CharField(max_length=765) password = models.CharField(max_length=120) external = models.IntegerField(null=True, blank=True) deleted = models.IntegerField

Django - user permissions to certain views?

倾然丶 夕夏残阳落幕 提交于 2019-11-27 13:38:38
问题 From the admin I see that you can allocate permissions to a user or a user group to :allow add, change or delete data from a model. That is great, but I also need to allow a user or a user group to access or not a group of views. I have certain type of services on my web site so I want to allow some users to access a certain services (pages/views) but not others. So how can I allow certain users/user groups access to certain views? Thank you! 回答1: Users that cannot add or change etc. a