Skip to content

Commit

Permalink
Merge pull request #70 from julkascript/develop
Browse files Browse the repository at this point in the history
Merge develop to master
  • Loading branch information
julkascript authored Feb 16, 2024
2 parents ae65b4c + 8b37d78 commit 64428fe
Show file tree
Hide file tree
Showing 234 changed files with 15,600 additions and 3 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/action-test-frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Frontend Tests

on:
pull_request:
branches:
- develop
- master

paths-ignore:
- "*.md"

jobs:

buildAndTest:
name: Build & Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: 🏗 Setup Node
uses: actions/setup-node@v3
with:
node-version: 18

- name: 🗂️ Install dependencies
run: npm install
working-directory: ./frontend

- name: 🔨 Build
run: npm run build
working-directory: ./frontend

- name: 🧪 Test
run: npm test
working-directory: ./frontend
40 changes: 40 additions & 0 deletions .github/workflows/action-tests-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
name: Backend Tests

on:
pull_request:
branches:
- develop
- master

paths-ignore:
- "*.md"

jobs:
docker:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Set up environment variables
run: |
echo "POSTGRES_USER=postgres" >> $GITHUB_ENV
echo "POSTGRES_PASSWORD=postgres" >> $GITHUB_ENV
echo "POSTGRES_DB=postgres" >> $GITHUB_ENV
echo "POSTGRES_HOST=localhost" >> $GITHUB_ENV
echo "SECRET_KEY=super secret" >> $GITHUB_ENV
- uses: actions/checkout@v3
- uses: iamsauravsharma/create-dotenv@v2.0.1
with:
file-path: '/home/runner/work/cardflow/cardflow/frontend/.env'
- uses: iamsauravsharma/create-dotenv@v2.0.1
with:
file-path: '/home/runner/work/cardflow/cardflow/backend/.env'
- uses: isbang/compose-action@v1.5.1
with:
compose-file: "./docker-compose.yml"
services: |
backend
postgres
- name: Run tests
run: |
docker exec cardflow-backend-1 sh -c "pytest"
46 changes: 46 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Pycharm editor files and folders
__pycache__
.idea/
venv/
*.jpg

# ENV files and folders
backend/.env
frontend/.env
.env

#KEYS
keys/

# DB files and folders
db*
postgresql/
pgadmin4/

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

# Avatars
backend/media
22 changes: 22 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# How to contribute to Cardflow

## Did you find a bug?

1. Open an issue at the [Issues]([url](https://github.com/julkascript/cardflow/issues)https://github.com/julkascript/cardflow/issues) section.
2. Be as descriptive as possible.
3. Provide screenshots if any.
4. Write detailed steps to reproduce the issue.

## Do you want to work on an issue or a feature?

1. Open a new GitHub pull request with the changes.
2. Ensure the PR description clearly describes the solution and why you went for it. Include the relevant issue number if applicable. Ensure all tests are passing.

## Do you intend to add a new feature or change an existing one?

Open an issue at the [Issues]([url](https://github.com/julkascript/cardflow/issues)https://github.com/julkascript/cardflow/issues) section. State your problem and be as detailed as possible.
Emphasize on how your change will benefits the project.

<br>

***Thanks for contributing to Cardflow and don't forget to have fun!*** ❤️
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Yulian Prodanov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,49 @@
cardflow readme
<p align="center">
<img src="https://github.com/julkascript/cardflow/assets/59143945/9cfe53f6-051d-45b5-8411-e77a5dc06b97" alt="cardflow logo" width="128" />
<br />
<h1 align="center">Cardflow</h1>
</p>

## Getting started

Visit https://cardflow.market to get started with Cardflow!

## Who is using Cardflow?

Cardflow is an open-source Trading Card Game card market, currently supporting only "Yu-Gi-Oh!" cards. Buy, sell and trade quickly and easily with zero cost and taxes.

## Tech stack

<div>
<table>
<tr>
<td><b>Frontend</b></td>
<td><b>Backend</b></td>
</tr>
<tr>
<td>
<img src="https://github.com/julkascript/cardflow/assets/59143945/23b5372d-9764-4b45-8d28-0c678cba0889" alt="react logo" width="30" />
<img src="https://github.com/julkascript/cardflow/assets/59143945/38da343e-353f-4321-8951-61652606b41f" alt="react logo" width="30" />
</td>
<td>
<img src="https://github.com/julkascript/cardflow/assets/59143945/5f98bff6-93a0-4b17-be8e-0e2e26b94f9f" alt="react logo" width="30" />
<img src="https://github.com/julkascript/cardflow/assets/59143945/f85df09f-2a3d-4249-b53b-2211c97c15cc" alt="react logo" width="30" />
</td>
</tr>
</table>
</div>

## Setting up Cardflow for development

1. `git clone git@github.com:julkascript/cardflow.git .`
2. `cp sample.env .env && cp backend/sample.env backend/.env && cp frontend/sample.env frontend/.env`
3. `docker compose up -d --build`
5. You most likely want to seed data, so you can have cards to work with.
- `docker ps` to see the containers
- `docker exec -it <backend_container_id> sh`
- `python manage.py seed staple`
6. Visit Cardflow at `localhost:5173`

## Feel like contributing?

Check out our [guideline document](https://github.com/julkascript/cardflow/blob/develop/CONTRIBUTING.md) and start contributing right away!
26 changes: 26 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM python:3.11.4-slim-buster

WORKDIR /usr/src/app

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN apt-get update && apt-get install -y netcat libpq-dev gcc openssh-client

RUN pip install --upgrade pip

COPY ./sample.env .env

COPY ./requirements.txt .

RUN pip install -r requirements.txt

COPY ./entrypoint.sh .

COPY ./ .

RUN sed -i 's/\r$//g' /usr/src/app/entrypoint.sh
RUN chmod +x /usr/src/app/entrypoint.sh

CMD ["sh", "entrypoint.sh"]
# CMD ["tail", "-f", "/dev/null"]
Empty file added backend/__init__.py
Empty file.
Empty file added backend/accounts/__init__.py
Empty file.
49 changes: 49 additions & 0 deletions backend/accounts/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.utils.translation import gettext_lazy as _
from django.contrib.auth import get_user_model

User = get_user_model()


class UserAdmin(BaseUserAdmin):
fieldsets = (
(None, {"fields": ("username", "password")}),
(_("Personal info"), {"fields": ("email", "first_name", "last_name", "phone_number", "city", "shipping_address", "avatar")}),
(_("Permissions"),
{
"fields": (
"is_active",
"is_staff",
"is_superuser",
"groups",
"user_permissions",
),
},
),
(_("Important dates"), {"fields": ("last_login", "date_joined")}),
)
add_fieldsets = (
(
None,
{
"classes": ("wide",),
"fields": (
"username", "password1", "password2", "email", "first_name",
"last_name", "is_active", "is_staff", "avatar", "is_superuser"
),
},
),
)
list_display = (
"username", "email", "first_name", "last_name",
"phone_number", "city", "shipping_address", "is_active", "id", "last_login",
)
list_filter = ("username", "email", "is_superuser", "is_active")
search_fields = ("username", "email", "first_name", "last_name")
ordering = ("username", "email")
list_per_page = 15
readonly_fields = ('last_login', 'date_joined')


admin.site.register(User, UserAdmin)
6 changes: 6 additions & 0 deletions backend/accounts/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AccountsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'accounts'
11 changes: 11 additions & 0 deletions backend/accounts/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django_filters import rest_framework as filters

from .models import User


class UserFilter(filters.FilterSet):
username = filters.CharFilter(lookup_expr='icontains')

class Meta:
model = User
fields = ['username']
61 changes: 61 additions & 0 deletions backend/accounts/middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from django.contrib.auth import get_user_model
from django.http import JsonResponse
from django.urls import include, path
from rest_framework_simplejwt.authentication import JWTAuthentication
from rest_framework_simplejwt.exceptions import TokenError, InvalidToken

JWT_authenticator = JWTAuthentication()

User = get_user_model()


class JWTAuthorizationMiddleware:

EXCLUDED_PATHS = [
'/api/accounts/login/',
'/api/accounts/register/',
'/api/accounts/refresh/',
'/',
"/api/schema/",
"/api/docs/",
]

def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):

if request.path in self.EXCLUDED_PATHS or request.path.startswith('/admin') or request.path.startswith('/api/yugioh'):
return self.get_response(request)

if 'Authorization' not in request.headers:
return JsonResponse({'error': 'Invalid Authorization header'}, status=401)

auth_header = request.headers['Authorization']
auth_parts = auth_header.split()

if len(auth_parts) != 2 or auth_parts[0] != 'Bearer':
return JsonResponse({'error': 'Invalid Type'}, status=401)

try:
token_response = JWT_authenticator.authenticate(request)
user = self.has_access_rights(token_response, request)
if not user:
return JsonResponse({'error': 'Unauthorized access'}, status=401)
except InvalidToken:
return JsonResponse({'error': 'Invalid token or expired'}, status=401)
except TokenError:
return JsonResponse({'error': 'Invalid token'}, status=401)

return self.get_response(request)

def has_access_rights(self, token_response, request):

try:
user, _ = token_response

except User.DoesNotExist:
print('User does not exist')
return None

return bool(user.is_active)
Loading

0 comments on commit 64428fe

Please sign in to comment.