Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def dispatch(self, request, *args, **kwargs):
try:
self.user = User.objects.get(
pw_reset_token=kwargs.get("token"),
pw_reset_time__gte=now() - dt.timedelta(days=1),
)
except User.DoesNotExist:
messages.error(self.request, phrases.cfp.auth_reset_fail)
return redirect(reverse("orga:auth.reset"))
return super().dispatch(request, *args, **kwargs)
def _clean_login(self, data):
try:
uname = User.objects.get(email__iexact=data.get("login_email")).email
except User.DoesNotExist: # We do this to avoid timing attacks
uname = "user@invalid"
user = authenticate(username=uname, password=data.get("login_password"))
if user is None:
raise ValidationError(
_(
"No user account matches the entered credentials. "
"Are you sure that you typed your password correctly?"
)
)
if not user.is_active:
raise ValidationError(_("Sorry, your account is currently disabled."))
def authenticate(self, *args, token=None, **kwargs):
if token:
with suppress(User.DoesNotExist, MultipleObjectsReturned):
return User.objects.get(auth_token__key__iexact=token)
return None
def clean(self):
data = super().clean()
try:
user = User.objects.get(email__iexact=data.get("login_email"))
except User.DoesNotExist:
user = None
data["user"] = user
return data
from pretalx.person.models import User
try:
ticket = TicketbutlerTicket.objects.filter(user__email__iexact=email, ticketbutler_orderid=ticketbutler_orderid).order_by('id')[0]
# Ensure that the user is marked as active in case of previous
# import bugs of if the user had a refund and got deactivated
ticket.user.is_active = True
ticket.ticketbutler_ticket_type_name = ticket_type_name
ticket.user.save()
ticket.save()
return ticket
except IndexError:
pass
try:
user = User.objects.get(email=email.lower())
except User.DoesNotExist:
user = User.objects.create_user(email=email.lower(), name=name)
return TicketbutlerTicket.objects.create(
user=user,
ticketbutler_orderid=ticketbutler_orderid,
sprints=sprints,
ticketbutler_ticket_type_name=ticket_type_name,
)
def form_valid(self, form):
created = not self.object
self.object = form.instance
self._questions_form.submission = self.object
if not self._questions_form.is_valid():
return self.get(self.request, *self.args, **self.kwargs)
form.instance.event = self.request.event
form.save()
self._questions_form.save()
if created:
email = form.cleaned_data["speaker"]
try:
speaker = User.objects.get(email__iexact=email) # TODO: send email!
messages.success(
self.request,
_(
"The submission has been created; the speaker already had an account on this system."
),
)
except User.DoesNotExist:
speaker = create_user_as_orga(
email=email,
name=form.cleaned_data["speaker_name"],
submission=form.instance,
)
messages.success(
self.request,
_(
"The submission has been created and the speaker has been invited to add an account!"
def dispatch(self, request, *args, **kwargs):
try:
self.user = User.objects.get(
pw_reset_token=kwargs.get("token"),
pw_reset_time__gte=now() - dt.timedelta(days=1),
)
except User.DoesNotExist:
messages.error(self.request, phrases.cfp.auth_reset_fail)
return redirect(
reverse("cfp:event.reset", kwargs={"event": kwargs.get("event")})
)
return super().dispatch(request, *args, **kwargs)