Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_context_data(self, **kwargs):
context = super(UserCRUDL.List, self).get_context_data(**kwargs)
context['groups'] = Group.objects.all()
group_id = self.request.POST.get('group_id', self.request.GET.get('group_id', 0))
context['group_id'] = int(group_id)
return context
def pre_process(self, request, *args, **kwargs):
token = self.kwargs.get('token')
validity_time = timezone.now() - timedelta(hours=48)
recovery_token = RecoveryToken.objects.filter(created_on__gt=validity_time, token=token)
if not recovery_token:
messages.info(request, _("Your link has expired for security reasons. "
"Please reinitiate the process by entering your email here."))
return HttpResponseRedirect(reverse("users.user_forget"))
return super(UserCRUDL.Recover, self).pre_process(request, args, kwargs)
from .views import Login, UserCRUDL
logout_url = getattr(settings, 'LOGOUT_REDIRECT_URL', None)
urlpatterns = [
url(
r'^login/$', Login.as_view(), dict(template_name='smartmin/users/login.html'),
name="users.user_login"
),
url(
r'^logout/$', LogoutView.as_view(), dict(redirect_field_name='go', next_page=logout_url),
name="users.user_logout"
),
]
urlpatterns += UserCRUDL().as_urlpatterns()
def get_context_data(self, *args, **kwargs):
context_data = super(UserCRUDL.Newpassword, self).get_context_data(*args, **kwargs)
context_data['expire_days'] = getattr(settings, 'USER_PASSWORD_EXPIRATION', -1)
context_data['window_days'] = getattr(settings, 'USER_PASSWORD_REPEAT_WINDOW', -1)
return context_data
def post_save(self, obj):
obj = super(UserCRUDL.Profile, self).post_save(obj)
if 'new_password' in self.form.cleaned_data and self.form.cleaned_data['new_password']:
FailedLogin.objects.filter(user=self.object).delete()
PasswordHistory.objects.create(user=obj, password=obj.password)
return obj
def get_context_data(self, *args, **kwargs):
context = super(UserCRUDL.Failed, self).get_context_data(*args, **kwargs)
lockout_timeout = getattr(settings, 'USER_LOCKOUT_TIMEOUT', 10)
failed_login_limit = getattr(settings, 'USER_FAILED_LOGIN_LIMIT', 5)
allow_email_recovery = getattr(settings, 'USER_ALLOW_EMAIL_RECOVERY', True)
context['lockout_timeout'] = lockout_timeout
context['failed_login_limit'] = failed_login_limit
context['allow_email_recovery'] = allow_email_recovery
return context
user = get_user_model().objects.filter(email__iexact=email).first()
context = build_email_context(self.request, user)
if user:
token = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(32))
RecoveryToken.objects.create(token=token, user=user)
email_template = loader.get_template(user_email_template)
FailedLogin.objects.filter(user=user).delete()
context['user'] = user
context['path'] = "%s" % reverse('users.user_recover', args=[token])
send_mail(_('Password Recovery Request'), email_template.render(context), from_email,
[email], fail_silently=False)
response = super(UserCRUDL.Forget, self).form_valid(form)
return response