Add page to create user
parent
7520580d66
commit
48c2ee67bd
2
app.js
2
app.js
|
@ -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
|
||||
|
|
|
@ -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;
|
|
@ -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;
|
|
@ -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;
|
|
@ -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
|
Reference in New Issue