corrected install.sh, completed API key giving / new task adding / task checking

This commit is contained in:
Paul Liverman III 2018-04-23 22:42:56 -07:00
parent add6e675cb
commit a70c3ccfc7
5 changed files with 43 additions and 26 deletions

View File

@ -28,8 +28,8 @@ class Simplex extends Application
[new_api_key: "/new-api-key"]: => [new_api_key: "/new-api-key"]: =>
if @user if @user
if key = APIKeys\create(@user) if api_key = APIKeys\create(@user)
return json: { success: true, :key } return json: { success: true, :api_key }
[console: "/console"]: => [console: "/console"]: =>
if @user and @user.admin if @user and @user.admin

View File

@ -104,6 +104,7 @@ class API extends Application
-- return json: { success: true, task: tasks[1] } -- return json: { success: true, task: tasks[1] }
-- else -- else
-- return standard_err! -- return standard_err!
return status: 501 json: { errors: {"Not implemented."} }
[list: "/list"]: capture_errors_json json_params => [list: "/list"]: capture_errors_json json_params =>
assert_valid @params, { assert_valid @params, {

View File

@ -11,15 +11,8 @@ read -p "Enter email address for use with certbot-auto: " EMAIL_ADDRESS
read -p "Enter the domain name this will be running on: " DOMAIN_NAME read -p "Enter the domain name this will be running on: " DOMAIN_NAME
read -p "Enter the port this will be running on: " PORT read -p "Enter the port this will be running on: " PORT
if [ -z EMAIL_ADDRESS ] EMAIL_ADDRESS=${EMAIL_ADDRESS:-noone@example.com}
then PORT=${PORT:-9872}
EMAIL_ADDRESS=no-one@example.com
fi
if [ -z PORT ]
then
PORT=9872 # TODO fix this does not work
fi
### PREREQUISITES ### ### PREREQUISITES ###
@ -92,7 +85,7 @@ echo "{
sql_password: '$POSTGRES_PASSWORD' sql_password: '$POSTGRES_PASSWORD'
session_secret: '$(cat /dev/urandom | head -c 12 | base64)' session_secret: '$(cat /dev/urandom | head -c 12 | base64)'
_domain: '$DOMAIN_NAME' _domain: '$DOMAIN_NAME'
_port: '$PORT' _port: $PORT
}" > ./secret.moon }" > ./secret.moon
# Compile, Run migrations # Compile, Run migrations
@ -138,7 +131,7 @@ sudo echo "server {
ssl_dhparam $INSTALL_DIR/dhparams.pem; ssl_dhparam $INSTALL_DIR/dhparams.pem;
location / { location / {
proxy_pass http://127.0.0.1:$PORT proxy_pass http://127.0.0.1:$PORT;
} }
}" > /etc/nginx/sites-enabled/simplex-proxy.conf }" > /etc/nginx/sites-enabled/simplex-proxy.conf
sudo nginx -s reload # might fail because the service isn't running yet sudo nginx -s reload # might fail because the service isn't running yet

View File

@ -11,8 +11,12 @@ function check(id) {
var xhr = request("/v1/do"); var xhr = request("/v1/do");
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
if (xhr.readyState === 4) { if (xhr.readyState === 4) {
// TODO handle success / errors data = JSON.parse(xhr.responseText);
console.log(xhr.responseText); if (data.task) {
$("#task-" + data.task.id).prop("checked", data.task.done);
} else {
console.log(data); // NOTE TEMPORARY (handle errors better!)
}
} }
} }
xhr.send(JSON.stringify({api_key: API_KEY, id: id})); xhr.send(JSON.stringify({api_key: API_KEY, id: id}));
@ -20,8 +24,12 @@ function check(id) {
var xhr = request("/v1/undo"); var xhr = request("/v1/undo");
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
if (xhr.readyState === 4) { if (xhr.readyState === 4) {
// TODO handle success / errors data = JSON.parse(xhr.responseText);
console.log(xhr.responseText); if (data.task) {
$("#task-" + data.task.id).prop("checked", data.task.done);
} else {
console.log(data); // NOTE TEMPORARY (handle errors better!)
}
} }
} }
xhr.send(JSON.stringify({api_key: API_KEY, id: id})); xhr.send(JSON.stringify({api_key: API_KEY, id: id}));
@ -29,13 +37,16 @@ function check(id) {
} }
function new_task() { function new_task() {
var text = document.getElementById("new-task"); var text = document.getElementById("new-task-input");
console.log(text); // TEMPORARY
var xhr = request("/v1/new"); var xhr = request("/v1/new");
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
if (xhr.readyState === 4) { if (xhr.readyState === 4) {
// TODO handle success / errors data = JSON.parse(xhr.responseText);
console.log(xhr.responseText); if (data.task) {
$("#new-task").before("<li><input type='checkbox' id='task-" + data.task.id + "' onchange='check(" + data.task.id + ")' checked=false> " + data.task.content + "</li>");
} else {
console.log(data); // NOTE TEMPORARY (handle errors better!)
}
} }
} }
xhr.send(JSON.stringify({api_key: API_KEY, content: text.value})); xhr.send(JSON.stringify({api_key: API_KEY, content: text.value}));
@ -44,5 +55,16 @@ function new_task() {
} }
function new_api_key() { function new_api_key() {
// TODO var xhr = request("/new-api-key");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
data = JSON.parse(xhr.responseText);
if (data.api_key) {
$("#new-api-key").before("<li>" + data.api_key.key + "</li>");
} else {
console.log(data); // NOTE TEMPORARY (handle errors better!)
}
}
}
xhr.send(); // NOTE may need to send empty string or empty JSON object
} }

View File

@ -3,6 +3,7 @@ import Widget from require "lapis.html"
class LoggedIn extends Widget class LoggedIn extends Widget
content: => content: =>
script -> raw "var API_KEY = '#{@keys[1].key}';" script -> raw "var API_KEY = '#{@keys[1].key}';"
script src: "http://code.jquery.com/jquery-3.3.1.min.js", integrity: "sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=", crossorigin: "anonymous"
script src: "/static/index.js" script src: "/static/index.js"
p "API Keys:" p "API Keys:"
@ -10,8 +11,8 @@ class LoggedIn extends Widget
if @keys if @keys
for key in *@keys for key in *@keys
li key.key li key.key
li -> li id: "new-api-key", ->
a onclick: "new_api_key()", "+" button onclick: "new_api_key()", "+"
p "Tasks:" p "Tasks:"
ul -> ul ->
@ -20,9 +21,9 @@ class LoggedIn extends Widget
li -> li ->
input type: "checkbox", id: "task-#{task.id}", onchange: "check(#{task.id});", checked: task.done input type: "checkbox", id: "task-#{task.id}", onchange: "check(#{task.id});", checked: task.done
text " #{task.content}" text " #{task.content}"
li -> li id: "new-task", ->
form { form {
onsubmit: "return new_task();" onsubmit: "return new_task();"
}, -> }, ->
input type: "text", id: "new-task", placeholder: "new task" input type: "text", id: "new-task-input", placeholder: "new task"
input type: "submit", value: "+" input type: "submit", value: "+"