+let jst_server = (await import('@ndcode/jst_server')).default
+
return async (root, session) => {
let signed_in_as = await session.get_json('signed_in_as')
if (signed_in_as === undefined)
- return undefined
- let accounts = await root.get('accounts', {})
- return await accounts.get(signed_in_as, {})
+ throw new jst_server.Problem(
+ 'Unauthorized',
+ 'Please sign in first.',
+ 401
+ )
+ let accounts = await root.get('accounts')
+ let account = accounts.get(signed_in_as)
+ if (account === undefined)
+ throw new jst_server.Problem(
+ 'Account expired',
+ 'Database is inconsistent, please sign out and recreate your account.'
+ 507
+ )
+ return account
}
+let jst_server = (await import('@ndcode/jst_server')).default
+
return async (root, component_names) => {
let p = await root.get('navigation')
+ if (p === undefined)
+ throw new jst_server.Problem(
+ 'Navigation error',
+ 'Please import the navigation tree into the database.',
+ 508
+ )
for (let i = 0; i < component_names.length; ++i) {
let children = await p.get('children')
p = await children.get(component_names[i])
+ if (p === undefined)
+ throw new jst_server.Problem(
+ 'Navigation error',
+ `Can't find the path "${
+ component_names.slice(0, i + 1).map(name => '/' + name).join('')
+ }" in the navigation tree.`,
+ 508
+ )
}
return p
}
+let jst_server = (await import('@ndcode/jst_server')).default
let nodemailer = require('nodemailer')
return async (root, name) => {
let nodemailers = await root.get('nodemailers')
- return nodemailer.createTransport(await nodemailers.get_json(name))
+ if (nodemailers === undefined)
+ throw new Problem(
+ 'Nodemailer error',
+ 'Please import the nodemailers data into the database.',
+ 509
+ )
+ let _nodemailer = await nodemailers.get_json(name)
+ throw new Problem(
+ 'Nodemailer error',
+ `Can't find the nodemailer "${name}" in the nodemailers data.',
+ 509
+ )
+ return nodemailer.createTransport(_nodemailer)
}
-let XDate = require('xdate')
+let jst_server = (await import('@ndcode/jst_server')).default
return async (env, root) => {
- let sessions = await root.get('sessions', {})
+ let sessions = await root.get('sessions')
let session = await sessions.get(env.session_key)
- if (session === undefined) {
+ if (session === undefined || env.now >= await session.get_json('expires'))
// this should never happen, but could happen if we take more than a day
// to process an incoming request, and database is cleaned in the meantime
- let expires = new XDate(env.now)
- expires.addDays(1)
- session = Transaction.json_to_logjson({expires: expires.getTime()})
- sessions.set(env.session_key, session)
- }
+ throw new jst_server.Problem(
+ 'Session expired',
+ 'We took too long to process an incoming request, please try again.'
+ 506
+ )
return session
}
let assert = require('assert')
+let jst_server = (await import('@ndcode/jst_server')).default
let XDate = require('xdate')
let arrays_equal =
copyright = await globals.get_json('copyright')
let navigation = await root.get('navigation')
-
+ if (navigation === undefined)
+ throw new jst_server.Problem(
+ 'Navigation error',
+ 'Please import the navigation tree into the database.',
+ 508
+ )
+
+ // this code is taken from get_navigation.jst and instrumented
let p = navigation
component_titles = [await p.get_json('title')] // Home
for (let i = 0; i < component_names.length; ++i) {
let children = await p.get('children')
p = await children.get(component_names[i])
+ if (navigation === undefined)
+ throw new jst_server.Problem(
+ 'Navigation error',
+ `Can't find the path "${
+ component_names.slice(0, i + 1).map(name => '/' + name).join('')
+ }" in the navigation tree.`,
+ 508
+ )
component_titles.push(await p.get_json('title'))
}
+ // similar to above but walks the top level laterally (not deeply)
menu_names = await navigation.get_json('menu')
let children = await navigation.get('children')
menu_titles = [await navigation.get_json('title')] // Home
for (let i = 0; i < menu_names.length; ++i) {
let child = await children.get(menu_names[i])
+ if (child === undefined)
+ throw new jst_server.Problem(
+ 'Navigation error',
+ `Can't find the path "/${menu_names[i]}" in the navigation tree.`
+ 508
+ )
menu_titles.push(await child.get('title'))
}
// initialize env.session_key, set cookie in env.response
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
let pageviews = await root.get('pageviews', {})
async () => {
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
let account = await get_account(root, session)
- if (account === undefined)
- throw new jst_server.Problem(
- 'Unauthorized',
- 'Please sign in first.',
- 401
- )
-
return {
given_names: await account.get_json('given_names'),
family_name: await account.get_json('family_name'),
async () => {
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
let change_details_draft = await session.get_json('change_details_draft')
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
let account = await get_account(root, session)
- if (account === undefined)
- throw new jst_server.Problem(
- 'Unauthorized',
- 'Please sign in first.',
- 401
- )
-
account.set_json('given_names', details.given_names)
account.set_json('family_name', details.family_name)
account.set_json('contact_me', details.contact_me)
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
if (details) {
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
let account = await get_account(root, session)
- if (account === undefined)
- throw new jst_server.Problem(
- 'Unauthorized',
- 'Please sign in first.',
- 401
- )
-
if (old_password !== await account.get_json('password'))
throw new jst_server.Problem(
'Incorrect password',
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
+ let session = await get_session(env, root)
let accounts = await root.get('accounts', {})
let account = await accounts.get(email)
425
)
- let session = await get_session(env, root)
session.set_json('signed_in_as', email)
await transaction.commit()
}
async () => {
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
session.delete('signed_in_as')
await transaction.commit()
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
let captcha = await session.get('captcha')
async () => {
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
let sign_up_draft = await session.get_json('sign_up_draft')
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
if (details) {
async () => {
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
let contact_draft = await session.get_json('contact_draft')
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
if (details) {
"502": "Bad gateway",
"503": "Service unavailable",
"504": "Gateway timeout",
- "505": "HTTP version not supported"
+ "505": "HTTP version not supported",
+ "506": "Session expired",
+ "507": "Account expired",
+ "508": "Navigation error",
+ "509": "Nodemailer error"
}
async () => {
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
let feedback_draft = await session.get_json('feedback_draft')
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
if (details) {
let jst_server = (await import('@ndcode/jst_server')).default
-let XDate = require('xdate')
return async env => {
let get_account = await _require('/_lib/get_account.jst')
async () => {
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
let account = await get_account(root, session)
- if (account === undefined)
- throw new jst_server.Problem(
- 'Unauthorized',
- 'Please sign in first.',
- 401
- )
if (!await account.get_json('administrator'))
throw new jst_server.Problem(
'Unauthorized',
let jst_server = (await import('@ndcode/jst_server')).default
-let XDate = require('xdate')
return async env => {
let post_request = await _require('/_lib/post_request.jst')
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
let account = await get_account(root, session)
- if (account === undefined)
- throw new jst_server.Problem(
- 'Unauthorized',
- 'Please sign in first.',
- 401
- )
if (!await account.get_json('administrator'))
throw new jst_server.Problem(
'Unauthorized',
let jst_server = (await import('@ndcode/jst_server')).default
-let XDate = require('xdate')
return async env => {
let get_account = await _require('/_lib/get_account.jst')
async () => {
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
let account = await get_account(root, session)
- if (account === undefined)
- throw new jst_server.Problem(
- 'Unauthorized',
- 'Please sign in first.',
- 401
- )
if (!await account.get_json('administrator'))
throw new jst_server.Problem(
'Unauthorized',
let jst_server = (await import('@ndcode/jst_server')).default
-let XDate = require('xdate')
return async env => {
let get_account = await _require('/_lib/get_account.jst')
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
let account = await get_account(root, session)
- if (account === undefined)
- throw new jst_server.Problem(
- 'Unauthorized',
- 'Please sign in first.',
- 401
- )
if (!await account.get_json('administrator'))
throw new jst_server.Problem(
'Unauthorized',
let jst_server = (await import('@ndcode/jst_server')).default
-let XDate = require('xdate')
return async env => {
let get_account = await _require('/_lib/get_account.jst')
async () => {
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
let account = await get_account(root, session)
- if (account === undefined)
- throw new jst_server.Problem(
- 'Unauthorized',
- 'Please sign in first.',
- 401
- )
if (!await account.get_json('administrator'))
throw new jst_server.Problem(
'Unauthorized',
let jst_server = (await import('@ndcode/jst_server')).default
-let XDate = require('xdate')
return async env => {
let get_account = await _require('/_lib/get_account.jst')
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
let account = await get_account(root, session)
- if (account === undefined)
- throw new jst_server.Problem(
- 'Unauthorized',
- 'Please sign in first.',
- 401
- )
if (!await account.get_json('administrator'))
throw new jst_server.Problem(
'Unauthorized',
let transaction = await env.site.database.Transaction()
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
// store captcha text in the session for validation when form submitted
let placeholder
let contact_draft
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
placeholder = await get_placeholder(env, session)
let placeholder
let signed_in_as, details, change_details_draft
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
placeholder = await get_placeholder(env, session)
signed_in_as = await session.get_json('signed_in_as')
-
- account = await get_account(root, session)
- details =
- account === undefined ?
- null :
- {
+ if (signed_in_as === undefined)
+ details = null
+ else {
+ account = await get_account(root, session)
+ details = {
given_names: await account.get_json('given_names'),
family_name: await account.get_json('family_name'),
contact_me: await account.get_json('contact_me')
}
+ }
change_details_draft = await session.get_json('change_details_draft')
if (change_details_draft === undefined || env.now >= change_details_draft.expires)
let transaction = await env.site.database.Transaction()
let placeholder
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
placeholder = await get_placeholder(env, session)
await transaction.commit()
let transaction = await env.site.database.Transaction()
let placeholder
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
placeholder = await get_placeholder(env, session)
await transaction.commit()
let placeholder
let sign_up_draft
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
placeholder = await get_placeholder(env, session)
let transaction = await env.site.database.Transaction()
let placeholder
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
placeholder = await get_placeholder(env, session)
transaction.commit()
let transaction = await env.site.database.Transaction()
let placeholder
try {
- let root = await transaction.get({})
+ let root = await transaction.get()
let session = await get_session(env, root)
placeholder = await get_placeholder(env, session)
await transaction.commit()