diff --git a/back/Pipfile b/back/Pipfile index b7f1045..876b3dc 100644 --- a/back/Pipfile +++ b/back/Pipfile @@ -6,7 +6,7 @@ verify_ssl = true [dev-packages] [packages] -django = "==1.10.7" +django = "==2.1.4" gunicorn = "==19.6.0" [requires] diff --git a/back/backend/__init__.py b/back/backend/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/back/backend/admin.py b/back/backend/admin.py new file mode 100644 index 0000000..0a3bcde --- /dev/null +++ b/back/backend/admin.py @@ -0,0 +1,5 @@ +from django.contrib import admin +from .models import BackEnd + +# Register your models here. +admin.site.register(BackEnd) diff --git a/back/backend/apps.py b/back/backend/apps.py new file mode 100644 index 0000000..6a244a2 --- /dev/null +++ b/back/backend/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class BackendConfig(AppConfig): + name = 'backend' diff --git a/back/backend/migrations/0001_initial.py b/back/backend/migrations/0001_initial.py new file mode 100644 index 0000000..4fde024 --- /dev/null +++ b/back/backend/migrations/0001_initial.py @@ -0,0 +1,22 @@ +# Generated by Django 2.1.5 on 2019-01-17 06:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='BackEnd', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=200)), + ('description', models.TextField()), + ], + ), + ] diff --git a/back/backend/migrations/__init__.py b/back/backend/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/back/backend/models.py b/back/backend/models.py new file mode 100644 index 0000000..30f96de --- /dev/null +++ b/back/backend/models.py @@ -0,0 +1,13 @@ +from django.db import models + +# Create your models here. + + +class BackEnd(models.Model): + title = models.CharField(max_length=200) + description = models.TextField() + + def __str__(self): + """A string representation of the model.""" + return self.title + diff --git a/back/backend/tests.py b/back/backend/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/back/backend/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/back/backend/views.py b/back/backend/views.py new file mode 100644 index 0000000..a11275b --- /dev/null +++ b/back/backend/views.py @@ -0,0 +1,16 @@ +from django.shortcuts import render +from django.http import JsonResponse + + +# Create your views here. + +# each stub. +def profile(request): + data = { + 'name': 'Vitor', + 'location': 'Finland', + 'is_active': True, + 'count': 28 + } + + return JsonResponse(data) diff --git a/back/manage.py b/back/manage.py old mode 100644 new mode 100755 diff --git a/back/reimbursinator/settings.py b/back/reimbursinator/settings.py index 7b526da..f17a05c 100644 --- a/back/reimbursinator/settings.py +++ b/back/reimbursinator/settings.py @@ -20,7 +20,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'w*d2$rg#i88&6^9u2)jl0!4_)=_e1)0fxreofqzb(qxaw$3+$d' +SECRET_KEY = '5(ucf-232_)x@1ck($8ck=zwh%q=p++-0j@qh=835cuqh3ic-y' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True diff --git a/back/reimbursinator/urls.py b/back/reimbursinator/urls.py index d5ef412..04f4d6d 100644 --- a/back/reimbursinator/urls.py +++ b/back/reimbursinator/urls.py @@ -14,12 +14,8 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.conf.urls import url, include -# from django.urls import path, include +from django.urls import path urlpatterns = [ - # path('admin/', admin.site.urls), - # path('username/reports/', include('backend.urls')) - url(r'^admin/', admin.site.urls), - url(r'^username/reports/', include('backend.urls')) + path('admin/', admin.site.urls), ] diff --git a/docker-compose.yml b/docker-compose.yml index dea2bf8..bd21cbc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,9 @@ -version: '3.3' +version: '2.0' services: api: build: ./back + image: reimbursinator_back command: gunicorn --bind 0.0.0.0:444 --keyfile /etc/ssl/private/selfsigned.key --certfile /etc/ssl/private/selfsigned.crt reimbursinator.wsgi:application #volumes: # - ./app/:/usr/src/back/ @@ -12,6 +13,7 @@ services: - SECRET_KEY=please_change web: build: ./front + image: reimbursinator_front image: nginx:1.10.3 ports: - "8443:443" diff --git a/front/static/dashboard.html b/front/static/dashboard.html index 299c8e0..a8b588e 100644 --- a/front/static/dashboard.html +++ b/front/static/dashboard.html @@ -1,38 +1,58 @@ - + - - - - - - - Reimbursinator - - - -
-

Reimbursinator Report

- + + + + + + + + + Reimbursinator + + + +
+
+

Reimbursinator Report

+
+ +
+ + diff --git a/front/static/index.html b/front/static/index.html index bdab667..ff26455 100644 --- a/front/static/index.html +++ b/front/static/index.html @@ -2,14 +2,37 @@ - + + - + + Reimbursinator - +

Reimbursinator

@@ -19,7 +42,7 @@ Sign up
diff --git a/front/static/login.html b/front/static/login.html index 39b3960..5f44283 100644 --- a/front/static/login.html +++ b/front/static/login.html @@ -3,18 +3,24 @@ + - - Login + + + Log in - -

Login Page

-
- username:
- password:
- -
- - + + +

Log in

+
+ username:
+ password:
+ +
+

+ + diff --git a/front/static/login.js b/front/static/login.js new file mode 100644 index 0000000..20217d3 --- /dev/null +++ b/front/static/login.js @@ -0,0 +1,45 @@ +function displayErrorMessage(errorMessage) { + const errorReport = document.querySelector("#errorReport"); + errorReport.innerHTML = JSON.parse(errorMessage).error; +} + +function postToLoginEndpoint(event) { + event.preventDefault(); + + const credentials = { + "username" : this.elements.username.value, + "password" : this.elements.password.value + } + const url = "https://reqres.in/api/login" // mock api service + const xhr = new XMLHttpRequest(); + + console.log(`User credentials:\n${JSON.stringify(credentials)}`); + + xhr.open("POST", url, true); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.onreadystatechange = function() { + if (this.readyState === 4) { + if (this.status === 200) { + console.log("LOGIN SUCCESS!"); + console.log(`Server response:\n${this.response}`); + token = JSON.parse(this.response).token; + localStorage.setItem("token", token); + window.location.replace("dashboard.html"); + } else { + console.log("LOGIN FAILURE!"); + console.log(`Server status: ${this.status}`); + console.log(`Server response:\n${this.response}`); + displayErrorMessage(this.response); + } + } + }; + + xhr.onerror = function() { + alert("Error connecting to the authentication server!"); + }; + + xhr.send(JSON.stringify(credentials)); +} + +const form = document.querySelector("form"); +form.addEventListener("submit", postToLoginEndpoint); diff --git a/front/static/logout.js b/front/static/logout.js new file mode 100644 index 0000000..e7a3a21 --- /dev/null +++ b/front/static/logout.js @@ -0,0 +1,34 @@ +function postToLogoutEndpoint(event) { + event.preventDefault(); + + const token = localStorage.getItem("token"); + const url = "https://reqres.in/api/logout" // mock api service + const xhr = new XMLHttpRequest(); + + xhr.open("POST", url, true); + xhr.setRequestHeader("Authorization", `Token ${token}`); + xhr.onreadystatechange = function() { + if (this.readyState === 4) { + if (this.status === 200) { + console.log("LOGOUT SUCCESS!"); + console.log(`Server response:\n${this.response}`); + localStorage.removeItem("token"); + window.location.replace("index.html"); + } else { + console.log("LOGOUT FAILURE!"); + console.log(`Server status: ${this.status}`); + console.log(`Server response:\n${this.response}`); + } + } + }; + + xhr.onerror = function() { + alert("Error connecting to authentication server!"); + }; + + xhr.send(); +} + +const logoutLinks = document.querySelectorAll(".log-out-link"); +logoutLinks[0].addEventListener("click", postToLogoutEndpoint); +logoutLinks[1].addEventListener("click", postToLogoutEndpoint); diff --git a/front/static/signup.html b/front/static/signup.html index 43a62cd..7635b4e 100644 --- a/front/static/signup.html +++ b/front/static/signup.html @@ -3,20 +3,25 @@ + - + + Sign up -

Sign up page

-
- User Name:
- Password:
- Confirm Password:
- - Return to main menu -
+ +

Sign up page

+
+ User Name:
+ Password:
+ Confirm Password:
+ + Return to main menu +
- \ No newline at end of file +