django-authentication

Modifying Django UserCreationForm

耗尽温柔 提交于 2019-12-30 00:38:11
问题 I wanted to add more fields to the standard Django UserCreationForm so I went ahead and subclassed it inside of my app's forms.py file and ended up with this: class CustomUserCreationForm(UserCreationForm): email = forms.EmailField(label = "Email") first_name = forms.CharField(label = "First name") last_name = forms.CharField(label = "Last name") class Meta: model = User fields = ("first_name", "last_name", "username",) def save(self, commit=True): user = super(CustomUserCreationForm, self)

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

回眸只為那壹抹淺笑 提交于 2019-12-29 04:48:07
问题 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 allauth.account.signals import email_confirmed from django.dispatch import receiver from django.contrib.auth.models import User @receiver(email_confirmed) def email_confirmed_(request, email_address, **kwargs): user = User.objects.get(email=email_address)

why django inbuilt auth views not recognizing the customized form?

青春壹個敷衍的年華 提交于 2019-12-25 07:31:20
问题 I understand that when we need to make the django inbuilt views, parameter specification should be made before the inbuilt view function could use it. now I want to customize the form for django auth view password_reset_confirm and in the url, I import my customized form from Myapp.forms import PasswordSetForm from django.contrib.auth import urls,views and for the url url(r'^accounts/ ^reset/(?P<uidb36>[0-9A-Za-z]{1,13})-(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$ ', 'django.contrib.auth

How to save the users last logout time

爷,独闯天下 提交于 2019-12-24 21:24:58
问题 I am looking to save the users last logout time.My idea was to add it to the users profile model. I am using Django 1.11.15 Example: class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) ... last_logout = models.DateTimeField(blank=True, null=True) below is how I created my profile model just for reference def signup(request): if request.method == 'POST': form = UserCreateForm(request.POST or None) if form.is_valid(): new_user = form.save() Profile.objects

Django request.method automatically set to GET and not POST

本秂侑毒 提交于 2019-12-24 19:13:54
问题 I'd like to setup an LDAP Authentication Backend in Django, and I've already used ldap3 to confirm a bind, with success. I'm now realising that writing a class for my LDAP Backend with just ldap3 is not so straightforward, and that installing django_auth_ldap could be another route to explore. I've tested already some code to create a bind to the LDAP "server", and then perform a simple search. All okay. This method I tested is outside of my Django framework. When implementing the same method

FieldError: Local field 'password' in class 'User' clashes with field of similar name from base class 'AbstractBaseUser'?

五迷三道 提交于 2019-12-24 14:36:08
问题 I am using Django 1.5. I have the following model: class User(AbstractBaseUser): #id = models.IntegerField(primary_key=True) #identifier = models.CharField(max_length=40, unique=True, db_index=True) username = models.CharField(max_length=90, unique=True, db_index=True) create_time = models.DateTimeField(null=True, blank=True) update_time = models.DateTimeField(null=True, blank=True) email = models.CharField(max_length=225) password = models.CharField(max_length=120) external = models

Authenticating a custom user in Django 1.5

心不动则不痛 提交于 2019-12-24 03:25:54
问题 I have a custom user in a Django 1.5 project, which uses the email field as the username: class MyUser(AbstractUser): my_custom_field = models.CharField(max_length=20, blank=True, null=True) USERNAME_FIELD = 'email' MyUser._meta.get_field_by_name('email')[0]._unique = True MyUser.REQUIRED_FIELDS.remove('email') If I try to authenticate that user like so: auth_user = authenticate(username=email, password=password) login(request, auth_user) I get this: Traceback: File "/Users/user/dev/proj/app

Custom response for invalid token authentication in Django rest framework

不羁岁月 提交于 2019-12-24 00:23:56
问题 For the following piece of code, I would like to return a boolean corresponding to whether the user was authenticated or not. class UserAuthenticatedView(APIView): authentication_classes = (TokenAuthentication,) permission_classes = (AllowAny,) def get(self, request, format=None): is_authenticated = request.user.is_authenticated() resp = {'is_authenticated': is_authenticated} return Response(resp, content_type="application/json", status=status.HTTP_200_OK) However, for invalid token, the

Django REST HTTP 400 Error on Getting Token Authentication View

别说谁变了你拦得住时间么 提交于 2019-12-23 19:31:09
问题 I want to use Django with Django-REST frameowrk on backend to authenticate users on Native android app. I am currently using Token based auth system. (More details) I have implemented exact same procedure listed by the guide, to setup up the Token Authentication. Now I want my user to be able to obtain token in exchange for credentials. I use make a POST request using following code: JSONObject cred = new JSONObject(); try { cred.put("password",mPassword); cred.put("username",mEmail); } catch

Django ver 1.7 AppRegistryNotReady: Models aren't loaded yet

五迷三道 提交于 2019-12-23 09:04:44
问题 I am trying to work through the authentication tutorials to make sure everything works as expected. I entered the following code. >>> from django.contrib.auth.models import User >>> user = User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword') >>> user.last_name = 'Lennon' >>> user.save() and I get the error AppRegistryNotReady: Models aren't loaded yet. I see from the release notes The default implementation of remove() for ForeignKey related managers changed from a series