Skip to content

Commit

Permalink
Final tests with development server, Login signup set up
Browse files Browse the repository at this point in the history
  • Loading branch information
ZEZE1020 committed Jan 12, 2025
1 parent 786741a commit 7ff497c
Show file tree
Hide file tree
Showing 199 changed files with 37,645 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.8, 3.9]
python-version: [3.13]

steps:
- uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn social_media_api.wsgi
8 changes: 7 additions & 1 deletion accounts/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
from django.contrib import admin
from django.contrib import admin
from .models import CustomUser, Follow

# Register the CustomUser model
admin.site.register(CustomUser)

# Register your models here.
# Register the Follow model
admin.site.register(Follow)
1 change: 0 additions & 1 deletion accounts/serializers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# accounts/serializers.py
from rest_framework import serializers
from .models import CustomUser, Follow

Expand Down
75 changes: 37 additions & 38 deletions accounts/views.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,72 @@
from django.shortcuts import render
from rest_framework import viewsets, permissions
from .models import CustomUser
from .serializers import UserSerializer
from .models import CustomUser, Follow
from .serializers import UserSerializer, FollowSerializer
from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework import status
from django.contrib.auth import get_user_model
from .models import Follow
from .serializers import FollowSerializer
from django.urls import reverse_lazy
from django.views.generic import ListView, DetailView, CreateView, UpdateView
from .models import CustomUser

User = get_user_model()
# Create your views here.
from django.contrib.auth import login, authenticate
from django.shortcuts import render, redirect

class UserViewSet(viewsets.ModelViewSet):
queryset = CustomUser.objects.all()
serializer_class = UserSerializer
permission_classes = [permissions.IsAuthenticatedOrReadOnly]

class UserListView(ListView):
model = CustomUser
template_name = 'accounts/user_list.html'
context_object_name = 'users'

class UserDetailView(DetailView):
model = CustomUser
template_name = 'accounts/user_detail.html'
context_object_name = 'user'

class UserCreateView(CreateView):
model = CustomUser
template_name = 'accounts/user_create.html'
fields = ['username', 'email', 'password', 'bio', 'profile_picture']
success_url = '/'

def form_valid(self, form):
form.save()
username = form.cleaned_data.get('username')
raw_password = form.cleaned_data.get('password')
user = authenticate(username=username, password=raw_password)
login(self.request, user)
return redirect('home')

class UserUpdateView(UpdateView):
model = CustomUser
template_name = 'accounts/user_update.html'
fields = ['username', 'email', 'bio', 'profile_picture']
success_url = '/'

@api_view(['POST'])
@permission_classes([IsAuthenticated])
def follow_user(request, user_id):
try:
user_to_follow = User.objects.get(id=user_id)
user_to_follow = CustomUser.objects.get(id=user_id)
if Follow.objects.filter(follower=request.user, following=user_to_follow).exists():
return Response({'detail': 'Already following this user.'}, status=status.HTTP_400_BAD_REQUEST)
if request.user == user_to_follow:
return Response({'detail': 'You cannot follow yourself.'}, status=status.HTTP_400_BAD_REQUEST)
Follow.objects.create(follower=request.user, following=user_to_follow)
return Response({'detail': 'Followed successfully.'}, status=status.HTTP_200_OK)
except User.DoesNotExist:
except CustomUser.DoesNotExist:
return Response({'detail': 'User not found.'}, status=status.HTTP_404_NOT_FOUND)

@api_view(['POST'])
@permission_classes([IsAuthenticated])
def unfollow_user(request, user_id):
try:
user_to_unfollow = User.objects.get(id=user_id)
user_to_unfollow = CustomUser.objects.get(id=user_id)
follow_instance = Follow.objects.filter(follower=request.user, following=user_to_unfollow)
if follow_instance.exists():
follow_instance.delete()
return Response({'detail': 'Unfollowed successfully.'}, status=status.HTTP_200_OK)
return Response({'detail': 'You are not following this user.'}, status=status.HTTP_400_BAD_REQUEST)
except User.DoesNotExist:
except CustomUser.DoesNotExist:
return Response({'detail': 'User not found.'}, status=status.HTTP_404_NOT_FOUND)


class UserListView(ListView):
model = CustomUser
template_name = 'accounts/user_list.html'
context_object_name = 'users'

class UserDetailView(DetailView):
model = CustomUser
template_name = 'accounts/user_detail.html'
context_object_name = 'user'

class UserCreateView(CreateView):
model = CustomUser
template_name = 'accounts/user_create.html'
fields = ['username', 'email', 'bio', 'profile_picture']
success_url = reverse_lazy('user-list')

class UserUpdateView(UpdateView):
model = CustomUser
template_name = 'accounts/user_update.html'
fields = ['username', 'email', 'bio', 'profile_picture']
success_url = reverse_lazy('user-list')
5 changes: 4 additions & 1 deletion notifications/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from django.contrib import admin
from django.contrib import admin
from .models import Notification

# Register your models here.
# Register the Notification model
admin.site.register(Notification)
5 changes: 4 additions & 1 deletion posts/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from django.contrib import admin
from django.contrib import admin
from .models import Post

# Register your models here.
# Register the Post model
admin.site.register(Post)
Binary file modified requirements.txt
Binary file not shown.
Binary file modified social_media_api/__pycache__/settings.cpython-313.pyc
Binary file not shown.
23 changes: 23 additions & 0 deletions social_media_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
'posts',
'accounts',
'notifications',
'django.contrib.sites',
'allauth',
'allauth.account',
]

MIDDLEWARE = [
Expand All @@ -54,10 +57,30 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'allauth.account.middleware.AccountMiddleware',
]

ROOT_URLCONF = 'social_media_api.urls'

#Authentication settings
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)

SITE_ID = 1
# URL configuration
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'
# Email Verification
ACCOUNT_EMAIL_VERIFICATION = 'none'
ACCOUNT_EMAIL_REQUIRED = True

# Allauth settings
ACCOUNT_AUTHENTICATION_METHOD = 'username_email'
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'


TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
Expand Down
9 changes: 6 additions & 3 deletions social_media_api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include
from .views import home_view

urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/', include('accounts.urls')),
path('notifications/', include('notifications.urls')),
path('posts/', include('posts.urls')),
path('api/accounts/', include('accounts.urls')),
path('api/notifications/', include('notifications.urls')),
path('api/posts/', include('posts.urls')),
path('', home_view, name='home'),
path('accounts', include('allauth.urls'))
]

if settings.DEBUG:
Expand Down
4 changes: 4 additions & 0 deletions social_media_api/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.shortcuts import render

def home_view(request):
return render(request, 'home.html')
39 changes: 38 additions & 1 deletion static/css/styles.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* static/css/styles.css */

/* General Body Styling */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f8f9fa;
}

/* Header and Navigation Styling */
header {
background-color: #343a40;
color: white;
Expand Down Expand Up @@ -37,6 +38,7 @@ main {
margin: 0 auto;
}

/* Footer Styling */
footer {
background-color: #343a40;
color: white;
Expand All @@ -47,11 +49,46 @@ footer {
width: 100%;
}

/* Heading Styling */
h1,
h2 {
color: #343a40;
}

/* Image Styling */
img {
max-width: 100%;
}

/* Form Styling */
.auth-form {
background-color: white;
border: 1px solid #ddd;
padding: 2em;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.auth-form input[type="text"],
.auth-form input[type="password"],
.auth-form input[type="email"] {
width: 100%;
padding: 0.75em;
margin: 0.5em 0;
border: 1px solid #ddd;
border-radius: 5px;
}

.auth-form .btn {
background-color: #007bff;
color: white;
border: none;
padding: 0.75em 2em;
border-radius: 5px;
cursor: pointer;
font-size: 1em;
}

.auth-form .btn:hover {
background-color: #0056b3;
}
Loading

0 comments on commit 7ff497c

Please sign in to comment.