script {
let sign_in = async (...arguments) => api_call(
- '/api/sign_in.json',
+ '/api/account/sign_in.json',
...arguments
)
let sign_out = async (...arguments) => api_call(
- '/api/sign_out.json',
+ '/api/account/sign_out.json',
...arguments
)
let feedback = async (...arguments) => api_call(
- '/api/feedback.json',
+ '/api/account/feedback.json',
...arguments
)
let stream_buffers = require('stream-buffers')
-return async (env, endpoint, handler) => {
+return async (env, handler) => {
let Problem = await _require('/_lib/Problem.jst')
let result
)
env.request.pipe(write_stream)
let arguments = JSON.parse((await data).toString())
- console.log('endpoint', endpoint, 'arguments', JSON.stringify(arguments))
+ console.log('endpoint', env.parsed_url.path, 'arguments', JSON.stringify(arguments))
result = await handler(...arguments)
if (result === undefined)
result = null
- console.log('endpoint', endpoint, 'result', JSON.stringify(result))
+ console.log('endpoint', env.parsed_url.path, 'result', JSON.stringify(result))
}
catch (error) {
let problem =
// status
500
)
- console.log('endpoint', endpoint, 'problem', problem.detail)
+ console.log('endpoint', env.parsed_url.path, 'problem', problem.detail)
env.mime_type = 'application/problem+json; charset=utf-8'
env.site.serve(
await post_request(
// env
env,
- // endpoint
- '/api/password_reset.json',
// handler
async (email, password) => {
// coerce and/or validate
await post_request(
// env
env,
- // endpoint
- '/api/sign_in.json',
// handler
async (email, password) => {
// coerce and/or validate
await post_request(
// env
env,
- // endpoint
- '/api/sign_out.json',
// handler
async () => {
let transaction = await env.site.database.Transaction()
await post_request(
// env
env,
- // endpoint
- '/api/sign_up/create_account.json',
// handler
async (verification_code, details) => {
// coerce and/or validate
if (captcha === undefined || XDate.now() >= captcha.get('expires'))
throw new Problem(
'No verification image in session',
- `Please call the "/api/verification_image.png" endpoint to create a verification image, in same session as the "/api/sign_up/create_account.json" call and less than one hour prior.`,
+ `Please call the "/api/verification_image.png" endpoint to create a verification image, in same session as the "/api/account/sign_up/create_account.json" call and less than one hour prior.`,
418
)
await post_request(
// env
env,
- // endpoint
- '/api/sign_up/get_draft.json',
// handler
async () => {
let transaction = await env.site.database.Transaction()
await post_request(
// env
env,
- // endpoint
- '/api/sign_up/send_verification_email.json',
// handler
async email => {
// coerce and/or validate
if (account === undefined)
throw new Problem(
'Account does not exist',
- `Please create the account for "${email}" before attempting to send a email verification link.`
+ `Please create the account for "${email}" before attempting to send an email verification link.`
421
)
+ if (
+ await logjson.logjson_to_json(
+ await account.get('email_verified')
+ )
+ )
+ throw new Problem(
+ 'Email already verified',
+ `Your email "${email}" is already verified. You can now sign in.`
+ 422
+ )
+
let link_code = crypto.randomBytes(16).toString('hex')
let expires = new XDate()
expires.addDays(1)
await post_request(
// env
env,
- // endpoint
- '/api/sign_up/set_draft.json',
// handler
async details => {
// coerce and/or validate
email: details.email.slice(0, 256).toLowerCase(),
given_names: details.given_names.slice(0, 256),
family_name: details.family_name.slice(0, 256),
- password: details.password.slice(0, 256),
contact_me: details.contact_me ? true : false
}
await post_request(
// env
env,
- // endpoint
- '/api/sign_up/verify_email.json',
// handler
async (email, link_code) => {
// coerce and/or validate
await post_request(
// env
env,
- // endpoint
- '/api/verify_password.json',
// handler
async (email, link_code) => {
// coerce and/or validate
await post_request(
// env
env,
- // endpoint
- '/api/feedback.json',
// handler
async (page, message) => {
// coerce and/or validate
script {
let password_reset = async (...arguments) => api_call(
- '/api/password_reset.json',
+ '/api/account/password_reset.json',
...arguments
)
script {
let sign_up_send_email_verification_link = async (...arguments) => api_call(
- '/api/sign_up/send_email_verification_link.json',
+ '/api/account/sign_up/send_email_verification_link.json',
...arguments
)
div.col-md-6 {
div.form-group {
label.form-label(for="password") {'Password *'}
- input.form-control#password(type="password" value=details.password || '' placeholder="New password" required="required" minlength=8 maxlength=256) {}
+ input.form-control#password(type="password" placeholder="New password" required="required" minlength=8 maxlength=256) {}
}
}
}
script {
let sign_up_create_account = async (...arguments) => api_call(
- '/api/sign_up/create_account.json',
+ '/api/account/sign_up/create_account.json',
...arguments
)
//let sign_up_get_draft = async (...arguments) => api_call(
- // '/api/sign_up/get_draft.json',
+ // '/api/account/sign_up/get_draft.json',
// ...arguments
//)
let sign_up_set_draft = async (...arguments) => api_call(
- '/api/sign_up/set_draft.json',
+ '/api/account/sign_up/set_draft.json',
...arguments
)
let sign_up_send_email_verification_link = async (...arguments) => api_call(
- '/api/sign_up/send_email_verification_link.json',
+ '/api/account/sign_up/send_email_verification_link.json',
...arguments
)
- let coerce_details = () => {
- return {
- email: document.getElementById('email').value.slice(0, 256).toLowerCase(),
- given_names: document.getElementById('given-names').value.slice(0, 256),
- family_name: document.getElementById('family-name').value.slice(0, 256),
- password: document.getElementById('password').value.slice(0, 256),
- contact_me: document.getElementById('contact-me').checked ? true : false
- }
- }
-
let draft_timeout_running = false
let draft_timeout_handler = async () => {
draft_timeout_running = false
- await sign_up_set_draft(coerce_details())
+ await sign_up_set_draft(
+ {
+ email: document.getElementById('email').value.slice(0, 256).toLowerCase(),
+ given_names: document.getElementById('given-names').value.slice(0, 256),
+ family_name: document.getElementById('family-name').value.slice(0, 256),
+ contact_me: document.getElementById('contact-me').checked ? true : false
+ }
+ )
//console.log('draft', await sign_up_get_draft())
}
let draft_change_handler = () => {
}
}
+ let details
let step_1 = async () => {
if (
!document.getElementById('given-names').reportValidity() ||
$('#step-1-tick').show()
$('#step-1-cross').hide()
//$('#step-1-spinner').hide()
+
+ details = {
+ email: document.getElementById('email').value.slice(0, 256).toLowerCase(),
+ given_names: document.getElementById('given-names').value.slice(0, 256),
+ family_name: document.getElementById('family-name').value.slice(0, 256),
+ password: document.getElementById('password').value.slice(0, 256),
+ contact_me: document.getElementById('contact-me').checked ? true : false
+ }
return true
}
- let step_2_details = ''
let step_2 = async () => {
$('#step-2-tick').hide()
$('#step-2-cross').hide()
document.getElementById('step-2').scrollIntoView()
try {
- step_2_details = coerce_details()
await sign_up_create_account(
// verification_code
document.getElementById('verification-code').value.slice(0, 6).toLowerCase(),
// details
- step_2_details
+ details
)
}
catch (error) {
$('#step-2-tick').show()
$('#step-2-cross').hide()
$('#step-2-spinner').hide()
- document.getElementById('step-2-message').textContent = `Your account with email "${step_2_details.email}" has been created.`
+ document.getElementById('step-2-message').textContent = `Your account with email "${details.email}" has been created.`
return true
}
document.getElementById('step-3').scrollIntoView()
try {
- await sign_up_send_email_verification_link(step_2_details.email)
+ await sign_up_send_email_verification_link(details.email)
}
catch (error) {
let problem =
$('#step-3-cross').hide()
$('#step-3-spinner').hide()
- document.getElementById('step-3-message').textContent = `Email verification link has been sent to "${step_2_details.email}". Please check your email for next steps.`
+ document.getElementById('step-3-message').textContent = `Email verification link has been sent to "${details.email}". Please check your email for next steps.`
return true
}
script {
let sign_up_verify_email = async (...arguments) => api_call(
- '/api/sign_up/verify_email.json',
+ '/api/account/sign_up/verify_email.json',
...arguments
)
script {
let verify_password = async (...arguments) => api_call(
- '/api/verify_password.json',
+ '/api/account/verify_password.json',
...arguments
)