Ready for release? 🤞
This commit is contained in:
parent
a8b9d9ff32
commit
80930dac4f
11 changed files with 410 additions and 32 deletions
|
|
@ -5,8 +5,7 @@ const UserSchema = new Schema({
|
|||
username: String,
|
||||
password: String,
|
||||
configs: [{
|
||||
name: String,
|
||||
conf: String
|
||||
type: String
|
||||
}]
|
||||
})
|
||||
|
||||
|
|
@ -24,15 +23,10 @@ UserSchema.methods.changePassword = function (password: string, newPassword: str
|
|||
}
|
||||
}
|
||||
|
||||
interface INamedConfig {
|
||||
name: string,
|
||||
conf: string
|
||||
}
|
||||
|
||||
export type UserModel = Document & {
|
||||
username: string,
|
||||
password: string,
|
||||
configs: Array<INamedConfig>,
|
||||
configs: Array<String>,
|
||||
generateHash: Function,
|
||||
validPassword: Function,
|
||||
changePassword: Function
|
||||
|
|
|
|||
|
|
@ -30,8 +30,14 @@ export const init = (app: Application, passport: PassportStatic) => {
|
|||
}
|
||||
})
|
||||
|
||||
app.get('/register', async (req, res) => {
|
||||
res.render('register')
|
||||
})
|
||||
|
||||
app.post('/register', async (req, res) => {
|
||||
const exUser = await UserDB.findOne({ 'email': req.body.email })
|
||||
const exUser = await UserDB.findOne({
|
||||
'username': req.body.username
|
||||
})
|
||||
if (exUser) {
|
||||
res.redirect('/register?exists')
|
||||
} else {
|
||||
|
|
@ -40,6 +46,10 @@ export const init = (app: Application, passport: PassportStatic) => {
|
|||
user.password = user.generateHash(req.body.password)
|
||||
user.configs = Array()
|
||||
await user.save()
|
||||
|
||||
req.logIn(user, () => {
|
||||
res.redirect('/')
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -19,10 +19,10 @@ export const init = (app: Application, passport: PassportStatic) => {
|
|||
await conf.save()
|
||||
|
||||
if (req.isAuthenticated() && req.user) {
|
||||
req.user.configs.push({
|
||||
name: req.body.name,
|
||||
conf: conf.shortid
|
||||
})
|
||||
req.user.configs.push(
|
||||
conf.shortid
|
||||
)
|
||||
await req.user.save()
|
||||
}
|
||||
res.status(200).send(conf)
|
||||
} catch (ex) {
|
||||
|
|
@ -32,6 +32,24 @@ export const init = (app: Application, passport: PassportStatic) => {
|
|||
}
|
||||
})
|
||||
|
||||
app.get('/configs', async (req, res) => {
|
||||
if (req.isAuthenticated() && req.user) {
|
||||
res.render('configs', {
|
||||
user: req.user
|
||||
})
|
||||
} else {
|
||||
res.redirect('/login?origin=/configs')
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/configs', async (req, res) => {
|
||||
if (req.isAuthenticated() && req.user) {
|
||||
res.json(req.user.configs)
|
||||
} else {
|
||||
res.json([])
|
||||
}
|
||||
})
|
||||
|
||||
app.get('/configs/:id', async (req, res) => {
|
||||
const conf = await ConfigDB.findOne({
|
||||
shortid: req.params.id
|
||||
|
|
|
|||
100
src/app/views/configs.ejs
Normal file
100
src/app/views/configs.ejs
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Geolosys Configurator</title>
|
||||
|
||||
<link rel="shortcut icon" href="/assets/img/logo.png" type="image/x-icon">
|
||||
|
||||
<link rel="stylesheet" href="/Libraries/font-awesome/css/all.min.css">
|
||||
<link rel="stylesheet" href="/Libraries/bootstrap/css/bootstrap.css">
|
||||
<link rel="stylesheet" href="/assets/css/base.css">
|
||||
|
||||
<script src="/Libraries/bootstrap/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="/assets/js/configs.js"></script>
|
||||
</head>
|
||||
|
||||
<body class="fade">
|
||||
<nav class="navbar navbar-expand-lg navbar-dark sticky-top bg-dark">
|
||||
<div class="container-fluid">
|
||||
<a href="/" class="navbar-brand">
|
||||
<span>
|
||||
<img width="24" src="/assets/img/logo.png"> Configurator
|
||||
</span>
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
|
||||
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav mr-auto mb-2 mb-lg-0">
|
||||
<li class="nav-item">
|
||||
<a href="/" class="nav-link">
|
||||
<span>
|
||||
<i class="far fa-plus-square"></i> Create
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
<% if(user) {%>
|
||||
<li class="nav-item">
|
||||
<a href="/configs" class="nav-link active">
|
||||
<span>
|
||||
<b>{ }</b> Your Configs
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
<% } %>
|
||||
<li class="nav-item">
|
||||
<% if(user) {%>
|
||||
<a href="/logout" class="nav-link">
|
||||
<span>
|
||||
<i class="fas fa-sign-out-alt"></i> Log Out
|
||||
</span>
|
||||
</a>
|
||||
<% } else { %>
|
||||
<a href="/login" class="nav-link">
|
||||
<span>
|
||||
<i class="fas fa-sign-in-alt"></i> Log In
|
||||
</span>
|
||||
</a>
|
||||
<% } %>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="text-center d-block">
|
||||
<img class="header" src="/assets/img/logo.png">
|
||||
<h4>Your Geolosys Configs</h4>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<table class="table m-auto" style="width: 90vw; max-width: 512px;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">Config</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="config-body">
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<nav class="navbar fixed-bottom navbar-light bg-light">
|
||||
<h6 class="text-center w-100">
|
||||
Made with 💙 by
|
||||
<a href="https://oitsjustjose.com/">oitsjustjose</a>
|
||||
</h6>
|
||||
<div class="text-center w-100">
|
||||
Source Code Hosted on
|
||||
<a href="https://github.com/oitsjustjose/geolosys-config-generator" target="_blank">GitHub</a>
|
||||
</div>
|
||||
</nav>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -39,7 +39,7 @@
|
|||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav mr-auto mb-2 mb-lg-0">
|
||||
<li class="nav-item">
|
||||
<a href="#" class="nav-link active">
|
||||
<a href="/" class="nav-link active">
|
||||
<span>
|
||||
<i class="far fa-plus-square"></i> Create
|
||||
</span>
|
||||
|
|
@ -64,7 +64,7 @@
|
|||
<% } else { %>
|
||||
<a href="/login" class="nav-link">
|
||||
<span>
|
||||
<i class="fas fa-sign-out-alt"></i> Log In
|
||||
<i class="fas fa-sign-in-alt"></i> Log In
|
||||
</span>
|
||||
</a>
|
||||
<% } %>
|
||||
|
|
@ -87,13 +87,10 @@
|
|||
|
||||
<div class="container">
|
||||
<h4>Ores</h4>
|
||||
|
||||
<div class="accordion mb-4" id="oreconfig">
|
||||
</div>
|
||||
|
||||
<h4>Stones</h4>
|
||||
|
||||
|
||||
<div class="accordion mb-4" id="stoneconfig">
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -102,14 +99,16 @@
|
|||
Generate
|
||||
</button>
|
||||
|
||||
<h5 class="text-center">
|
||||
Made with 💙 by
|
||||
<a href="https://oitsjustjose.com/">oitsjustjose</a>
|
||||
</h5>
|
||||
<h6 class="text-center">
|
||||
Source Code Hosted on
|
||||
<a href="https://github.com/oitsjustjose/geolosys-config-generator" target="_blank">GitHub</a>
|
||||
</h6>
|
||||
<nav class="navbar fixed-bottom navbar-light bg-light">
|
||||
<h6 class="text-center w-100">
|
||||
Made with 💙 by
|
||||
<a href="https://oitsjustjose.com/">oitsjustjose</a>
|
||||
</h6>
|
||||
<div class="text-center w-100">
|
||||
Source Code Hosted on
|
||||
<a href="https://github.com/oitsjustjose/geolosys-config-generator" target="_blank">GitHub</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="modal fade" tabindex="-1" id="notification">
|
||||
|
|
|
|||
|
|
@ -10,20 +10,52 @@
|
|||
|
||||
<link rel="stylesheet" href="/Libraries/font-awesome/css/all.min.css">
|
||||
<link rel="stylesheet" href="/Libraries/bootstrap/css/bootstrap.css">
|
||||
<link rel="stylesheet" href="/assets/css/base.css">
|
||||
|
||||
<script src="/Libraries/bootstrap/js/bootstrap.js"></script>
|
||||
<script src="/assets/js/login.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-dark sticky-top bg-dark">
|
||||
<div class="container-fluid">
|
||||
<a href="/" class="navbar-brand">
|
||||
<span>
|
||||
<img width="24" src="/assets/img/logo.png"> Configurator
|
||||
</span>
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
|
||||
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav mr-auto mb-2 mb-lg-0">
|
||||
<li class="nav-item">
|
||||
<a href="/" class="nav-link">
|
||||
<span>
|
||||
<i class="far fa-plus-square"></i> Create
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a href="/register" class="nav-link">
|
||||
<span>
|
||||
<i class="fas fa-user-plus"></i> Register
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container d-flex flex-column justify-content-center"
|
||||
style="width: 98vw; height: 100vh; max-width: 768px; max-height: 100vh">
|
||||
style="width: 98vw; height: 90vh; max-width: 768px; max-height: 90vh">
|
||||
<div class="d-block text-center header">
|
||||
<h2>
|
||||
Geolosys Configurator Login
|
||||
</h2>
|
||||
<h4>
|
||||
By: oitsjustjose (Jose)
|
||||
</h4>
|
||||
</div>
|
||||
<form action="/login" method="POST">
|
||||
<div class="mb-3">
|
||||
|
|
@ -38,7 +70,6 @@
|
|||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="modal fade" tabindex="-1" id="notification">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
|
|
|
|||
107
src/app/views/register.ejs
Normal file
107
src/app/views/register.ejs
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Geolosys Configurator Login</title>
|
||||
|
||||
<link rel="shortcut icon" href="/assets/img/logo.png" type="image/x-icon">
|
||||
|
||||
<link rel="stylesheet" href="/Libraries/font-awesome/css/all.min.css">
|
||||
<link rel="stylesheet" href="/Libraries/bootstrap/css/bootstrap.css">
|
||||
<link rel="stylesheet" href="/assets/css/base.css">
|
||||
|
||||
<script src="/Libraries/bootstrap/js/bootstrap.js"></script>
|
||||
<script src="/assets/js/register.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-dark sticky-top bg-dark">
|
||||
<div class="container-fluid">
|
||||
<a href="/" class="navbar-brand">
|
||||
<span>
|
||||
<img width="24" src="/assets/img/logo.png"> Configurator
|
||||
</span>
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
|
||||
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav mr-auto mb-2 mb-lg-0">
|
||||
<li class="nav-item">
|
||||
<a href="/" class="nav-link">
|
||||
<span>
|
||||
<i class="far fa-plus-square"></i> Create
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a href="/login" class="nav-link">
|
||||
<span>
|
||||
<i class="fas fa-sign-in-alt"></i> Log In
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container d-flex flex-column justify-content-center last"
|
||||
style="width: 98vw; height: 90vh; max-width: 768px; max-height: 90vh">
|
||||
<div class="d-block text-center header">
|
||||
<h2>
|
||||
Geolosys Configurator Account Registration
|
||||
</h2>
|
||||
</div>
|
||||
<form action="/register" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Username</label>
|
||||
<input type="text" class="form-control" name="username" id="username" oninput="checkUsername(this)"
|
||||
required>
|
||||
<div class="invalid-feedback">
|
||||
Password Must Be At Least 6 Characters
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" class="form-control" name="password" id="password" oninput="checkPass(this)"
|
||||
required>
|
||||
<div class="invalid-feedback">
|
||||
Password Must Be At Least 8 Characters
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Confirm Password</label>
|
||||
<input type="password" class="form-control" name="password-conf" id="password-conf"
|
||||
oninput="checkPassConf(this)" required>
|
||||
<div class="invalid-feedback">
|
||||
Passwords Must Match
|
||||
</div>
|
||||
</div>
|
||||
<button id="register-btn" type="submit" class="btn btn-primary"
|
||||
onclick="location.href = '/register'">Register</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" tabindex="-1" id="notification">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"></h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -5,4 +5,4 @@ img.header {
|
|||
|
||||
input.json-invalid {
|
||||
border: 4px solid red;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
39
src/public/assets/js/configs.js
Normal file
39
src/public/assets/js/configs.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
window.addEventListener('load', async () => {
|
||||
const resp = await fetch('/configs', {
|
||||
method: 'POST'
|
||||
});
|
||||
|
||||
const configs = await resp.json();
|
||||
render(configs);
|
||||
|
||||
/* Give the body enough space for a bottom navbar */
|
||||
document.body.style.paddingBottom = `${document.querySelector('.navbar.fixed-bottom').clientHeight}px`;
|
||||
|
||||
document.body.classList.add('show');
|
||||
});
|
||||
|
||||
const render = (configs) => {
|
||||
for (const [idx, config] of configs.entries()) {
|
||||
const row = makeRow(idx, config);
|
||||
document.getElementById('config-body').appendChild(row);
|
||||
}
|
||||
};
|
||||
|
||||
const makeRow = (idx, config) => {
|
||||
const row = document.createElement('tr');
|
||||
|
||||
const rowHead = document.createElement('th');
|
||||
rowHead.setAttribute('scope', 'row');
|
||||
rowHead.innerText = `${idx + 1}`;
|
||||
|
||||
const jsonD = document.createElement('td');
|
||||
const json = document.createElement('a');
|
||||
json.href = `${location.origin}/configs/${config}`;
|
||||
json.innerText = config;
|
||||
|
||||
jsonD.appendChild(json);
|
||||
row.appendChild(rowHead);
|
||||
row.appendChild(jsonD);
|
||||
|
||||
return row;
|
||||
};
|
||||
|
|
@ -7,5 +7,9 @@ window.addEventListener('load', () => {
|
|||
OreFormRenderer.init();
|
||||
StoneFormRenderer.init();
|
||||
events.init();
|
||||
|
||||
/* Give the body enough space for a bottom navbar */
|
||||
document.body.style.paddingBottom = `${document.querySelector('.navbar.fixed-bottom').clientHeight}px`;
|
||||
|
||||
document.body.classList.add('show');
|
||||
});
|
||||
76
src/public/assets/js/register.js
Normal file
76
src/public/assets/js/register.js
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
window.addEventListener('load', () => {
|
||||
const queries = new URLSearchParams(location.search);
|
||||
|
||||
if (queries.has('exists')) {
|
||||
makeNotification('Username Already Exists', 'Sorry - that username already exists 😭');
|
||||
history.replaceState(null, '', location.href.replace('?exists', ''));
|
||||
}
|
||||
});
|
||||
|
||||
const validations = {
|
||||
username: false,
|
||||
pass: false,
|
||||
passConf: false
|
||||
};
|
||||
|
||||
|
||||
const checkUsername = (username) => {
|
||||
if (username.value.length < 6) {
|
||||
username.classList.add('is-invalid');
|
||||
document.getElementById('register-btn').disabled = true;
|
||||
validations.username = false;
|
||||
} else {
|
||||
validations.username = true;
|
||||
if (validations.pass && validations.passConf && validations.username) {
|
||||
document.getElementById('register-btn').disabled = false;
|
||||
}
|
||||
username.classList.remove('is-invalid');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {HTMLInputElement} password
|
||||
*/
|
||||
const checkPass = (password) => {
|
||||
if (password.value.length < 8) {
|
||||
password.classList.add('is-invalid');
|
||||
document.getElementById('register-btn').disabled = true;
|
||||
validations.pass = false;
|
||||
} else {
|
||||
validations.pass = true;
|
||||
if (validations.pass && validations.passConf && validations.username) {
|
||||
document.getElementById('register-btn').disabled = false;
|
||||
}
|
||||
password.classList.remove('is-invalid');
|
||||
checkPassConf(document.getElementById('password-conf'));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {HTMLInputElement} password
|
||||
*/
|
||||
const checkPassConf = (password) => {
|
||||
if (password.value != document.getElementById('password').value) {
|
||||
password.classList.add('is-invalid');
|
||||
document.getElementById('register-btn').disabled = true;
|
||||
validations.passConf = false;
|
||||
} else {
|
||||
validations.passConf = true;
|
||||
if (validations.pass && validations.passConf && validations.username) {
|
||||
document.getElementById('register-btn').disabled = false;
|
||||
}
|
||||
password.classList.remove('is-invalid');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const makeNotification = (title, contents) => {
|
||||
const modal = document.getElementById('notification');
|
||||
|
||||
modal.querySelector('.modal-title').innerHTML = title;
|
||||
modal.querySelector('.modal-body').innerHTML = contents;
|
||||
|
||||
new bootstrap.Modal(modal).show();
|
||||
};
|
||||
Loading…
Reference in a new issue