django-authentication

Django, TastyPie, Authentication, and custom middleware headache

a 夏天 提交于 2019-12-23 02:46:11
问题 I have a Django web application which requires authentication across the whole site. I've accomplished that with custom middleware which basically test if request.user.is_anonymous and, if they are, redirects them to the login page. It looks like this: from django.contrib.auth.views import login from django.contrib.auth import authenticate from django.http import HttpResponseRedirect, HttpResponse from django.utils import simplejson from django.core import serializers class SiteLogin: "This

Custom Authentication for non-user connection with Django Rest Framework

前提是你 提交于 2019-12-22 06:57:29
问题 I have enabled user authentication with DRF using TokenAuthentication REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.TokenAuthentication', 'rest_framework.authentication.SessionAuthentication' ), 'DEFAULT_MODEL_SERIALIZER_CLASS': 'rest_framework.serializers.ModelSerializer', 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.permissions.AllowAny', ), #'EXCEPTION_HANDLER': 'apps.core.exceptions.custom_exception_handler' } I have the following model: class

How do I use the The login_required decorator in my URL?

∥☆過路亽.° 提交于 2019-12-21 07:03:00
问题 I want to check that the user is authorized for certain URLs. I'm using generic views. The docs here say the login_required can be passed as an optional arguments but I'm not sure. Something like this maybe: (r'^$', 'archive_index', link_info_dict, 'coltrane_link_archive_index', login_required=True,), I have this and I would like to be able to use the login_required decorator within the URL. Is it possible? How can I do it? from django.conf.urls.defaults import * from coltrane.models import

Django 1.8 LookupError AUTH_USER_MODEL

六眼飞鱼酱① 提交于 2019-12-21 05:16:06
问题 I'm using a custon user model as such in my app called fowl . When I run syncdb or makemigrations or migrate I get a LookupError . Please help In settings.py I have defined AUTH_USER_MODEL as 'fowl.User' fowl/models.py from django.db import models from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, BaseUserManager from django.utils import timezone from django.core.mail import send_mail from django.utils.translation import ugettext_lazy as _ class UserManager

Django automatic login after user registration (1.4)

霸气de小男生 提交于 2019-12-21 05:00:54
问题 I have an issue where I am successfully registering users - however, I want users to be logged in on registration. Here is the code that represents my registration view. Any thoughts on why the user is not auto-logged in? Notes: The user is being registered correctly, they can log in after this authenticate(**kwargs) is returning the correct user In settings.py I have: AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend',) Thanks! def register(request): user_creation_form =

Object of type 'AuthToken' is not JSON serializable

左心房为你撑大大i 提交于 2019-12-21 04:54:24
问题 I'm getting the above error when creating token, here's the code: from rest_framework import generics, permissions from rest_framework.response import Response from knox.models import AuthToken from .serializers import UserSerializer, RegisterSerializer class RegisterAPI(generics.GenericAPIView): serializer_class = RegisterSerializer def post(self, request, *args, **kwargs): serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) user = serializer.save()

RelatedObjectDoesNotExist: User has no userprofile

喜你入骨 提交于 2019-12-20 20:18:15
问题 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 the recommended way. Then I tried to access the user's userprofile in my views: views.py: player = request.user.userprofile which seemed to align with the recommended way as well, but that is where I get my error: RelatedObjectDoesNotExist User has no

Django AUTHENTICATION_BACKENDS import error

限于喜欢 提交于 2019-12-20 19:47:29
问题 What is the proper way to import a custom backend in settings.py? I currently have the following in settings.py: AUTHENTICATION_BACKENDS = ('apps.apployment_site.auth.CustomAuth') where apployment_site is the app, auth is file name, and CustomAuth is the class name. In my view, I get: ImportError: a doesn't look like a module path after I run the following code: from django.contrib.auth import authenticate from apployment_site import * authenticate(username="username", password="password")

Django authentication - wrong redirect url to login page

余生长醉 提交于 2019-12-20 10:28:22
问题 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/',

Getting `django-registration` to send you to the page you were originally trying to visit

怎甘沉沦 提交于 2019-12-20 10:07:22
问题 django.contrib.auth has an awesome feature: When you try to access a page that's decorated by login_required , you get redirected to the login page with a next argument, so after you login you get redirected back to the page you were originally trying to access. That's good for the user flow. But, apparently django-registration does not provide a similar feature. I expected that if you register instead of login, you would also get a next thing, and after registering-n'-activating you'll get