Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zubhub authentication feature backend and frontend #1

Merged
merged 2 commits into from
Dec 17, 2020
Merged
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
4 changes: 4 additions & 0 deletions zubhub_backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
media/
migrations/
__pycache__/
.gitignore
23 changes: 23 additions & 0 deletions zubhub_backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ENVIRONMENT=development

DEFAULT_FRONTEND_DOMAIN=localhost:3000
DEFAULT_DISPLAY_NAME=ZubHub

SECRET_KEY=<any string of your choice, preferably long one>
DEBUG=1

POSTGRES_NAME=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_HOST=db

SENDGRID_API_KEY=<your sendgrid api key>

RABBITMQ_DEFAULT_USER=admin
RABBITMQ_DEFAULT_PASS=admin

CELERY_BROKER=amqp://admin:admin@rabbitmq:5672/
CELERY_BACKEND=django-db

CELERY_FLOWER_USER=admin
CELERY_FLOWER_PASSWORD=admin
7 changes: 7 additions & 0 deletions zubhub_backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
media/
migrations/
__pycache__/
*.pyc
staticfiles/
.env
.docker/
30 changes: 30 additions & 0 deletions zubhub_backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM python:3.8-slim-buster

ENV PYTHONUNBUFFERED 1

# Python build stage

RUN apt-get update \
# dependencies for building Python packages
&& apt-get install -y build-essential procps netcat \
# psycopg2 dependencies
&& apt-get install -y libpq-dev \
# Translations dependencies
&& apt-get install -y gettext \
# cleaning up unused files
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& rm -rf /var/lib/apt/lists/*


WORKDIR /zubhub_backend

# copying neccessary files to work directory
COPY requirements.txt /zubhub_backend/

RUN pip install --upgrade pip wheel \
# Requirements are installed here to ensure they will be cached.
&& pip install -r /zubhub_backend/requirements.txt

# copy project

COPY . /zubhub_backend/
94 changes: 94 additions & 0 deletions zubhub_backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
version: '3.8'

services:
web:
env_file: .env
build:
context: .
dockerfile: ./Dockerfile
command: bash -c "python /zubhub_backend/zubhub/manage.py collectstatic --noinput && /usr/local/bin/gunicorn zubhub.wsgi --bind 0.0.0.0:8000 --chdir /zubhub_backend/zubhub"
environment:
- ENVIRONMENT=${ENVIRONMENT}
- SECRET_KEY:${SECRET_KEY}
- DEBUG:${DEBUG}
- POSTGRES_NAME=${POSTGRES_NAME}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_HOST=${POSTGRES_HOST}
- SENDGRID_API_KEY=${SENDGRID_API_KEY}
volumes:
- .:/zubhub_backend
ports:
- 8000:8000
depends_on:
- db
- rabbitmq

db:
env_file: .env
image: postgres:11
environment:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data/
ports:
- 5432:5432

rabbitmq:
env_file: .env
image: rabbitmq:3-management
ports:
- 5672:5672
- 15672:15672

celery_worker:
env_file: .env
build:
context: .
dockerfile: ./Dockerfile
image: zubhub_celery_worker
command: bash -c "cd zubhub && celery -A zubhub worker -l INFO"
volumes:
- .:/zubhub_backend
depends_on:
- rabbitmq
- db

flower:
env_file: .env
build:
context: .
dockerfile: ./Dockerfile
image: zubhub_celery_flower
ports:
- 5555:5555
command: bash -c 'cd zubhub && celery flower --app=zubhub --broker="${CELERY_BROKER}" --basic_auth="${CELERY_FLOWER_USER}:${CELERY_FLOWER_PASSWORD}"'
volumes:
- .:/zubhub_backend
depends_on:
- celery_worker
- rabbitmq
- db

prometheus:
image: prom/prometheus
ports:
- 9090:9090
command:
- --config.file=/etc/prometheus/prometheus.yml
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
depends_on:
- cadvisor

cadvisor:
image: google/cadvisor
container_name: cadvisor
volumes:
- /:/rootfs:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro

volumes:
postgres_data:
16 changes: 16 additions & 0 deletions zubhub_backend/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
scrape_configs:

- job_name: cadvisor
scrape_interval: 5s
static_configs:
- targets:
- cadvisor:8080

- job_name: flower
scrape_interval: 5s
static_configs:
- targets:
- nginx:5555
basic_auth:
username: admin
password: admin
29 changes: 29 additions & 0 deletions zubhub_backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Django==2.2.7
djangorestframework==3.10.3
pytz==2020.4
sqlparse==0.4.1
psycopg2-binary==2.8.3
django-cors-headers==3.1.1
django-allauth==0.40.0
django-rest-auth==0.9.5
whitenoise==4.1.4
gunicorn==19.9.0
django-crispy-forms==1.8.0
pillow==6.2.1
django-debug-toolbar==2.0
coreapi==2.3.3
pyyaml==5.1.2
django-rest-swagger==2.2.0
django-celery-email==3.0.0
django-celery-results==2.0.0
celery==4.4
flower==0.9.5
ipython
watchdog==0.10.2
argh>=0.24.1
requests==2.23.0
django-capture-on-commit-callbacks
factory-boy==2.12.0
coverage==5.1
pytest==5.3.5
pytest-django==3.8.0
Empty file.
5 changes: 5 additions & 0 deletions zubhub_backend/zubhub/APIS/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class ApisConfig(AppConfig):
name = 'APIS'
3 changes: 3 additions & 0 deletions zubhub_backend/zubhub/APIS/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
7 changes: 7 additions & 0 deletions zubhub_backend/zubhub/APIS/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.urls import path, include

urlpatterns = [
path('rest-auth/', include('rest_auth.urls')),
path('rest-auth/registration/',include('rest_auth.registration.urls')),
path('creators/', include('creators.urls', namespace="creators"))
]
Empty file.
14 changes: 14 additions & 0 deletions zubhub_backend/zubhub/creators/adapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from allauth.account.adapter import DefaultAccountAdapter
from .models import Location

class CustomAccountAdapter(DefaultAccountAdapter):

def save_user(self, request, user, form, commit=False):
creator = super().save_user(request, user, form, commit)
data = form.cleaned_data
location = Location.objects.get(name = data.get('location'))

creator.dateOfBirth = data.get('dateOfBirth')
creator.location = location
creator.save()
return creator
10 changes: 10 additions & 0 deletions zubhub_backend/zubhub/creators/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.contrib import admin
from django.contrib.auth import get_user_model
from django.contrib.auth.admin import UserAdmin

Creator = get_user_model()

UserAdmin.fieldsets += ('Personal Info', {'fields': ('avatar', 'phone', 'dateOfBirth', 'location', 'bio')}),
UserAdmin.readonly_fields += ("avatar"),

admin.site.register(Creator, UserAdmin)
5 changes: 5 additions & 0 deletions zubhub_backend/zubhub/creators/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class CreatorsConfig(AppConfig):
name = 'creators'
46 changes: 46 additions & 0 deletions zubhub_backend/zubhub/creators/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# from django.contrib.auth import get_user_model
# from django.contrib.auth.forms import ReadOnlyPasswordHashField
# from django import forms

# class UserCreationForm(forms.ModelForm):
# password1 = forms.CharField(label='Password', widget=forms.PasswordInput)
# password2 = forms.CharField(label='Password confirmation', widget=forms.PasswordInput)

# class Meta:
# model = get_user_model()
# fields = ('email','username','first_name','last_name','avatar','phone','dateOfBirth','location',)

# def clean_password2(self):
# # Check that the two password entries match
# password1 = self.cleaned_data.get("password1")
# password2 = self.cleaned_data.get("password2")
# if password1 and password2 and password1 != password2:
# raise forms.ValidationError("Passwords don't match")
# return password2

# def save(self, commit=True):
# # Save the provided password in hashed format
# user = super().save(commit=False)
# user.set_password(self.cleaned_data["password1"])
# if commit:
# user.save()
# return user


# class UserChangeForm(forms.ModelForm):
# """A form for updating users. Includes all the fields on
# the user, but replaces the password field with admin's
# password hash display field.
# """
# password = ReadOnlyPasswordHashField()

# class Meta:
# model = get_user_model()
# fields = ('email','username', 'password', 'first_name','last_name',
# 'avatar','phone','dateOfBirth','location', 'is_active', 'is_admin',)

# def clean_password(self):
# # Regardless of what the user provides, return the initial value.
# # This is done here, rather than on the field, because the
# # field does not have access to the initial value
# return self.initial["password"]
Loading