-
Notifications
You must be signed in to change notification settings - Fork 0
Adding recording to hits for validation and login #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from django.contrib import admin | ||
|
|
||
| from .models import PwnedRecord | ||
|
|
||
|
|
||
| @admin.register(PwnedRecord) | ||
| class PwnedRecordAdmin(admin.ModelAdmin): | ||
| list_display = ('email', 'created', 'count', 'notified',) | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| from django.contrib.auth.backends import ModelBackend | ||
|
|
||
| from .client import PwnedClient | ||
| from .models import PwnedRecord | ||
| from .settings import get_config | ||
|
|
||
|
|
||
| class PwnedBackendMixin: | ||
|
|
||
| client = PwnedClient | ||
|
|
||
| def authenticate(self, request, username=None, password=None): | ||
| user = super().authenticate(request, username=username, password=password) | ||
| # If authenticated, check supplied password against API | ||
| if user and password: | ||
| pwned_client = self.client() | ||
| count = pwned_client.count_occurrences(password) | ||
| if count and get_config()['RECORD_HITS']: | ||
| PwnedRecord.objects.create( | ||
| email = user.email, | ||
| count = count, | ||
| ) | ||
| return user | ||
|
|
||
|
|
||
| class PwnedModelBackend(PwnedBackendMixin, ModelBackend): | ||
| pass |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Generated by Django 2.2 on 2019-05-03 13:21 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| initial = True | ||
|
|
||
| dependencies = [ | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name='PwnedRecord', | ||
| fields=[ | ||
| ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('email', models.EmailField(blank=True, max_length=254)), | ||
| ('count', models.PositiveIntegerField(db_index=True)), | ||
| ('notified', models.BooleanField(db_index=True, default=False)), | ||
| ('created', models.DateTimeField(auto_now_add=True)), | ||
| ], | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| from django.contrib.auth import get_user_model | ||
| from django.db import models | ||
|
|
||
|
|
||
| UserModel = get_user_model() | ||
|
|
||
|
|
||
| class PwnedRecord(models.Model): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure that this app should be providing this model at all, especially with fields ( |
||
| email = models.EmailField(blank=True) | ||
| count = models.PositiveIntegerField(db_index=True) | ||
| notified = models.BooleanField(db_index=True, default=False) | ||
| created = models.DateTimeField(auto_now_add=True) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import.