forked from ZcashFoundation/zebra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
1,251 additions
and
437 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
Invisible captcha | ||
|
||
https://www.google.com/recaptcha/admin/site/693074980/settings | ||
|
||
https://developers.google.com/recaptcha/intro | ||
|
||
https://github.com/dozoisch/react-google-recaptcha | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2.12 on 2024-01-13 23:01 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('g12f', '0079_remove_zpage_thumbnail_url'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='creator', | ||
name='password_set', | ||
field=models.BooleanField(default=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Generated by Django 3.2.12 on 2024-01-13 23:04 | ||
|
||
from django.db import migrations | ||
from django.contrib.auth.hashers import make_password | ||
|
||
|
||
def set_unusable_passwords(apps, schema_editor): | ||
Creator = apps.get_model('g12f', 'Creator') | ||
|
||
def set_unusable_password(creator): | ||
# Mimic the behavior of your set_unusable_password method | ||
creator.password = make_password(None) | ||
creator.password_set = False # Assuming you have this field in your model | ||
|
||
for c in Creator.objects.filter(password=""): | ||
set_unusable_password(c) | ||
c.save(update_fields=['password', 'password_set']) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('g12f', '0080_creator_password_set'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(set_unusable_passwords), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.contrib import admin | ||
from .models import OTPSecret | ||
|
||
|
||
@admin.register(OTPSecret) | ||
class OTPSecretAdmin(admin.ModelAdmin): | ||
list_display = ['user', 'created_at', 'last_used_at'] | ||
search_fields = ['user__username'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class OtpConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'dj.apps.otp' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Generated by Django 3.2.12 on 2024-01-11 05:15 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='OTPSecret', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('secret', models.CharField(max_length=255)), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('last_used_at', models.DateTimeField(blank=True, null=True)), | ||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2.12 on 2024-01-12 00:26 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('otp', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='otpsecret', | ||
name='is_active', | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django.db import models | ||
from django.contrib.auth import get_user_model | ||
|
||
User = get_user_model() | ||
|
||
|
||
class OTPSecret(models.Model): | ||
user = models.OneToOneField(User, on_delete=models.CASCADE) | ||
secret = models.CharField(max_length=255) | ||
is_active = models.BooleanField(default=False) | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
last_used_at = models.DateTimeField(null=True, blank=True) | ||
|
||
def __str__(self): | ||
return f"OTP Secret for {self.user.username}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from rest_framework import serializers | ||
|
||
|
||
class VerifyOTPSerializer(serializers.Serializer): | ||
token = serializers.CharField(max_length=10) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.urls import path | ||
from .views import SetupOTPView, RetrieveOTPStatusView, EnableOTPView, DisableOTPView, LoginWithOTPView | ||
|
||
|
||
urlpatterns = [ | ||
path('status/', RetrieveOTPStatusView.as_view(), name='mfa_status'), | ||
path('setup/', SetupOTPView.as_view(), name='setup_mfa'), | ||
path('enable/', EnableOTPView.as_view(), name='enable_mfa'), | ||
path('disable/', DisableOTPView.as_view(), name='disable_mfa'), | ||
path('login/', LoginWithOTPView.as_view(), name='login_with_mfa'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
import pyotp | ||
|
||
def generate_secret(): | ||
""" | ||
Generates a secure random base32-encoded secret key for TOTP authentication. | ||
""" | ||
return pyotp.random_base32() | ||
|
||
|
||
def verify_token(secret, token): | ||
""" | ||
Verifies a TOTP token. | ||
:param secret: The user's secret key (base32 encoded). | ||
:param token: The OTP token to verify. | ||
""" | ||
totp = pyotp.TOTP(secret) | ||
return totp.verify(token) |
Oops, something went wrong.