django-authentication

User authentication with mobile number and OTP in Django 1.7

走远了吗. 提交于 2019-12-13 00:42:07
问题 I have two types of users. - Customer. - Vendor. For Customers, I've already created custom user class where login happens through email and password. But, Vendors do not have email id and password. All vendor accounts are manually created by the django admin. Vendor class looks like this. class Vendor(): phone = models.CharField(max_length=12, unique=True, required=True) name = models.CharField() . . What's the best way to implement OTP login for Vendors? Vendors usually login through an

Automatically select related for OneToOne field

ⅰ亾dé卋堺 提交于 2019-12-12 10:54:24
问题 In my Django project I have a Profile for each django User, and the Profile is related to an Info model. Both relationships are OneToOne. Since most of the time I am using both the Profile and the Info models for a user, I would like those to be selected by default so I don't hit the database again. Is there any way to do this using Django authentication? 回答1: I know this has been here for a while but I am adding my solution in case someone else faces a similar situation. Django (as of v1.8

Prevent social account creation in allauth

丶灬走出姿态 提交于 2019-12-12 09:43:51
问题 Is it possible to prevent account creation under certain circumstances in allauth, preferably using the pre_social_login signal? 回答1: With the current development branch you can easily do this. In your settings: SOCIALACCOUNT_ADAPTER = 'my.adapter.MySocialAccountAdapter' Then use this adapter.py: from django.http import HttpResponse from allauth.socialaccount.adapter import DefaultSocialAccountAdapter from allauth.exceptions import ImmediateHttpResponse class MySocialAccountAdapter

Django Auth Token ValueError When Assigning to User

落爺英雄遲暮 提交于 2019-12-12 06:28:39
问题 I'm currently following the Django guide and using the receiver to assign an auth token. However, the following retuens the error Cannot assign "<User: User object>": "Token.user" must be a "User" instance. ##PRE CREATE Method @receiver(post_save, sender=User) def create_auth_token(sender, instance=None, created=False, **kwargs): if created: Token.objects.create(user=instance) class UserViewSet(viewsets.ModelViewSet): queryset = User.objects.all() serializer_class = UserSerializer Even

Django- why inbuilt auth login function not passing info about user to after successful login url

大兔子大兔子 提交于 2019-12-12 05:51:37
问题 Hi I used the django inbult auth urls and views for my project and now have finished the initial user account creation/login/reset password process. Now, the user can log in and be redirected to the after successful login url accounts/profile/. I have several doubts on the django login function. For convenience, I've copy paste the django inbuilt login function code below. @sensitive_post_parameters() @csrf_protect @never_cache def login(request, template_name='registration/login.html',

Django: Session created in database when login page loaded

[亡魂溺海] 提交于 2019-12-12 04:47:17
问题 My django_session table was growing very large and it seems to be due to a pingdom bot that I set-up hitting my login page. I tried creating a brand new django 1.4 app and the behaviour is replicated on any page that uses the django.contrib.auth.views.login page, including the default admin login page. This surely can't be the desired behaviour. Is it a bug? Is there a fix? (I have redirected the pingdom bot to another page that doesn't cause a new session to be created but I'd like to solve

Is there a way to add custom code to login_required

岁酱吖の 提交于 2019-12-12 04:04:47
问题 I've made my own LoginRequiredMixin like this: class LoginRequiredMixin(object): @classmethod def as_view(cls, **initkwargs): view = super(LoginRequiredMixin, cls).as_view(**initkwargs) # (!!) multilangue = reverse_lazy, PAS reverse return login_required(view, login_url=reverse_lazy('my_home_login')) So far so good, everything works fine when you create new views like this: class EditView(LoginRequiredMixin, generic.UpdateView): model = Personne template_name = 'my_home/profile/base.html'

Custom user models in Django: `no such table: auth_user`

强颜欢笑 提交于 2019-12-12 02:19:15
问题 According to the answer to my previous question, I edited the django-registration module with the following modifications: in myapp/models.py : from django.contrib.auth.models import UserManager from django.contrib.auth.models import AbstractUser class AccountManager(UserManager): def create_user(self, email, password=None, **kwargs): if not email: raise ValueError('Users must have a valid email address.') if not kwargs.get('username'): raise ValueError('Users must have a valid username.')

Django ) 'authenticate' with the user model retrieved by the foreign model

╄→гoц情女王★ 提交于 2019-12-12 01:47:45
问题 I'm developing 'email verification' module. First of all, I have a model named 'SNUser' having 'One To One' relationship with the default 'user' model below : class SNUser(models.Model): # Manager objects = SNUserManager() # Auth user = models.OneToOneField(User, unique=True, primary_key=True) I finished sending email containing the unique token for an user. When the link is clicked, I searched the correct SNUser object by the token.(That token is one of the field of SNUser model). So what I

Correct way to extend AbstractUser in Django?

耗尽温柔 提交于 2019-12-12 01:38:04
问题 I'm trying to integrate two django apps where each had their individual auths working. To do that, I'm trying to subclass AbstractUser instead of User. I'm following the PyBB docs and Django#substituting_custom_model. I've removed all migration files in all my apps apart from their individual init .py (including the migrations from the PyBB library sitting in my site-packages). I've also changed the Mysql database to a blank one to start afresh and I'm trying to subclass AbstractUser as shown