feat(settings): Save settings in cookie
This commit is contained in:
committed by
Benedikt Rötsch
parent
3373ff282d
commit
354df3c4b4
@@ -113,6 +113,22 @@ nav ul li:last-child {
|
||||
nav ul li a {
|
||||
transform: skew(15deg);
|
||||
}
|
||||
/* Form */
|
||||
input, textarea {
|
||||
width:100%;
|
||||
padding:10px;
|
||||
border: 1px solid $grey;
|
||||
}
|
||||
|
||||
label {
|
||||
padding: 10px 0;
|
||||
display: block;
|
||||
}
|
||||
.form {
|
||||
background: white;
|
||||
padding: 2rem;
|
||||
box-shadow: $grad;
|
||||
}
|
||||
|
||||
/* Home Page __ hero*/
|
||||
.hero {
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
const express = require('express')
|
||||
const router = express.Router()
|
||||
|
||||
/* GET seeting page. */
|
||||
/* GET settings page. */
|
||||
router.get('/', function (req, res, next) {
|
||||
res.render('settings', { title: 'Settings' })
|
||||
const cookie = req.cookies.universitySettings
|
||||
const settings = cookie || { cpa: '', cda: '', space: '' }
|
||||
res.render('settings', { title: 'Settings', settings })
|
||||
})
|
||||
|
||||
/* POST settings page. */
|
||||
router.post('/', function (req, res, next) {
|
||||
const settings = {space: req.body.space, cda: req.body.cda, cpa: req.body.cpa}
|
||||
res.cookie('universitySettings', settings, { maxAge: 900000, httpOnly: true })
|
||||
res.render('settings', settings)
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
|
||||
@@ -3,7 +3,9 @@ const { createClient } = require('contentful')
|
||||
const client = createClient({space: process.env.CF_SPACE, accessToken: process.env.CF_ACCESS_TOKEN})
|
||||
|
||||
export function getCourses () {
|
||||
// TODO
|
||||
// to get all the courses we simply request from Contentful all the entries
|
||||
// with the content_type `course`
|
||||
return client.getEntries({content_type: 'course'})
|
||||
}
|
||||
|
||||
export function getLessons (courseId) {
|
||||
|
||||
@@ -2,4 +2,11 @@ extends layout
|
||||
|
||||
block content
|
||||
h1= title
|
||||
p Welcome to #{title}
|
||||
form(action=`/settings` method="POST" class="form")
|
||||
label(for="space") Space
|
||||
input(type="text" name="space" value=settings.space)
|
||||
label(for="cda") Delivery API Key
|
||||
input(type="text" name="cda" value=settings.cda)
|
||||
label(for="cpa") Preview API Key
|
||||
input(type="text" name="cpa" value=settings.cpa)
|
||||
input(type="submit" value="Save →" class="button")
|
||||
|
||||
Reference in New Issue
Block a user