Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
33 changes: 0 additions & 33 deletions backend/accounts/migrations/0001_initial.py

This file was deleted.

24 changes: 0 additions & 24 deletions backend/accounts/migrations/0002_auto_20201126_2154.py

This file was deleted.

Empty file.
60 changes: 56 additions & 4 deletions backend/accounts/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.db import models
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, BaseUserManager
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, BaseUserManager, Group, Permission, User
from django.conf import settings

class UserAccountManager(BaseUserManager):
def create_user(self, email, password=None, **extra_fields):
Expand All @@ -15,14 +16,20 @@ def create_user(self, email, password=None, **extra_fields):
return user

class UserAccount(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=255, unique=True)
# user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='user_account')
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
email = models.EmailField(max_length=255, unique=True)
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)

objects = UserAccountManager()

groups = models.ManyToManyField(Group, verbose_name='groups', blank=True, related_name='user_accounts_groups')
user_permissions = models.ManyToManyField(
Permission,
verbose_name='user permissions',
blank=True,
related_name='user_account_permissions' # Unique related_name for UserAccount
)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['first_name', 'last_name']

Expand All @@ -34,3 +41,48 @@ def get_short_name(self):

def __str__(self):
return self.email



class ProfileAccountManager(BaseUserManager):
def create_profile(self, email,**extra_fields):
if not email:
raise ValueError('An email address is required for creating profile')

email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)

user.save()

return user

class UserProfileAccount(AbstractBaseUser, PermissionsMixin):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE,null=True,default=None,related_name='user_profile_account')
name = models.CharField(max_length=255)
email = models.EmailField(max_length=255, unique=True)
contact = models.CharField(max_length=255)
designation = models.CharField(max_length=255)
organization = models.CharField(max_length=255)
radiodetails = models.CharField(max_length=255)
radiosetdetails = models.CharField(max_length=255)
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=True)
objects = ProfileAccountManager()
# groups = models.ManyToManyField(Group, verbose_name='groups', blank=True, related_name='user_profile_accounts_groups')
user_permissions = models.ManyToManyField(
Permission,
verbose_name='user permissions',
blank=True,
related_name='user_profile_account_permissions' # Unique related_name for UserProfileAccount
)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['name', 'designation']


def get_full_name(self):
return self.name

def __str__(self):
return self.email


12 changes: 11 additions & 1 deletion backend/accounts/serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
from djoser.serializers import UserCreateSerializer
from django.contrib.auth import get_user_model
from rest_framework import serializers
from .models import UserProfileAccount
from django.contrib.auth.models import Group
User = get_user_model()

class UserCreateSerializer(UserCreateSerializer):
user_accounts_groups = serializers.PrimaryKeyRelatedField(many=True,queryset=Group.objects.all(), required=False)
class Meta(UserCreateSerializer.Meta):
model = User
fields = ('id', 'email', 'first_name', 'last_name', 'password')
fields = ('id', 'email', 'first_name', 'last_name', 'password','user_accounts_groups')

class UserProfileAccountSerializer(serializers.ModelSerializer):
# user_profile_accounts_groups = serializers.PrimaryKeyRelatedField(many=True,queryset=Group.objects.all(), required=False)
class Meta:
model = UserProfileAccount
fields = ('id', 'name', 'email', 'contact', 'designation', 'organization', 'radiodetails', 'radiosetdetails')
84 changes: 83 additions & 1 deletion backend/accounts/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,85 @@
from django.shortcuts import render
from rest_framework import viewsets,generics
from .models import UserProfileAccount
from .serializers import UserProfileAccountSerializer
from rest_framework.permissions import AllowAny
from rest_framework.response import Response
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
import requests
from django.http import Http404
from rest_framework import status
from rest_framework.decorators import authentication_classes, permission_classes,api_view
from rest_framework.permissions import IsAuthenticated
import logging
logger = logging.getLogger(__name__)

# Create your views here.

class ProfileCreateView(generics.CreateAPIView):
queryset = UserProfileAccount.objects.all()
serializer_class = UserProfileAccountSerializer
permission_classes = [AllowAny]

# @login_required
# def get_user_profile(request):
# print('get_user')
# user_profile = UserProfileAccount.objects.get(user=request.user)
# # user_profile = UserProfileAccount.objects.get(email='drishtiolf@gmail.com') # Assuming you have a user field in your profile model.
# serializer = UserProfileAccountSerializer(user_profile)
# lookup_field = 'email'
# return Response(serializer.data)
# # profile_data = {
# # "name": user_profile.name,
# # "email": user_profile.email,
# # "contact": user_profile.contact,
# # "designation": user_profile.designation,
# # "organization": user_profile.organization,
# # # Add more fields as needed
# # }
# # print(user_profile.status_code)
# # return JsonResponse(profile_data)

@authentication_classes([])
@permission_classes([AllowAny])
class UserProfileDetailView(generics.RetrieveAPIView):
queryset = UserProfileAccount.objects.all()
serializer_class = UserProfileAccountSerializer
lookup_field = 'email'


def retrieve(self, request, *args, **kwargs):
email = self.kwargs.get('email')
try:
user_profile = UserProfileAccount.objects.get(email=email)
serializer = UserProfileAccountSerializer(user_profile)
return Response(serializer.data, status=status.HTTP_200_OK)
except UserProfileAccount.DoesNotExist:
raise Http404("User profile not found")

# class UserProfileDetailView(generics.RetrieveAPIView):
# serializer_class = UserProfileAccountSerializer

# def retrieve(self, request, *args, **kwargs):
# user_profile = request.user.user_accounts_groups # Assuming UserProfileAccount is related to the user model
# serializer = UserProfileAccountSerializer(user_profile)
# return Response(serializer.data, status=status.HTTP_200_OK)


# @api_view(['GET'])
# @permission_classes([IsAuthenticated])
# @login_required
# def user_profile(request):
# user = UserProfileAccount.objects.get(user=request.user)
# profile_data = {
# "name": user.name,
# "email": user.email,
# "contact": user.contact,
# "designation": user.designation,
# "organization": user.organization,
# "radiodetails" : user.radiodetails,
# "radiosetdetails" : user.radiosetdetails,
# # Add more fields as needed
# }
# serializer = UserProfileAccountSerializer(profile_data)
# # return JsonResponse(profile_data)
# return Response(serializer.data, status=status.HTTP_200_OK)
66 changes: 60 additions & 6 deletions backend/auth_system/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['*']


# Application definition
Expand All @@ -42,21 +42,30 @@
'djoser',
'accounts',
'social_django',
'corsheaders',
'rest_framework_simplejwt',
'rest_framework_simplejwt.token_blacklist'
]

MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'social_django.middleware.SocialAuthExceptionMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
# 'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

CORS_ORIGIN_ALLOW_ALL = True

CORS_ORIGIN_WHITELIST = [
'http://localhost:3000',
]

ROOT_URLCONF = 'auth_system.urls'

TEMPLATES = [
Expand Down Expand Up @@ -87,17 +96,18 @@
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'auth_system',
'USER': 'postgres',
'PASSWORD': '[YOUR DATABASE PASSWORD]',
'USER': 'sanjayjain',
'PASSWORD': 'capstone123',
'HOST': 'localhost'
}
}


EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[YOUR EMAIL THAT WILL SEND]'
EMAIL_HOST_PASSWORD = '[YOUR EMAIL APP PASSWORD]'
EMAIL_HOST_USER = 'drishti1152@gmail.com'
EMAIL_HOST_PASSWORD = 'ytbdkpwueyvklugr'
EMAIL_USE_TLS = True

# Password validation
Expand Down Expand Up @@ -200,3 +210,47 @@
}

AUTH_USER_MODEL = 'accounts.UserAccount'
AUTH_PROFILE_MODULE = 'accounts.UserProfileAccount'

CORS_ALLOW_ALL_ORIGINS = True

CORS_ALLOW_METHODS = [
'DELETE',
'GET',
'OPTIONS',
'PATCH',
'POST',
'PUT',
]

CORS_ALLOW_HEADERS = [
'accept',
'accept-encoding',
'authorization',
'content-type',
'dnt',
'origin',
'user-agent',
'x-csrftoken',
'x-requested-with',
]



# settings.py

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': 'debug.log', # Check the filename and path
},
},
'root': {
'handlers': ['file'],
'level': 'DEBUG',
},
}
10 changes: 10 additions & 0 deletions backend/auth_system/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
from django.urls import path, include, re_path
from django.views.generic import TemplateView
from rest_framework.routers import DefaultRouter
from accounts.views import ProfileCreateView
from accounts.views import UserProfileDetailView
# from accounts.views import user_profile



urlpatterns = [
path('auth/', include('djoser.urls')),
path('auth/', include('djoser.urls.jwt')),
path('auth/', include('djoser.social.urls')),
path('profiles/create/', ProfileCreateView.as_view(), name='profile-create'),
# path('user/profile/', user_profile, name='get_user_profile'),
path('user/profile/<str:email>/', UserProfileDetailView.as_view(), name='get_user_profile'),
]

urlpatterns += [re_path(r'^.*', TemplateView.as_view(template_name='index.html'))]

2 changes: 1 addition & 1 deletion frontend/.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
REACT_APP_API_URL = 'http://localhost:8000'
REACT_APP_API_URL = 'http://localhost:8000'
Loading