Add page to create user

main
sudoer777 2021-11-24 18:25:27 -07:00
parent 7520580d66
commit 48c2ee67bd
5 changed files with 45 additions and 2 deletions

2
app.js
View File

@ -14,6 +14,7 @@ var usersRouter = require('./routes/users');
var dataRouter = require('./routes/data');
var manageRouter = require('./routes/manage');
var authRouter = require('./routes/auth');
var adminRouter = require('./routes/admin');
var app = express();
@ -49,6 +50,7 @@ app.use('/users', usersRouter);
app.use('/data', dataRouter);
app.use('/manage', manageRouter);
app.use('/auth', authRouter);
app.use('/admin', adminRouter);
// catch 404 and forward to error handler

View File

@ -48,4 +48,6 @@ async function createUser(email, password) {
const query = `INSERT INTO accounts.users(email, password)
VALUES($1, $2)`;
await database.executeQuery(query, [email, hash]);
}
}
exports.createUser = createUser;

12
routes/admin.js 100644
View File

@ -0,0 +1,12 @@
var express = require('express');
var router = express.Router();
const passport = require('passport');
const app = require('../app');
const accounts = require('./../database/accounts/accounts');
router.get('/createuser', (req, res, next) => {
res.render('accounts/createuser', { title: 'Create user' });
});
module.exports = router;

View File

@ -1,5 +1,7 @@
const passport = require('passport');
var express = require('express');
var router = express.Router();
const passport = require('passport');
const accounts = require('./../database/accounts/accounts');
const app = require('../app');
router.post('/login', passport.authenticate('local'), (req, res, next) => {
@ -8,4 +10,9 @@ router.post('/login', passport.authenticate('local'), (req, res, next) => {
res.json(user);
});
router.post('/register', (req, res, next) => {
accounts.createUser(req.body.email, req.body.password)
.then(res.redirect('/'));
});
module.exports = router;

View File

@ -0,0 +1,20 @@
extends ../layout
block stylesheets
link(rel='stylesheet', href='/stylesheets/submit.css')
link(rel='stylesheet', href='/stylesheets/form.css')
block content
div#mobile-view
h1 #{title}
form(action='/auth/register', method='POST')
span(class='form-section')
label Email
span(class='form-section-input')
input(type="email", name="email")
span(class='form-section')
label Password
span(class='form-section-input')
input(type="password", name="password")
span(class='form-section')
button#submit-button(type="submit") Submit