def form_valid(self, form): key = self.key if isinstance(key, HttpResponse): return key request = self.request address = request.META['REMOTE_ADDR'] password = form.cleaned_data['new_password1'] with transaction.atomic(), version(comment="email address confirmed"): key.user.confirmed = timezone.now() key.user.created_in_backend = True key.user.save() if request.user != key.user: logout(request) # logout any previous user key.user.backend = settings.AUTHENTICATION_BACKENDS[0] login(request, key.user) # Actually create the user on the XMPP server xmpp_backend.create_user(username=key.user.node, domain=key.user.domain, password=password, email=key.user.email) key.user.log(ugettext_noop('Email address %(email)s confirmed.'), address, email=key.user.email) # TODO: More meaningful help message on a webchat, usable clients, follow updates, ... messages.success(request, _( "Successfully confirmed your email address. You can now use your account.")) stat(STAT_REGISTER_CONFIRMED) # Delete the registration key key.delete() return super(ConfirmRegistrationView, self).form_valid(form)
def block_user(self, request, obj): with version(user=request.user, comment='Blocked via admin interface'): obj.block() # Block other users with the same normalized email address if obj.email: for user in User.objects.exclude(pk=obj.pk).filter(normalized_email=obj.normalized_email): user.block()
def block_user(self, request, obj): with version(user=request.user, comment='Blocked via admin interface'): obj.block() # Block other users with the same normalized email address if obj.email: for user in User.objects.exclude(pk=obj.pk).filter( normalized_email=obj.normalized_email): user.block()
def form_valid(self, form): request = self.request self.ratelimit(request) address = request.META['REMOTE_ADDR'] lang = request.LANGUAGE_CODE base_url = '%s://%s' % (request.scheme, request.get_host()) if BlockedEmail.objects.is_blocked(form.cleaned_data['email']): BlockedIpAddress.objects.block(address) raise BlockedException(_('You cannot register with this email address.')) with transaction.atomic(), version(comment='User created'): response = super(RegistrationView, self).form_valid(form) user = self.object # Compute the normalized email address user.normalized_email = normalize_email(user.email) # save default language user.default_language = lang user.save() # log user creation, display help message. user.log(ugettext_noop('Account created.'), address=address) AddressActivity.objects.log(request, ACTIVITY_REGISTER, user=user, note=user.email) stat(STAT_REGISTER) messages.success(request, _( """Successfully created the account %(username)s. A confirmation email was just sent to the email address you provided (%(email)s). Before you can use your account, you must click on the confirmation link in that email.""") % { 'username': user.username, 'email': user.email, }) user.backend = settings.AUTHENTICATION_BACKENDS[0] login(self.request, user) task = send_confirmation_task.si( user_pk=user.pk, purpose=PURPOSE_REGISTER, language=lang, address=address, to=user.email, base_url=base_url, hostname=request.site['NAME']) # Store GPG key if any fp, key = form.get_gpg_data() if fp or key: gpg_task = add_gpg_key_task.si( user_pk=user.pk, address=address, fingerprint=fp, key=key) task = chain(gpg_task, task) task.delay() return response