corrected install.sh, completed API key giving / new task adding / task checking
This commit is contained in:
parent
add6e675cb
commit
a70c3ccfc7
4
app.moon
4
app.moon
@ -28,8 +28,8 @@ class Simplex extends Application
|
||||
|
||||
[new_api_key: "/new-api-key"]: =>
|
||||
if @user
|
||||
if key = APIKeys\create(@user)
|
||||
return json: { success: true, :key }
|
||||
if api_key = APIKeys\create(@user)
|
||||
return json: { success: true, :api_key }
|
||||
|
||||
[console: "/console"]: =>
|
||||
if @user and @user.admin
|
||||
|
@ -104,6 +104,7 @@ class API extends Application
|
||||
-- return json: { success: true, task: tasks[1] }
|
||||
-- else
|
||||
-- return standard_err!
|
||||
return status: 501 json: { errors: {"Not implemented."} }
|
||||
|
||||
[list: "/list"]: capture_errors_json json_params =>
|
||||
assert_valid @params, {
|
||||
|
15
install.sh
15
install.sh
@ -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 port this will be running on: " PORT
|
||||
|
||||
if [ -z EMAIL_ADDRESS ]
|
||||
then
|
||||
EMAIL_ADDRESS=no-one@example.com
|
||||
fi
|
||||
|
||||
if [ -z PORT ]
|
||||
then
|
||||
PORT=9872 # TODO fix this does not work
|
||||
fi
|
||||
EMAIL_ADDRESS=${EMAIL_ADDRESS:-noone@example.com}
|
||||
PORT=${PORT:-9872}
|
||||
|
||||
### PREREQUISITES ###
|
||||
|
||||
@ -92,7 +85,7 @@ echo "{
|
||||
sql_password: '$POSTGRES_PASSWORD'
|
||||
session_secret: '$(cat /dev/urandom | head -c 12 | base64)'
|
||||
_domain: '$DOMAIN_NAME'
|
||||
_port: '$PORT'
|
||||
_port: $PORT
|
||||
}" > ./secret.moon
|
||||
|
||||
# Compile, Run migrations
|
||||
@ -138,7 +131,7 @@ sudo echo "server {
|
||||
ssl_dhparam $INSTALL_DIR/dhparams.pem;
|
||||
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:$PORT
|
||||
proxy_pass http://127.0.0.1:$PORT;
|
||||
}
|
||||
}" > /etc/nginx/sites-enabled/simplex-proxy.conf
|
||||
sudo nginx -s reload # might fail because the service isn't running yet
|
||||
|
@ -11,8 +11,12 @@ function check(id) {
|
||||
var xhr = request("/v1/do");
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === 4) {
|
||||
// TODO handle success / errors
|
||||
console.log(xhr.responseText);
|
||||
data = JSON.parse(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}));
|
||||
@ -20,8 +24,12 @@ function check(id) {
|
||||
var xhr = request("/v1/undo");
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === 4) {
|
||||
// TODO handle success / errors
|
||||
console.log(xhr.responseText);
|
||||
data = JSON.parse(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}));
|
||||
@ -29,13 +37,16 @@ function check(id) {
|
||||
}
|
||||
|
||||
function new_task() {
|
||||
var text = document.getElementById("new-task");
|
||||
console.log(text); // TEMPORARY
|
||||
var text = document.getElementById("new-task-input");
|
||||
var xhr = request("/v1/new");
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === 4) {
|
||||
// TODO handle success / errors
|
||||
console.log(xhr.responseText);
|
||||
data = JSON.parse(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}));
|
||||
@ -44,5 +55,16 @@ function new_task() {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ import Widget from require "lapis.html"
|
||||
class LoggedIn extends Widget
|
||||
content: =>
|
||||
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"
|
||||
|
||||
p "API Keys:"
|
||||
@ -10,8 +11,8 @@ class LoggedIn extends Widget
|
||||
if @keys
|
||||
for key in *@keys
|
||||
li key.key
|
||||
li ->
|
||||
a onclick: "new_api_key()", "+"
|
||||
li id: "new-api-key", ->
|
||||
button onclick: "new_api_key()", "+"
|
||||
|
||||
p "Tasks:"
|
||||
ul ->
|
||||
@ -20,9 +21,9 @@ class LoggedIn extends Widget
|
||||
li ->
|
||||
input type: "checkbox", id: "task-#{task.id}", onchange: "check(#{task.id});", checked: task.done
|
||||
text " #{task.content}"
|
||||
li ->
|
||||
li id: "new-task", ->
|
||||
form {
|
||||
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: "+"
|
||||
|
Loading…
Reference in New Issue
Block a user