1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-01 20:39:28 +00:00

Added route for registering an Account

This commit is contained in:
2022-02-13 22:11:15 +00:00
parent cbdbc92807
commit 401eaa56e1
2 changed files with 52 additions and 1 deletions

View File

@@ -3,6 +3,9 @@
const express = require('express');
const router = express.Router();
const Account = require('../lib/Account');
const validator = require('../lib/validator');
router.get('/', (req, res) => {
return res.render('index', {
title: 'Stratos - Home'
@@ -34,6 +37,49 @@ router.get('/logout', (req, res) => {
});
});
router.post('/register', async (req, res) => {
let fields;
try {
fields = validator.validate(req.body,
[
'fname',
'lname',
'email',
'password',
'confPassword'
],
{
email: 'email',
password: [ 'password', 'confPassword' ]
}
).fields;
} catch (e) {
console.error(e);
return res.status(400).json({ status: 'Invalid' });
}
let a;
try {
a = await Account.createAccount(
fields.get('fname'),
fields.get('onames'),
fields.get('lname'),
fields.get('email'),
fields.get('password')
);
} catch (e) {
console.error(e);
return res.render('error', {
code: 400,
msg: 'Unable to create account'
});
}
a.login(req);
return res.redirect('/login');
});
module.exports = {
root: '/',
router: router