django-authentication

How to enable https in Django-auth generated pages?

拈花ヽ惹草 提交于 2019-12-03 06:18:47
问题 Using the Django-auth application (Django version 1.3), I want to have my login page go to https://mysite.com/login/ . Currently, I'm using: # urls.py from django.contrib.auth.views import login urlpatterns = patterns('', url(r'^login/$', login, name='login-view'),) # navbar.html <li id="nav-login"><a href="{% url login-view %}" ><b>Login</b></a></li> which works nicely, but goes to http://mysite.com/login/ . Is there some way to tell Django-auth what prefix (https) to use, when it reverses

How to manually authenticate after get django user?

心不动则不痛 提交于 2019-12-03 06:12:58
Im writing a facebook-connect app that login user after authenticate session on facebook, question is how can i authenticate user on django after get user object? user = User.objects.get(email=email) user = authenticate(username=user.username, password=user.password) login(request, user) Is there another way to achieve this ? You don't actually need to authenticate() first if you do this (but I didn't tell you!): user.backend = 'django.contrib.auth.backends.ModelBackend' login(request, user) There are two things you should look at and be aware of based on your question and example. First, the

Why second user login redirects me to /accounts/profile/ url?

北城余情 提交于 2019-12-03 04:15:19
I am using Django built in view for user login: url(r'^user/login/$', 'django.contrib.auth.views.login', {'template_name': 'users/templates/login.html'}, name='user-login'), After login when I goto user/login again I can login second time. I submit the form and getting: The current URL, accounts/profile/, didn't match any of these. I haven't declare this url in urls.py . What I am doing wrong? Why framework want to redirect to this url? Traian django.contrib.auth.views.login redirects you to accounts/profile/ right after you log in. You may want to set LOGIN_REDIRECT_URL inside your settings

Users in initial data fixture

霸气de小男生 提交于 2019-12-03 04:04:21
问题 I'm creating a few users by default in my fixtures/initial_data.json so as to have some testing "subjects." The problem I'm experiencing is password generation. I could set the password in the 'fields', but that won't generate a hashed password: [ { "model": "auth.user", "pk": 1, "fields": { "username": "user1", "password": "password" } } ] I need a way to generate the user's password. Do I have to do this manually and generate a string like {hash_method}${salt}${hashed_password} like Django

Django-AttributeError 'User' object has no attribute 'backend' (But…it does?)

穿精又带淫゛_ 提交于 2019-12-03 03:25:41
问题 In order to sign users in after registering them, I manually set the user.backend property. It normally works in my views. In this instance, I'm trying to register the user via AJAX. It is raising an AttributeError. Here is my code: def register_async(request): if request.method=='POST': userform=MyUserCreationForm(request.POST) if userform.is_valid(): #username of <30 char is required by Django User model. I'm storing username as a hash of user email user=userform.save(commit=False) user

Can I change Django's auth_user.username field to be 100 chars long without breaking anything?

二次信任 提交于 2019-12-03 03:07:46
Before somebody marks this question as a duplicate of this question Can django's auth_user.username be varchar(75)? How could that be done? or other such questions on SO, please read this question. The question I linked to asks this question precisely but unfortunately the answers don't address the question that was asked. Can I change the auth_user.username field to be 100 characters long by doing the following: Run ALTER table in DB for the username field Change the max_length here: username = models.CharField(_('username'), max_length=30, unique=True, help_text=_("Required. 30 characters or

Auto register Django auth models using custom admin site

允我心安 提交于 2019-12-03 01:43:36
I implemented authentication management using Django auth with the default admin site but then I wanted to use my own AdminSite to rewrite some behaviors: class OptiAdmin(admin.AdminSite): site_title = "Optimizer site's admin" #...Other stuff here Then registered my own models: admin_site = OptiAdmin(name='opti_admin') admin.site.register(MyModel, MyModelAdmin) #Other stuff here But when I go to the admin site I am only able to see the models I just registered, which sounds fair to me but I would like to see all the other apps models in this new custom site including the auth's users and

Multiple Django apps, shared authentication

时光毁灭记忆、已成空白 提交于 2019-12-02 23:48:14
Two answers to this question, depending on whether sharing is across different sites or different subdomains Second answer: Multiple Django apps, shared authentication A user goes to site1.com and logs in. Now, if he goes to site2.com, then he should already be logged in (authenticated) at that site. site1.com and site2.com are handled by different Django apps on the same sever. I get that the sites can share the database containing the authentication tables. What I don't get is how the session data is handled. After logging in to site1, the user goes to site2. Here he always has request.user

Most optimized way to delete all sessions for a specific user in Django?

若如初见. 提交于 2019-12-02 22:45:19
I'm running Django 1.3, using Sessions Middleware and Auth Middleware: # settings.py SESSION_ENGINE = django.contrib.sessions.backends.db # Persist sessions to DB SESSION_COOKIE_AGE = 1209600 # Cookies last 2 weeks Each time a user logs in from a different location (different computer/browser), a new Session() is created and saved with a unique session_id . This can result in multiple database entries for the same user. Their login persists on that node until the cookie is deleted or session expires. When a user changes their password, I want to delete all unexpired sessions for that user from

Django authentication - wrong redirect url to login page

萝らか妹 提交于 2019-12-02 22:44:16
When a user is not logged I'm trying to enter areas of site for authenticated users only I should be redirected to my login site with ?next= and here my LOGIN_REDIRECT_URL from settings. But instead of /users/login in my address bar /accounts/login is displayed. What should I change to get the right url ? settings : AUTH_PROFILE_MODULE = 'accounts.UserProfile' LOGIN_REDIRECT_URL = '/user/profile/' project's urls : import accounts.urls as regUrls urlpatterns = patterns("", (...) (r'^user/', include(regUrls)), ) accounts application urls.py : urlpatterns = patterns('', url(r'^profile/$', profile