Fixed merge conflict in reimbursinator/urls.py

This commit is contained in:
Rupika 2019-01-19 22:39:07 -08:00
commit be5c722eca
19 changed files with 264 additions and 69 deletions

View file

@ -6,7 +6,7 @@ verify_ssl = true
[dev-packages]
[packages]
django = "==1.10.7"
django = "==2.1.4"
gunicorn = "==19.6.0"
[requires]

0
back/backend/__init__.py Normal file
View file

5
back/backend/admin.py Normal file
View file

@ -0,0 +1,5 @@
from django.contrib import admin
from .models import BackEnd
# Register your models here.
admin.site.register(BackEnd)

5
back/backend/apps.py Normal file
View file

@ -0,0 +1,5 @@
from django.apps import AppConfig
class BackendConfig(AppConfig):
name = 'backend'

View file

@ -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()),
],
),
]

View file

13
back/backend/models.py Normal file
View file

@ -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

3
back/backend/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

16
back/backend/views.py Normal file
View file

@ -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)

0
back/manage.py Normal file → Executable file
View file

View file

@ -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

View file

@ -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),
]

View file

@ -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"

View file

@ -1,38 +1,58 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, width=device-width" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous"/>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<title>Reimbursinator</title>
<link rel="shortcut icon" href="/favicon.ico" />
</head>
<body>
<div class="container">
<div class="jumbotron"><h1>Reimbursinator Report</h1></div>
<nav class="navbar">
<ul class="nav nav-tabs mr-auto">
<li class="nav-item">
<a class="nav-link active" href="#">New</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Unfinished</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">History</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Others</a>
</li>
</ul>
<ul class="nav justify-content-end">
<li class="nav-item">
<a class="nav-link" href="#">Logout</a>
</li>
</ul>
</nav>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<link rel="shortcut icon" href="/favicon.ico">
<title>Reimbursinator</title>
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-dark bg-primary">
<a class="navbar-brand" href="#">Reimbursinator</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsing-dashboard-navbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsing-dashboard-navbar">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link log-out-link" href="#">
<i class="fas fa-sign-out-alt"></i>
Log out
</a>
</li>
</ul>
</div>
</body>
</nav>
<div class="container">
<div class="jumbotron">
<h1>Reimbursinator Report</h1>
</div>
<nav class="navbar">
<ul class="nav nav-tabs mr-auto">
<li class="nav-item">
<a class="nav-link active" href="#">New</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Unfinished</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">History</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Others</a>
</li>
</ul>
<ul class="nav justify-content-end">
<li class="nav-item">
<a class="nav-link log-out-link" href="#">Log out</a>
</li>
</ul>
</nav>
</div>
<script src="logout.js"></script>
</body>
</html>

View file

@ -2,14 +2,37 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, width=device-width">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<link rel="shortcut icon" href="/favicon.ico">
<title>Reimbursinator</title>
<link rel="shortcut icon" href="/favicon.ico" />
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-dark bg-primary">
<a class="navbar-brand" href="#">Reimbursinator</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsing-index-navbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsing-index-navbar">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="login.html">
<i class="fas fa-sign-in-alt"></i>
Log in
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="signup.html">
<i class="fas fa-user-plus"></i>
Sign up
</a>
</li>
</ul>
</div>
</nav>
<div class="container">
<div class="jumbotron">
<h1>Reimbursinator</h1>
@ -19,7 +42,7 @@
<a class="nav-link active" href="signup.html">Sign up</a>
</li>
<li class="nav-item">
<a class="nav-link" href="login.html">Login</a>
<a class="nav-link" href="login.html">Log in</a>
</li>
</ul>
</div>

View file

@ -3,18 +3,24 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<title>Login</title>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<link rel="shortcut icon" href="/favicon.ico">
<title>Log in</title>
</head>
<body>
<h1>Login Page</h1>
<form>
username: <input type="text" name="username" required><br>
password: <input type="password" name="password" required><br>
<input type="submit" name="submit" value="submit">
</form>
<!-- TODO: add script link here -->
</body>
<body>
<nav class="navbar navbar-expand-sm navbar-dark bg-primary">
<a class="navbar-brand" href="index.html">Reimbursinator</a>
</nav>
<h1>Log in</h1>
<form method="POST">
username: <input type="text" name="username" required><br>
password: <input type="password" name="password" required><br>
<input type="submit" name="submit" value="submit">
</form>
<p id="errorReport"><p>
<script src="login.js"></script>
</body>
</html>

45
front/static/login.js Normal file
View file

@ -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);

34
front/static/logout.js Normal file
View file

@ -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);

View file

@ -3,20 +3,25 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<link rel="shortcut icon" href="/favicon.ico">
<title>Sign up</title>
</head>
<body>
<h1>Sign up page</h1>
<form id="signup">
User Name: <input type="text" id="userName" minlength="4" size="10" required="required"><br>
Password: <input type="password" id="password" minlength="4" size="10" required="required"><br>
Confirm Password: <input type="password" id="confirmPassword"><br>
<input type="submit" value="Submit" formaction="index.html">
<a class="nav-link" href="index.html">Return to main menu</a>
</form>
<nav class="navbar navbar-expand-sm navbar-dark bg-primary">
<a class="navbar-brand" href="index.html">Reimbursinator</a>
</nav>
<h1>Sign up page</h1>
<form id="signup">
User Name: <input type="text" id="userName" minlength="4" size="10" required="required"><br>
Password: <input type="password" id="password" minlength="4" size="10" required="required"><br>
Confirm Password: <input type="password" id="confirmPassword"><br>
<input type="submit" value="Submit" formaction="index.html">
<a class="nav-link" href="index.html">Return to main menu</a>
</form>
</body>
<script src="signupPage.js"></script>
</html>
</html>