diff --git a/index.js b/index.js index 16ce947..bb88869 100644 --- a/index.js +++ b/index.js @@ -92,9 +92,6 @@ const wss = new WebSocket.Server({ */ router.get('/', async ctx => { try { - if(ctx.session.authorised !== true) return ctx.redirect('/login?msg=you need to log in') - const data = {} - if(ctx.query.msg) data.msg = ctx.query.msg await ctx.render('index') } catch(err) { await ctx.render('error', {message: err.message}) @@ -107,7 +104,6 @@ router.get('/', async ctx => { * @name Register Page * @route {GET} /register */ -router.get('/register', async ctx => await ctx.render('register')) router.get('/lights', async ctx => { try { //const temp = await new Temp(dbName) @@ -228,8 +224,9 @@ router.get('/temp', async ctx => { }) }); - if (tempfloat < 26) + if (tempfloat < 28) { + data3.heating = 'heating is on' } else @@ -243,55 +240,5 @@ router.get('/temp', async ctx => { } }) -/** - * The script to process new user registrations. - * - * @name Register Script - * @route {POST} /register - */ -router.post('/register', koaBody, async ctx => { - try { - // extract the data from the request - const body = ctx.request.body - console.log(body) - // call the functions in the module - user = await new User(dbName) - await user.register(body.user, body.pass) - // await user.uploadPicture(path, type) - // redirect to the home page - ctx.redirect(`/?msg=new user "${body.name}" added`) - } catch(err) { - await ctx.render('error', {message: err.message}) - } finally { - user.tearDown() - } -}) - -router.get('/login', async ctx => { - const data = {} - if(ctx.query.msg) data.msg = ctx.query.msg - if(ctx.query.user) data.user = ctx.query.user - await ctx.render('login', data) -}) - -router.post('/login', async ctx => { - try { - const body = ctx.request.body - user = await new User(dbName) - await user.login(body.user, body.pass) - ctx.session.authorised = true - return ctx.redirect('/?msg=you are now logged in...') - } catch(err) { - await ctx.render('error', {message: err.message}) - } finally { - user.tearDown() - } -}) - -router.get('/logout', async ctx => { - ctx.session.authorised = null - ctx.redirect('/?msg=you are now logged out') -}) - app.use(router.routes()) module.exports = app.listen(port, async() => console.log(`listening on port ${port}`)) \ No newline at end of file diff --git a/views/index.handlebars b/views/index.handlebars index 05eb63a..1bc22fc 100644 --- a/views/index.handlebars +++ b/views/index.handlebars @@ -11,8 +11,6 @@

Home

-

This is a secure page. Users need to have a valid account and be logged in to see it.

-

log out