def send_confirmation_task(data_obj): data_obj['context']['current_site'] = Site.objects.get_current() user = User.objects.get(id=data_obj['context']['user']) data_obj['context']['user'] = user data_obj['context']['name'] = user.get_full_name().title() msg = DefaultAccountAdapter().render_mail(data_obj['template_prefix'], data_obj['email'], data_obj['context']) msg.send()
def clean_username(self, username): print('THIS IS A TEST OF CLEAN USERNAME') if len(username) > 0: raise ValidationError( 'Please enter a username value less than the current one') return DefaultAccountAdapter.clean_username( self, username) # For other default validations.
def clean_username(self, username): if len(username) > USERNAME_MAX_LENGTH: raise ValidationError( f'Please enter a username less than {USERNAME_MAX_LENGTH + 1}') # For other default validations. return DefaultAccountAdapter.clean_username(self, username)
def save_user(self, request, user, form, commit=True): # Automatically create a group for the user. user = DefaultAccountAdapter.save_user(self, request, user, form, commit=True) group = Group.objects.create(name=user.username) group.save() user.groups.add(group) user.save() return user
def clean_username(self, username, shallow=None): print("aaaa", type(len(username))) if len(username) > 30: raise ValidationError( 'Please enter a username value less than the current one') # For other default validations. return DefaultAccountAdapter.clean_username(self, username)
def clean_username(self, username, shallow=False): zh_pattern = re.compile(u'[\u4e00-\u9fa5]+') username = str(username) result = zh_pattern.search(username) if result: raise forms.ValidationError(('用户名不能为中文'),code = 'invalid') return DefaultAccountAdapter.clean_username(self, username, shallow=shallow)
def save(self, request): self.cleaned_data["email"] = self.email DefaultAccountAdapter().stash_verified_email(request, self.email) # Possible problem: this causes the user to be saved twice. # If we want to save it once, we should override the Allauth method. # See https://github.com/pennersr/django-allauth/blob/master/allauth/account/forms.py#L401 user = super().save(request) user = self.invitation.set_guest_type(user) user.save() return user
def save_user(self, request, user, form): if not request.user.admin: raise PermissionDenied() user.email = request.data.get('email') user.admin = request.data.get('admin') user.passwordChange = True user.newIssueNotifications = True return DefaultAccountAdapter.save_user( self, request, user, form) # For other default validations.
def clean_username(self, username): if len(username) > 20: raise ValidationError( 'Please enter a username value less than the current one') return DefaultAccountAdapter.clean_username(self, username) # class RestrictEmailAdapter(DefaultAccountAdapter): # def clean_email(self,email): # RestrictedList = ['Your restricted list goes here.'] # if email in RestrictedList # raise ValidationError('You are restricted from registering. Please contact admin.') # return email
def new_user(request, invitation_type, invitation_id, template_name="invitations_views/new_user.html"): invitation_type = InvitationAbstract.get_model_from_string(invitation_type) invitation = get_object_or_404(invitation_type, pk=invitation_id) context = {"invitation": invitation} next_step = None if request.user.is_authenticated: if not request.user.email == invitation.email: message = ( "Un utilisateur précédent est déjà connecté.<br>" "Veuillez déconnecter ce compte en cliquant sur le bouton ci-dessous " "(ne tenez pas compte de la page d'accueil qui se chargera automatiquement) " "puis cliquez de nouveau sur le lien envoyé par e-mail pour accepter votre invitation." ) message = safestring.mark_safe(message) messages.error(request, _(message)) return redirect("account_logout") if invitation.can_be_accepted: user = get_user_model().objects.filter(email=invitation.email) if not user: form = NewUserForm(data=request.POST or None, invitation=invitation) context["form"] = form if form.is_valid(): user = form.save(request) DefaultAccountAdapter().login(request, user) next_step = redirect(get_safe_url(request, "redirect_to")) else: next_step = "{}?account_type={}&next={}".format( reverse("account_login"), invitation.SIGNIN_ACCOUNT_TYPE, get_safe_url(request, "redirect_to")) next_step = redirect(next_step) return next_step or render(request, template_name, context=context)
def clean_username(self, username): if len(username) > 8: raise ValidationError( 'Please enter a username value less than the current one') # For other default validations. return DefaultAccountAdapter.clean_username(self, username)
def clean_username(self, username, shallow=False): if len(username) >= 15: raise ValidationError( 'Please enter a username less than 15 characters') return DefaultAccountAdapter.clean_username( self, username) # For other default validations.
def clean_username(self, username): if len(username) > 10: raise ValidationError( "Please enter an username of maximum 10 characters") return DefaultAccountAdapter.clean_username(self, username)
def clean_password(self, password, user=None): if password.isdigit(): raise forms.ValidationError(('密码不能全为数字'),code = 'invalid') return DefaultAccountAdapter.clean_password(self, password, user=user)
def clean_password(self, password, user=None): if len(password) > 20: raise ValidationError( 'Please Enter a password greater that you can remember.') return DefaultAccountAdapter.clean_password(self, password)
def clean_username(self, username): if len(username) > settings.USERNAME_MAX_LENGTH: raise ValidationError('Max username length is eight charactors') # For other default validations. return DefaultAccountAdapter.clean_username(self, username)
# -*- coding: utf-8 -*- from __future__ import absolute_import, unicode_literals from django.contrib.auth import get_user_model from django.conf import settings from django.utils.translation import ugettext_lazy as _ from rest_framework import serializers, exceptions from rest_auth.serializers import LoginSerializer as RALoginSerializer from allauth.account.adapter import DefaultAccountAdapter # Get the UserModel UserModel = get_user_model() adapter = DefaultAccountAdapter() class UserDetailsSerializer(serializers.ModelSerializer): """ User model w/o password """ class Meta: model = UserModel fields = ('email', 'first_name', 'last_name') read_only_fields = ('email', ) class JWTSerializer(serializers.Serializer): """ Serializer for JWT authentication. """ token = serializers.CharField()