Skip to content

Commit

Permalink
I really should've been commiting along the way, sample login page, t…
Browse files Browse the repository at this point in the history
…rying to use django built in auth, has not been tested yet
  • Loading branch information
group117 committed Jul 17, 2024
1 parent b5428da commit d393a49
Show file tree
Hide file tree
Showing 8 changed files with 320 additions and 27 deletions.
9 changes: 9 additions & 0 deletions backend/api/api_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

from django.urls import path
from . import views
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView
)

urlpatterns = [
path('', views.landing_page, name='landing_page'),
path('login/', views.login, name='login'),
path('test/', views.test_page, name='test_page'),
path('api/medication_info/<int:user_id>/', views.get_medication_info,
name='get_medication_info'),
path('api/token/', TokenObtainPairView.as_view(),
name='token_obtain_pair'),
path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),

]
21 changes: 21 additions & 0 deletions backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,29 @@
from django.conf import settings
import os

from django.contrib.auth import authenticate
from rest_framework.response import Response
from rest_framework.decorators import api_view
from rest_framework_simplejwt.tokens import RefreshToken

from .models import MedicationInfo

@api_view(['POST'])
def login(request):
email = request.data.get('email')
password = request.data.get('password')

user = authenticate(request, username=email, password=password)

if user is not None:
refresh = RefreshToken.for_user(user)
return Response({
'access': str(refresh.access_token),
'refresh': str(refresh)
})
else:
return Response({'error': 'Invalid credentials'}, status=400)


# Create your views here.
def test_page(request):
Expand Down
18 changes: 18 additions & 0 deletions backend/med_reminder/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import os
from pathlib import Path
from dotenv import load_dotenv
from datetime import timedelta

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand Down Expand Up @@ -46,9 +47,26 @@
'django.contrib.staticfiles',
'api',
'rest_framework',
'rest_framework_simplejwt',
'rest_framework_simplejwt.token_blacklist'
'corsheaders',
]

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
),
}

SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=5),
'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
'ROTATE_REFRESH_TOKENS': False,
'BLACKLIST_AFTER_Rotation': True,
'AUTH_HEADER_TYPES': ('BEARER',),
'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
}

MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
Expand Down
18 changes: 18 additions & 0 deletions frontend/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import HomeScreen from './screens/HomeScreen';

Check failure on line 4 in frontend/App.tsx

View workflow job for this annotation

GitHub Actions / lint

Unable to resolve path to module './screens/HomeScreen'
import LoginScreen from './screens/LoginScreen';

const Stack = createNativeStackNavigator();

const app = () => {

Check warning on line 9 in frontend/App.tsx

View workflow job for this annotation

GitHub Actions / lint

'app' is assigned a value but never used
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name='LoginPage' component={LoginScreen} />
<Stack.Screen name='HomePage' component={HomeScreen} />
</Stack.Navigator>
</NavigationContainer>
);
};
3 changes: 2 additions & 1 deletion frontend/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"favicon": "./assets/images/favicon.png"
},
"plugins": [
"expo-router"
"expo-router",
"expo-secure-store"
],
"experiments": {
"typedRoutes": true
Expand Down
Loading

0 comments on commit d393a49

Please sign in to comment.