aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md6
-rw-r--r--src/server.js35
-rw-r--r--src/templates.js3
-rw-r--r--src/templates/about.html34
-rw-r--r--src/templates/expected.html1
-rw-r--r--src/templates/goals.html1
-rw-r--r--src/templates/ledger.html1
-rw-r--r--src/templates/login.html29
-rw-r--r--src/templates/sign-up.html23
-rw-r--r--src/templates/summary.html1
10 files changed, 103 insertions, 31 deletions
diff --git a/README.md b/README.md
index 40f54a5..9d6d27b 100644
--- a/README.md
+++ b/README.md
@@ -24,5 +24,9 @@ fill out a `config.json` file as specified below, and then `npm run run`.
- Add expected summary (maybe in /summary? compare to averages?)
- add rolling category values (grocery last month, last year, all time)
- Add graphs
-- Add initial balance somewhere
- Add assets/liabilities?
+- Add profile page
+ - Add initial balance somewhere
+ - Reset password
+- Add admin page
+- Add signup page with code needed \ No newline at end of file
diff --git a/src/server.js b/src/server.js
index 5d6cf9f..541f467 100644
--- a/src/server.js
+++ b/src/server.js
@@ -26,7 +26,8 @@ function hashWithSalt(password, salt) {
function setUpRoutes(models, jwtFunctions, database, templates) {
// Authentication routine
server.use(async function (req, res, next) {
- if (!req.path.toLowerCase().startsWith("/login")) {
+ let path = req.path.toLowerCase();
+ if (!path.startsWith("/login")) {
let cookie = req.cookies.authorization
if (!cookie) {
console.debug("Redirecting to login - no cookie")
@@ -58,10 +59,18 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
server.use('/static', express.static(path.join(__dirname, '/static')))
server.get('/', (req, res) => res.redirect("/ledger"))
+ server.get('/about', (req, res) => {
+ let body = templates["about"]({});
+ res.status(200).send(body)
+ })
server.get('/login', (req, res) => {
let body = templates["login"]({});
res.status(200).send(body)
})
+ server.get('/login/signup', async (req, res) => {
+ let body = templates["signup"]({});
+ res.status(200).send(body)
+ })
server.get('/ledger', async (req, res) => {
var ledger = await database.query(`SELECT * FROM transactions WHERE username = '${res.locals.user.username}' ORDER BY \`when\` DESC`, { type: database.QueryTypes.SELECT })
ledger.forEach((element, i) => {
@@ -134,6 +143,30 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
res.redirect('/login');
}
})
+ server.post('/login/signup', async (req, res) => {
+ if(req.body.code != config.signup_code){
+ console.debug("Redirecting to signup - bad code")
+ res.redirect('/login/signup');
+ return;
+ }
+ const user = await models.users.findOne({ where: { username: req.body.username } })
+ if(user){
+ console.debug("Redirecting to signup - user already exists")
+ res.redirect('/login/signup');
+ return;
+ }
+ let salt = crypto.randomBytes(32).toString("Base64");
+ let password = req.body.password
+ const hash = hashWithSalt(password, salt)
+ let new_user = {
+ username: req.body.username,
+ password: hash,
+ salt: salt
+ }
+ await models.users.create(new_user);
+ console.debug("Created account - log in")
+ res.redirect("/login")
+ })
server.post(`/transaction`, async (req, res, next) => {
try {
let item = req.body;
diff --git a/src/templates.js b/src/templates.js
index f7bfdfb..28435f8 100644
--- a/src/templates.js
+++ b/src/templates.js
@@ -9,8 +9,9 @@ function loadTemplate(templates, name, filepath){
function setUpTemplates(){
let templates = {};
-
+ loadTemplate(templates, "about", path.join(__dirname, 'templates/about.html'))
loadTemplate(templates, "login", path.join(__dirname, 'templates/login.html'))
+ loadTemplate(templates, "signup", path.join(__dirname, 'templates/sign-up.html'))
loadTemplate(templates, "ledger", path.join(__dirname, 'templates/ledger.html'))
loadTemplate(templates, "ledger-edit", path.join(__dirname, 'templates/ledger-edit.html'))
loadTemplate(templates, "goals", path.join(__dirname, 'templates/goals.html'))
diff --git a/src/templates/about.html b/src/templates/about.html
new file mode 100644
index 0000000..314545e
--- /dev/null
+++ b/src/templates/about.html
@@ -0,0 +1,34 @@
+<!doctype html>
+<html lang="en">
+
+<head>
+ <title>Mark's Database - Login</title>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
+ <link rel="stylesheet" type="text/css" href="/css/styles.css">
+</head>
+
+<body>
+ <div>
+ <a href="/ledger"><button class="bold">Ledger</button></a>
+ <a href="/summary"><button>Summary</button></a>
+ <a href="/goals"><button>Goals</button></a>
+ <a href="/expected"><button>Expected</button></a>
+ <a href="/about"><button>About</button></a>
+ </div>
+ <div>
+ <h1>About</h1>
+ <p>Welcome to the alpha budget app! You've been given exclusive access to this secret trial</p>
+ <p>Here is how I use this site</p>
+ <ol>
+ <li>Expenses go in <em>Ledger</em>. Income also goes in the ledger as negative</li>
+ <li>The category I use for big categories: bills, groceries, restaurants</li>
+ <li>Inside tags (which aren't csv yet) I have specifics: internet, coffee, gas</li>
+ <li><em>Summary</em> gives some view of where money is going and coming from</li>
+ <li><em>Expected</em> is what I expect in an out, for a period of days. For example, I pay internet every 31 days, and renew my domain every 365 days</li>
+ <li><em>Goals</em> can be used to subdivide net savings into categories. It is still W.I.P.</li>
+ </ol>
+ </div>
+</body>
+
+</html> \ No newline at end of file
diff --git a/src/templates/expected.html b/src/templates/expected.html
index 99bf6fd..64841a5 100644
--- a/src/templates/expected.html
+++ b/src/templates/expected.html
@@ -14,6 +14,7 @@
<a href="/summary"><button>Summary</button></a>
<a href="/goals"><button>Goals</button></a>
<a href="/expected"><button class="bold">Expected</button></a>
+ <a href="/about"><button>About</button></a>
</div>
<form method="post" action="/expected">
diff --git a/src/templates/goals.html b/src/templates/goals.html
index b617a6e..b5dbe42 100644
--- a/src/templates/goals.html
+++ b/src/templates/goals.html
@@ -14,6 +14,7 @@
<a href="/summary"><button>Summary</button></a>
<a href="/goals"><button class="bold">Goals</button></a>
<a href="/expected"><button>Expected</button></a>
+ <a href="/about"><button>About</button></a>
</div>
<form method="post" action="/goals">
diff --git a/src/templates/ledger.html b/src/templates/ledger.html
index f5c46de..543ee3a 100644
--- a/src/templates/ledger.html
+++ b/src/templates/ledger.html
@@ -15,6 +15,7 @@
<a href="/summary"><button>Summary</button></a>
<a href="/goals"><button>Goals</button></a>
<a href="/expected"><button>Expected</button></a>
+ <a href="/about"><button>About</button></a>
</div>
<form method="post" action="/transaction">
<input id="datePicker" name="when" placeholder="date" type="date">
diff --git a/src/templates/login.html b/src/templates/login.html
index f090108..dcf8f8e 100644
--- a/src/templates/login.html
+++ b/src/templates/login.html
@@ -2,37 +2,10 @@
<html lang="en">
<head>
- <title>Mark's Database - Login</title>
+ <title>Login</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" type="text/css" href="/css/styles.css">
- <script>
- let usernameEl = document.getElementById('username');
- let passwordEl = document.getElementById('password');
- function sendPost(){
- let username = usernameEl.value;
- let password = passwordEl.value;
- fetch(new Request("/login", {
- method: 'POST',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({'username':username, 'password':password})
- }))
- .then((response) => {
- console.log(response);
- window.location = "/";
- });
- }
- let onEnterEvent = function(event) {
- if (event.keyCode === 13) {
- sendPost()
- }
- }
- usernameEl.addEventListener("keyup", onEnterEvent);
- passwordEl.addEventListener("keyup", onEnterEvent);
- </script>
</head>
<body>
diff --git a/src/templates/sign-up.html b/src/templates/sign-up.html
new file mode 100644
index 0000000..81789bf
--- /dev/null
+++ b/src/templates/sign-up.html
@@ -0,0 +1,23 @@
+<!doctype html>
+<html lang="en">
+
+<head>
+ <title>Sign Up</title>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
+ <link rel="stylesheet" type="text/css" href="/css/styles.css">
+</head>
+
+<body>
+ <div>
+ <h1>Sign up!</h1>
+ <form method="post" action="/login/signup">
+ <input name="username" type="text" placeholder="Enter Username" required>
+ <input type="password" placeholder="Enter Password" name="password" required>
+ <input type="text" placeholder="Secret code" name="code" required>
+ <input type="submit" vallue="Log in">
+ </div>
+ </div>
+</body>
+
+</html> \ No newline at end of file
diff --git a/src/templates/summary.html b/src/templates/summary.html
index bdc2f44..a998be9 100644
--- a/src/templates/summary.html
+++ b/src/templates/summary.html
@@ -14,6 +14,7 @@
<a href="/summary"><button class="bold">Summary</button></a>
<a href="/goals"><button>Goals</button></a>
<a href="/expected"><button>Expected</button></a>
+ <a href="/about"><button>About</button></a>
</div>
<div class="summary-panel">