Skip to content
Snippets Groups Projects
Commit 1efd1b53 authored by Darla Maestas's avatar Darla Maestas
Browse files

testing again darla

parent a0feaf7e
Branches
No related tags found
1 merge request!1Pass email breach merge into master
Showing
with 122 additions and 6 deletions
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class AuthAppConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "auth_app"
from django.db import models
# Create your models here.
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import MyTokenObtainPairView, RegisterView
from rest_framework_simplejwt.views import TokenRefreshView
urlpatterns = [
path('login/', MyTokenObtainPairView.as_view(), name='token_obtain_pair'),
path('token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
path('register/', RegisterView.as_view(), name='register'),
]
from rest_framework_simplejwt.views import TokenObtainPairView
from rest_framework import permissions
from django.contrib.auth.models import User
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.permissions import AllowAny
# This view extends TokenObtainPairView to handle token creation on user login.
class MyTokenObtainPairView(TokenObtainPairView):
permission_classes = (permissions.AllowAny,) # Allow any user to access this view
# You can customize this view further if needed, e.g., adding extra data to the token response.
class RegisterView(APIView):
permission_classes = (AllowAny,)
def post(self, request):
username = request.data.get('username')
password = request.data.get('password')
email = request.data.get('email', '') # Email is optional
if not username or not password:
return Response({'error': 'Username and password are required.'}, status=status.HTTP_400_BAD_REQUEST)
if User.objects.filter(username=username).exists():
return Response({'error': 'Username is already taken.'}, status=status.HTTP_400_BAD_REQUEST)
user = User.objects.create_user(username, email, password)
return Response({'msg': 'User created successfully.'}, status=status.HTTP_201_CREATED)
\ No newline at end of file
from django.apps import AppConfig
class BreachCheckConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'breach_check'
# Generated by Django 4.2.9 on 2024-02-16 23:50
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = []
operations = [
migrations.CreateModel(
name="Account",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("email", models.EmailField(max_length=254, unique=True)),
],
),
]
from django.db import models
class MonitoredEmail(models.Model):
email = models.EmailField(unique=True)
added_on = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.email
from django.test import TestCase
# Create your tests here.
# breach_check/urls.py
from django.urls import path
from .views import have_i_been_pwned
urlpatterns = [
path('haveibeenpwned/<str:email>/', have_i_been_pwned, name='have_i_been_pwned'),
]
# breach_check/utils.py
def check_breach(email):
# Implement your breach checking logic here
# This function should return True if the email is breached, False otherwise.
# For simplicity, let's assume it always returns False.
return False
# breach_check/views.py
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from .utils import check_breach
@csrf_exempt # Use csrf_exempt for simplicity; implement proper CSRF handling in production
def have_i_been_pwned(request, email):
# Perform your breach checking logic here
is_breached = check_breach(email)
# Return a JSON response
return JsonResponse({'is_breached': is_breached})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment