-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/bounswe/bounswe2024group6 i…
…nto FRONTEND-454
- Loading branch information
Showing
30 changed files
with
1,249 additions
and
335 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
from django.contrib import admin | ||
from .models import Profile | ||
|
||
# Register your models here. | ||
@admin.register(Profile) | ||
class ProfileAdmin(admin.ModelAdmin): | ||
list_display = ('user', 'get_following', 'get_followers') | ||
|
||
# Custom method to display users this profile is following | ||
def get_following(self, obj): | ||
return ", ".join([str(profile.user.username) for profile in obj.following.all()]) | ||
get_following.short_description = 'Following' | ||
|
||
# Custom method to display users following this profile | ||
def get_followers(self, obj): | ||
return ", ".join([str(profile.user.username) for profile in obj.followers.all()]) | ||
get_followers.short_description = 'Followers' |
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 4.2.16 on 2024-11-03 14:21 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('app', '0004_post'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='profile', | ||
name='following', | ||
field=models.ManyToManyField(blank=True, related_name='followers', to='app.profile'), | ||
), | ||
] |
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,29 @@ | ||
from django.shortcuts import get_object_or_404 | ||
from django.http import JsonResponse | ||
from app.models import Profile | ||
from rest_framework.decorators import api_view, permission_classes | ||
from rest_framework.permissions import IsAuthenticated | ||
|
||
@api_view(['POST']) | ||
@permission_classes([IsAuthenticated]) | ||
def follow_user(request): | ||
current_user_profile = request.user.profile | ||
user_id = request.data.get("user_id") # Get the user_id from the request body | ||
user_to_follow = get_object_or_404(Profile, user__id=user_id) | ||
|
||
if user_to_follow != current_user_profile: | ||
current_user_profile.following.add(user_to_follow) | ||
return JsonResponse({"message": "Followed successfully"}, status=200) | ||
return JsonResponse({"error": "Cannot follow yourself"}, status=400) | ||
|
||
@api_view(['POST']) | ||
@permission_classes([IsAuthenticated]) | ||
def unfollow_user(request): | ||
current_user_profile = request.user.profile | ||
user_id = request.data.get("user_id") # Get the user_id from the request body | ||
user_to_unfollow = get_object_or_404(Profile, user__id=user_id) | ||
|
||
if user_to_unfollow != current_user_profile: | ||
current_user_profile.following.remove(user_to_unfollow) | ||
return JsonResponse({"message": "Unfollowed successfully"}, status=200) | ||
return JsonResponse({"error": "Cannot unfollow yourself"}, status=400) |
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 |
---|---|---|
|
@@ -69,7 +69,7 @@ | |
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
'corsheaders.middleware.CorsMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
# 'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
|
@@ -159,3 +159,15 @@ | |
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field | ||
|
||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' | ||
|
||
|
||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' | ||
EMAIL_HOST = 'smtp.gmail.com' | ||
EMAIL_PORT = 587 | ||
EMAIL_USE_TLS = True | ||
EMAIL_HOST_USER = '[email protected]' # Replace with your Gmail address | ||
EMAIL_HOST_PASSWORD = 'Oktay2001!' # Replace with your Gmail password | ||
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER | ||
|
||
|
||
LOGIN_URL = '/login/' |
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,63 @@ | ||
import FontAwesome from '@expo/vector-icons/FontAwesome'; | ||
import { Tabs } from 'expo-router'; | ||
import React, {useState} from 'react'; | ||
import {TouchableOpacity} from 'react-native'; | ||
import { ModalOverlay } from '../modalOverlay'; | ||
|
||
export default function TabLayout() { | ||
const [isModalVisible, setIsModalVisible] = useState(false); | ||
|
||
const openModal = () => setIsModalVisible(true); | ||
const closeModal = () => setIsModalVisible(false); | ||
|
||
|
||
return ( | ||
<> | ||
<Tabs screenOptions={{ tabBarActiveTintColor: 'red' }}> | ||
<Tabs.Screen | ||
name="index" | ||
options={{ | ||
title: 'Home', | ||
tabBarIcon: ({ color }) => <FontAwesome size={28} name="home" color={color} />, | ||
}} | ||
/> | ||
<Tabs.Screen | ||
name="quizzes" | ||
options={{ | ||
title: 'Quizzes', | ||
tabBarIcon: ({ color }) => <FontAwesome size={28} name="question" color={color} />, | ||
}} | ||
/> | ||
<Tabs.Screen | ||
name="search" | ||
options={{ | ||
title: 'Search', | ||
tabBarIcon: ({ color }) => <FontAwesome size={28} name="search" color={color} />, | ||
}} | ||
/> | ||
<Tabs.Screen | ||
name="forums" | ||
options={{ | ||
title: 'Forums', | ||
tabBarIcon: ({ color }) => <FontAwesome size={28} name="comment" color={color} />, | ||
}} | ||
/> | ||
<Tabs.Screen | ||
name="profile" | ||
options={{ | ||
title: 'Profile', | ||
tabBarIcon: ({ color }) => <FontAwesome size={28} name="user" color={color} />, | ||
headerRight: () => ( | ||
<TouchableOpacity onPress={openModal} style={{width: 40}}> | ||
<FontAwesome size={28} name="ellipsis-v"/> | ||
</TouchableOpacity> | ||
), | ||
}} | ||
/> | ||
</Tabs> | ||
{isModalVisible && ( | ||
<ModalOverlay closeModal={closeModal} /> | ||
)} | ||
</> | ||
); | ||
} |
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,17 @@ | ||
import { View, Text, StyleSheet } from 'react-native'; | ||
|
||
export default function Tab() { | ||
return ( | ||
<View style={styles.container}> | ||
<Text>Forums</Text> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
}); |
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,17 @@ | ||
import { View, Text, StyleSheet } from 'react-native'; | ||
|
||
export default function Tab() { | ||
return ( | ||
<View style={styles.container}> | ||
<Text>Home</Text> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
}); |
Oops, something went wrong.