Skip to content
Permalink
Browse files
forgot to comit changes
  • Loading branch information
kailad committed Dec 5, 2019
1 parent 172c338 commit b39b269661aac638e4734043e61e2d82ddcd6fa8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 57 deletions.
@@ -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}`))
@@ -11,8 +11,6 @@
</head>
<body>
<h1>Home</h1>
<p>This is a secure page. Users need to have a valid account and be logged in to see it.</p>
<p><a href="/logout">log out</a></p>
<form action="/lights" method="get">
<p><input type="submit" value="Lights page"></p>
</form>

0 comments on commit b39b269

Please sign in to comment.