django-authentication

Django: How to login user directly after registration using generic CreateView

◇◆丶佛笑我妖孽 提交于 2019-11-28 21:43:15
With django generic CreateView I can create a new user account, but how can I login this user automatically after registration using this technique? urls.py ... url( r'^signup/$', SignUpView.as_view(), name = 'user_signup' ), ... views.py class SignUpView ( CreateView ) : form_class = AccountCreationForm template_name = 'accounts/signup.html' success_url = reverse_lazy( 'home' ) forms.py class AccountCreationForm ( forms.ModelForm ) : def __init__( self, *args, **kwargs ) : super( AccountCreationForm, self ).__init__( *args, **kwargs ) for field in self.fields : self.fields[field].widget.attrs

(Django) Sharing authentication across two sites that are on different domains

自作多情 提交于 2019-11-28 21:27:46
问题 I have two sites say foo.com and bar.com and are both Django based. Primary registration occurs on foo.com (I'd like the main user db to be here) and I'd like for three things to happen: 1) User that logs in to foo.com is automatically able to access bar.com without logging in again 2) User that logs in to bar.com directly is authenticated against foo.com user db. 3) There is no need for a user to register at bar.com directly. How can I achieve this? If it greatly simplifies things I can make

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

ⅰ亾dé卋堺 提交于 2019-11-28 21:26:26
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(null=True, blank=True) purged = models.IntegerField(null=True, blank=True) username = models.CharField(max

django - set user permissions when user is automatically created

人盡茶涼 提交于 2019-11-28 20:02:06
问题 Django 1.5, python 2.6 The model automatically creates a user under certain conditions: User.objects.get_or_create(username=new_user_name, is_staff=True) u = User.objects.get(username=new_user_name) u.set_password('temporary') In addition to setting the username, password, and is_staff status, I would like to set the user's permissions - something like: u.user_permissions('Can view poll') or u.set_permissions('Can change poll') Is this possible? Thank you! 回答1: Use add and remove methods:

How can make Django permission_required decorator not to redirect already logged-in users to login page, but display some message

让人想犯罪 __ 提交于 2019-11-28 19:39:08
How can make Django permission_required decorator not to redirect already logged-in users to login page, but display some message like Insufficient permissions? Thank you. A quick and dirty solution would be to write your own decorator to do this. Something like this: decorator_with_arguments = lambda decorator: lambda *args, **kwargs: lambda func: decorator(func, *args, **kwargs) @decorator_with_arguments def custom_permission_required(function, perm): def _function(request, *args, **kwargs): if request.user.has_perm(perm): return function(request, *args, **kwargs) else: request.user.message

Best way to add convenience methods to a Django Auth User model?

☆樱花仙子☆ 提交于 2019-11-28 18:45:37
I want to add a convenience/model method to the django.contrib.auth.models.User model. What is the best practice for doing this since, last time I checked, extending the User model was considered bad practice. I have a separate custom UserProfile model. Should I be using that for all User-related convenience methods? It depends what you are trying to add to the model. If you want to add more information about the user, then it is generally recommended that you use the UserProfile method: http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users However, if

django-object-permissions Vs django-guardian Vs django-authority

允我心安 提交于 2019-11-28 18:39:46
问题 I've found 3 row-level permission solutions for Django 1.2+ django-object-permissions django-guardian django-authority Could someone tell if there is any recommended more than the others, what are their main differences, etc.? 回答1: I'll start this by saying we use none of these for object level permission - we use our own custom method and I really wish we hadn't. If you can avoid object level permissions at all, do so, they are a pain to organise. This is how I evaluate the 3 apps you've

Django create custom UserCreationForm

六眼飞鱼酱① 提交于 2019-11-28 18:23:30
I enabled the user auth module in Django, but when I use UserCreationForm he ask me only username and the two password/password confirmation fields. I want also email and fullname fields, and set to required fields. I've done this: from django.contrib.auth.forms import UserCreationForm from django import forms from django.contrib.auth.models import User class RegisterForm(UserCreationForm): email = forms.EmailField(label = "Email") fullname = forms.CharField(label = "Full name") class Meta: model = User fields = ("username", "fullname", "email", ) Now the form show the new fields but it doesn

Log in user using either email address or username in Django

余生长醉 提交于 2019-11-28 16:43:59
I am trying to create an auth backend to allow my users to log in using either their email address or their username in Django 1.6 with a custom user model. The backend works when I log in with a user name but for some reason does not with an email. Is there something I am forgetting to do? from django.conf import settings from django.contrib.auth.models import User class EmailOrUsernameModelBackend(object): """ This is a ModelBacked that allows authentication with either a username or an email address. """ def authenticate(self, username=None, password=None): if '@' in username: kwargs = {

Manually logging in a user without password

六月ゝ 毕业季﹏ 提交于 2019-11-28 15:27:43
I hope you can help me figure the best way to implement a manual (server-side initiated) login without using the password. Let me explain the workflow: User registers Thank you! An email with an activation link has been sent blablabla (Account now exists but is marked not enabled) User opens email, clicks link (Account is enabled) Thank you! You can now use the site What I'm trying to do is log in the user after he has clicked the email link so he can start using the website right away. I can't use his password since it's encrypted in the DB, is the only option writing a custom authentication