2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-- #
|
|
|
|
# Bruno Charest
|
|
|
|
# 2022-08-09
|
|
|
|
#
|
|
|
|
# __ DESCRIPTIONS __
|
|
|
|
# main : stating point of the program
|
|
|
|
#
|
|
|
|
# Project that create a web interface for Joplin base on
|
|
|
|
# Joplin Terminal running in background
|
|
|
|
#
|
|
|
|
# Inspiration of : https://ttj.dk/blog/2019/01/20/setup-a-website-with-nim
|
2022-07-31 16:45:47 -04:00
|
|
|
# Copyright 2019 - Thomas T. Jarløv
|
2022-08-02 21:39:10 -04:00
|
|
|
# [LINK] debug url : http://127.0.0.1:7000/
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
|
|
|
# Import section
|
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-10-27 13:10:16 -04:00
|
|
|
import os # Used to get arguments
|
|
|
|
import uri # We need to encode urls: encodeUrl()
|
2022-10-27 13:11:22 -04:00
|
|
|
|
2022-10-27 13:10:16 -04:00
|
|
|
import times # Time and date
|
|
|
|
import jester # Our webserver
|
|
|
|
import logging # Logging utils
|
|
|
|
import strutils # Basic functions
|
|
|
|
import parsecfg # Parse CFG (config) files
|
|
|
|
import std/json # json manipulation
|
2022-08-10 01:59:10 -04:00
|
|
|
import db_sqlite # SQLite
|
2022-08-02 21:39:10 -04:00
|
|
|
|
2022-07-31 16:45:47 -04:00
|
|
|
import code/database_utils # Utils used in the database
|
|
|
|
import code/password_utils # Our file with password utils
|
2022-10-27 13:10:16 -04:00
|
|
|
import code/joplin_utils # Joplin utils procedures and types
|
|
|
|
import code/web_utils # Web utils procedures and types
|
2022-07-31 16:45:47 -04:00
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
# First we'll load config files
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
let dict = loadConfig("config/config.cfg")
|
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
|
|
|
# Get parameters from config.cfg
|
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# Database
|
2022-10-27 13:10:16 -04:00
|
|
|
let db_user = dict.getSectionValue("Database", "user")
|
|
|
|
let db_pass = dict.getSectionValue("Database", "pass")
|
|
|
|
let db_name = dict.getSectionValue("Database", "name")
|
|
|
|
let db_host = dict.getSectionValue("Database", "host")
|
2022-07-31 16:45:47 -04:00
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# Website
|
2022-10-27 13:10:16 -04:00
|
|
|
let mainURL = dict.getSectionValue("Server", "url")
|
|
|
|
let mainPort = parseInt dict.getSectionValue("Server", "port")
|
2022-10-27 13:11:22 -04:00
|
|
|
#let mainWebsite = dict.getSectionValue("Server", "website")
|
2022-07-31 16:45:47 -04:00
|
|
|
|
2022-10-27 13:11:22 -04:00
|
|
|
# Joplin
|
2022-08-02 21:39:10 -04:00
|
|
|
let joplin_token = dict.getSectionValue("Joplin", "token")
|
2022-07-31 16:45:47 -04:00
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
# Database var
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
var db: DbConn
|
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
# Jester setting server settings
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
settings:
|
|
|
|
port = Port(mainPort)
|
|
|
|
bindAddr = mainURL
|
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
# Setup user data
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
type
|
|
|
|
TData* = ref object of RootObj
|
|
|
|
loggedIn*: bool
|
|
|
|
userid, username*, userpass*, email*: string
|
2022-08-30 20:49:50 -04:00
|
|
|
notification*: int
|
2022-07-31 16:45:47 -04:00
|
|
|
req*: Request
|
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
|
|
|
# proc init : initialisation variables
|
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-10-27 13:10:16 -04:00
|
|
|
proc init(c: var TData, cld: var ColomnLeftData, crd: var ColomnRightData) =
|
2022-07-31 16:45:47 -04:00
|
|
|
## Empty out user session data
|
|
|
|
c.userpass = ""
|
|
|
|
c.username = ""
|
2022-10-27 13:10:16 -04:00
|
|
|
c.userid = ""
|
2022-07-31 16:45:47 -04:00
|
|
|
c.loggedIn = false
|
2022-08-30 20:49:50 -04:00
|
|
|
c.notification = 0
|
2022-07-31 16:45:47 -04:00
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-10-27 13:10:16 -04:00
|
|
|
# function : loggedIn
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
func loggedIn(c: TData): bool =
|
|
|
|
## Check if user is logged in by verifying that c.username exists
|
|
|
|
c.username.len > 0
|
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-10-27 13:10:16 -04:00
|
|
|
# proc checkLoggedIn
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
proc checkLoggedIn(c: var TData) =
|
|
|
|
## Check if user is logged in
|
|
|
|
|
|
|
|
# Get the users cookie named `sid`. If it does not exist, return
|
|
|
|
if not c.req.cookies.hasKey("sid"): return
|
|
|
|
|
|
|
|
# Assign cookie to `let sid`
|
|
|
|
let sid = c.req.cookies["sid"]
|
|
|
|
|
|
|
|
# Update the value lastModified for the user in the
|
|
|
|
# table session where the sid and IP match. If there's
|
|
|
|
# any results (above 0) assign values
|
2022-10-27 13:10:16 -04:00
|
|
|
if execAffectedRows(db, sql("UPDATE session SET lastModified = " & $toInt(
|
|
|
|
epochTime()) & " " & "WHERE ip = ? AND key = ?"), c.req.ip, sid) > 0:
|
2022-07-31 16:45:47 -04:00
|
|
|
|
|
|
|
# Get user data based on userID from session table
|
|
|
|
# Assign values to user details - `c`
|
2022-10-27 13:10:16 -04:00
|
|
|
c.userid = getValue(db, sql"SELECT userid FROM session WHERE ip = ? AND key = ?",
|
|
|
|
c.req.ip, sid)
|
2022-07-31 16:45:47 -04:00
|
|
|
|
|
|
|
# Get user data based on userID from person table
|
|
|
|
let row = getRow(db, sql"SELECT name, email, status FROM person WHERE id = ?", c.userid)
|
|
|
|
|
|
|
|
# Assign user data
|
2022-10-27 13:10:16 -04:00
|
|
|
c.username = row[0]
|
|
|
|
c.email = toLowerAscii(row[1])
|
2022-07-31 16:45:47 -04:00
|
|
|
|
|
|
|
# Update our session table with info about activity
|
2022-10-27 13:10:16 -04:00
|
|
|
discard tryExec(db, sql"UPDATE person SET lastOnline = ? WHERE id = ?",
|
|
|
|
toInt(epochTime()), c.userid)
|
2022-07-31 16:45:47 -04:00
|
|
|
|
|
|
|
else:
|
|
|
|
# If the user is not found in the session table
|
|
|
|
c.loggedIn = false
|
|
|
|
|
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
|
|
|
# proc login user
|
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
proc login(c: var TData, email, pass: string): tuple[b: bool, s: string] =
|
|
|
|
## User login
|
|
|
|
|
|
|
|
# We have predefined query
|
|
|
|
const query = sql"SELECT id, name, password, email, salt, status FROM person WHERE email = ?"
|
|
|
|
|
|
|
|
# If the email or pass passed in the proc's parameters is empty, fail
|
|
|
|
if email.len == 0 or pass.len == 0:
|
|
|
|
return (false, "Missing password or username")
|
|
|
|
|
|
|
|
# We'll use fastRows for a quick query.
|
|
|
|
# Notice that the email is set to lower ascii
|
|
|
|
# to avoid problems if the user has any
|
|
|
|
# capitalized letters.
|
|
|
|
for row in fastRows(db, query, toLowerAscii(email)):
|
|
|
|
|
|
|
|
# Now our password library is going to work. It'll
|
|
|
|
# check the password against the hashed password
|
|
|
|
# and salt.
|
|
|
|
if row[2] == makePassword(pass, row[4], row[2]):
|
|
|
|
# Assign the values
|
2022-10-27 13:10:16 -04:00
|
|
|
c.userid = row[0]
|
2022-07-31 16:45:47 -04:00
|
|
|
c.username = row[1]
|
|
|
|
c.userpass = row[2]
|
2022-10-27 13:10:16 -04:00
|
|
|
c.email = toLowerAscii(row[3])
|
2022-07-31 16:45:47 -04:00
|
|
|
|
|
|
|
# Generate session key and save it
|
|
|
|
let key = makeSessionKey()
|
2022-10-27 13:10:16 -04:00
|
|
|
exec(db, sql"INSERT INTO session (ip, key, userid) VALUES (?, ?, ?)",
|
|
|
|
c.req.ip, key, row[0])
|
2022-07-31 16:45:47 -04:00
|
|
|
|
|
|
|
info("Login successful")
|
|
|
|
return (true, key)
|
|
|
|
|
|
|
|
info("Login failed")
|
|
|
|
return (false, "Login failed")
|
|
|
|
|
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
|
|
|
# proc logout user
|
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
proc logout(c: var TData) =
|
|
|
|
## Logout
|
|
|
|
|
|
|
|
c.username = ""
|
|
|
|
c.userpass = ""
|
|
|
|
const query = sql"DELETE FROM session WHERE ip = ? AND key = ?"
|
|
|
|
exec(db, query, c.req.ip, c.req.cookies["sid"])
|
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
# Do the check inside our routes
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
template createTFD() =
|
|
|
|
## Check if logged in and assign data to user
|
|
|
|
|
|
|
|
# Assign the c to TDATA
|
|
|
|
var c {.inject.}: TData
|
2022-08-06 16:51:49 -04:00
|
|
|
|
2022-10-27 13:11:22 -04:00
|
|
|
# Assign the cld et crd to ColomnData
|
2022-08-06 16:51:49 -04:00
|
|
|
var cld {.inject.}: ColomnLeftData
|
2022-10-27 13:10:16 -04:00
|
|
|
var crd {.inject.}: ColomnRightData
|
2022-08-06 16:51:49 -04:00
|
|
|
|
2022-10-27 13:11:22 -04:00
|
|
|
# Assign the dashData to DashbordData
|
|
|
|
var dashData {.inject.}: DashbordData
|
|
|
|
|
2022-07-31 16:45:47 -04:00
|
|
|
# New instance of c
|
|
|
|
new(c)
|
2022-08-06 16:51:49 -04:00
|
|
|
new(cld)
|
2022-10-27 13:10:16 -04:00
|
|
|
new(crd)
|
2022-10-27 13:11:22 -04:00
|
|
|
new(dashData)
|
2022-08-06 16:51:49 -04:00
|
|
|
|
2022-07-31 16:45:47 -04:00
|
|
|
# Set standard values
|
2022-10-27 13:10:16 -04:00
|
|
|
init(c, cld, crd)
|
2022-10-27 13:11:22 -04:00
|
|
|
|
2022-07-31 16:45:47 -04:00
|
|
|
# Get users request
|
|
|
|
c.req = request
|
2022-08-06 16:51:49 -04:00
|
|
|
cld.req = request
|
2022-10-27 13:10:16 -04:00
|
|
|
crd.req = request
|
2022-10-27 13:11:22 -04:00
|
|
|
dashData.req = request
|
2022-08-06 16:51:49 -04:00
|
|
|
|
2022-07-31 16:45:47 -04:00
|
|
|
# Check for cookies (we need the cookie named sid)
|
|
|
|
if cookies(request).len > 0:
|
|
|
|
# Check if user is logged in
|
|
|
|
checkLoggedIn(c)
|
|
|
|
# Use the func()
|
|
|
|
c.loggedIn = loggedIn(c)
|
|
|
|
|
|
|
|
|
|
|
|
# isMainModule
|
2022-08-10 01:59:10 -04:00
|
|
|
# ---------------------------- #
|
2022-07-31 16:45:47 -04:00
|
|
|
when isMainModule:
|
|
|
|
echo "Nim Web is now running: " & $now()
|
|
|
|
|
|
|
|
# Generate DB if newdb is in the arguments
|
|
|
|
# or if the database does not exists
|
|
|
|
if "newdb" in commandLineParams() or not fileExists(db_host):
|
|
|
|
generateDB()
|
|
|
|
quit()
|
|
|
|
|
|
|
|
# Connect to DB
|
|
|
|
try:
|
|
|
|
# We are using the values which we assigned earlier
|
2022-10-27 13:10:16 -04:00
|
|
|
db = open(connection = db_host, user = db_user, password = db_pass,
|
|
|
|
database = db_name)
|
2022-07-31 16:45:47 -04:00
|
|
|
info("Connection to DB is established.")
|
|
|
|
except:
|
|
|
|
fatal("Connection to DB could not be established.")
|
|
|
|
sleep(5_000)
|
|
|
|
quit()
|
|
|
|
|
|
|
|
# Add an admin user if newuser is in the args
|
|
|
|
if "newuser" in commandLineParams():
|
|
|
|
createAdminUser(db, commandLineParams())
|
|
|
|
quit()
|
|
|
|
|
|
|
|
|
|
|
|
# Include template files
|
2022-08-10 01:59:10 -04:00
|
|
|
# ---------------------------- #
|
2022-07-31 16:45:47 -04:00
|
|
|
#include "tmpl/main.tmpl"
|
|
|
|
include "tmpl/user.tmpl"
|
|
|
|
include "tmpl/website.tmpl"
|
2022-08-06 16:51:49 -04:00
|
|
|
|
|
|
|
# Tests pages include
|
2022-08-10 01:59:10 -04:00
|
|
|
# ---------------------------- #
|
2022-08-06 16:51:49 -04:00
|
|
|
include "tmpl/tests/test_homepage.tmpl"
|
|
|
|
include "tmpl/tests/test_ping.tmpl"
|
|
|
|
include "tmpl/tests/test_notebooks.tmpl"
|
|
|
|
include "tmpl/tests/test_notes.tmpl"
|
|
|
|
include "tmpl/tests/test_tags.tmpl"
|
|
|
|
include "tmpl/tests/test_viewtree.tmpl"
|
2022-10-27 13:11:22 -04:00
|
|
|
include "tmpl/tests/test_bouton.tmpl"
|
2022-08-06 16:51:49 -04:00
|
|
|
|
2022-07-31 16:45:47 -04:00
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
# Setup routes (URL's)
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
routes:
|
2022-10-27 13:10:16 -04:00
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# default route
|
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
get "/":
|
|
|
|
createTFD()
|
|
|
|
resp genMain(c)
|
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# master site once login
|
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
get "/secret":
|
|
|
|
createTFD()
|
2022-08-02 21:39:10 -04:00
|
|
|
echo c.loggedIn
|
2022-10-27 13:10:16 -04:00
|
|
|
var isStart: int = 0
|
|
|
|
|
|
|
|
|
|
|
|
# if joplin_cli_status() == false:
|
|
|
|
# isStart = joplin_cli_start()
|
|
|
|
|
|
|
|
|
|
|
|
echo "MESSAGE :", @"msg"
|
|
|
|
echo "NOTE_ID :", @"noteid"
|
|
|
|
let selectedNoteId = @"noteid"
|
|
|
|
var url_note = "/secret?msg=notes"
|
|
|
|
|
|
|
|
|
|
|
|
# URL msg and note id if exist noteid
|
|
|
|
if selectedNoteId != "":
|
|
|
|
url_note = "/secret?msg=notes¬eid=" & selectedNoteId
|
|
|
|
|
2022-07-31 16:45:47 -04:00
|
|
|
if c.loggedIn:
|
2022-10-27 13:10:16 -04:00
|
|
|
# Start joplin terminal cli if stropped
|
|
|
|
if @"msg" == "startStopJoplin":
|
|
|
|
var isStart = joplin_cli_start_stop()
|
|
|
|
redirect(url_note)
|
2022-08-30 20:49:50 -04:00
|
|
|
|
2022-08-06 16:51:49 -04:00
|
|
|
# if Joplin application work
|
|
|
|
var checkJoplin = waitFor ping_joplin(joplin_token)
|
|
|
|
if checkJoplin.ping_status:
|
|
|
|
cld.j_status = true
|
|
|
|
else:
|
|
|
|
cld.j_status = false
|
|
|
|
|
|
|
|
# determine the section to uptade
|
|
|
|
if @"msg" == "newNote":
|
|
|
|
cld.option = newNote
|
2022-10-27 13:10:16 -04:00
|
|
|
echo "=> Section newNote"
|
2022-08-06 16:51:49 -04:00
|
|
|
|
|
|
|
elif @"msg" == "search":
|
|
|
|
cld.option = search
|
2022-10-27 13:10:16 -04:00
|
|
|
echo "=> Section search"
|
2022-08-06 16:51:49 -04:00
|
|
|
|
|
|
|
elif @"msg" == "shortcuts":
|
|
|
|
cld.option = shortcuts
|
2022-10-27 13:10:16 -04:00
|
|
|
echo "=> Section shortcuts"
|
2022-08-06 16:51:49 -04:00
|
|
|
|
|
|
|
elif @"msg" == "notebooks":
|
2022-10-27 13:10:16 -04:00
|
|
|
echo "=> Section notebooks"
|
2022-08-06 16:51:49 -04:00
|
|
|
cld.option = notebooks
|
|
|
|
cld.j_notebooks = waitFor get_joplin_notebooks(joplin_token)
|
|
|
|
|
|
|
|
elif @"msg" == "notes":
|
2022-10-27 13:10:16 -04:00
|
|
|
echo "=> Section notes"
|
2022-08-06 16:51:49 -04:00
|
|
|
cld.option = notes
|
|
|
|
cld.j_notes = waitFor get_joplin_notes(joplin_token)
|
2022-10-27 13:10:16 -04:00
|
|
|
cld.j_notes_nb = cld.j_notes.id.len()
|
|
|
|
|
|
|
|
if selectedNoteId != "":
|
|
|
|
crd.j_SelectedNote = waitFor get_joplin_note(joplin_token, selectedNoteId)
|
2022-08-06 16:51:49 -04:00
|
|
|
|
|
|
|
elif @"msg" == "tags":
|
2022-10-27 13:10:16 -04:00
|
|
|
echo "=> Section tags"
|
2022-08-06 16:51:49 -04:00
|
|
|
cld.option = tags
|
|
|
|
cld.j_tags = waitFor get_joplin_tags(joplin_token)
|
|
|
|
|
2022-10-27 13:10:16 -04:00
|
|
|
elif @"msg" == "dashbord":
|
|
|
|
echo "=> Section dashbord"
|
|
|
|
#cld.option = dashbord
|
|
|
|
|
2022-10-27 13:11:22 -04:00
|
|
|
# getDashbordData(dashData)
|
2022-10-27 13:10:16 -04:00
|
|
|
|
2022-08-06 16:51:49 -04:00
|
|
|
elif @"msg" == "sendFeedBack":
|
|
|
|
echo "Todo"
|
2022-10-27 13:10:16 -04:00
|
|
|
|
|
|
|
resp Http200, {"Access-Control-Allow-Origin": "http://127.0.0.1:7000"},
|
2022-10-27 13:11:22 -04:00
|
|
|
genSecret(c, cld, crd, dashData)
|
2022-10-27 13:10:16 -04:00
|
|
|
|
2022-07-31 16:45:47 -04:00
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# Login route
|
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
get "/login":
|
|
|
|
createTFD()
|
2022-10-27 13:10:16 -04:00
|
|
|
resp Http200, {"Access-Control-Allow-Origin": "http://127.0.0.1:7000"},
|
|
|
|
genLogin(c, @"msg")
|
2022-07-31 16:45:47 -04:00
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# action route during login
|
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
post "/dologin":
|
|
|
|
createTFD()
|
|
|
|
|
2022-10-27 13:10:16 -04:00
|
|
|
let (loginB, loginS) = login(c, replace(toLowerAscii(@"email"), " ", ""),
|
|
|
|
replace(@"password", " ", ""))
|
2022-07-31 16:45:47 -04:00
|
|
|
if loginB:
|
|
|
|
when defined(dev):
|
|
|
|
jester.setCookie("sid", loginS, daysForward(7))
|
|
|
|
else:
|
2022-10-27 13:10:16 -04:00
|
|
|
jester.setCookie("sid", loginS, daysForward(7), samesite = Lax,
|
|
|
|
secure = true, httpOnly = true)
|
2022-08-04 00:39:09 -04:00
|
|
|
#jester.setCookie("sid", loginS, daysForward(7), samesite = Lax, secure = true, httpOnly = true)
|
2022-07-31 16:45:47 -04:00
|
|
|
|
|
|
|
redirect("/secret")
|
|
|
|
else:
|
|
|
|
redirect("/login?msg=" & encodeUrl(loginS))
|
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# Logout route
|
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 16:45:47 -04:00
|
|
|
get "/logout":
|
|
|
|
createTFD()
|
|
|
|
logout(c)
|
|
|
|
redirect("/")
|
2022-07-31 20:03:45 -04:00
|
|
|
|
2022-08-30 20:49:50 -04:00
|
|
|
# start_joplin route
|
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
|
|
|
# post "/start_joplin":
|
|
|
|
# if joplin_cli_status() == false:
|
|
|
|
# joplin_cli_start()
|
|
|
|
|
2022-10-27 13:10:16 -04:00
|
|
|
|
2022-08-30 20:49:50 -04:00
|
|
|
|
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
|
|
|
# # ROUTES TESTS SECTION ##
|
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-08-06 16:51:49 -04:00
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# master tests page
|
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-08-06 16:51:49 -04:00
|
|
|
get "/test":
|
|
|
|
createTFD()
|
|
|
|
resp test_homepage(c)
|
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# Test ping joplin - query api validation
|
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-08-06 16:51:49 -04:00
|
|
|
get "/test_pingjoplin":
|
|
|
|
createTFD()
|
2022-10-27 13:10:16 -04:00
|
|
|
|
2022-08-06 16:51:49 -04:00
|
|
|
var pingCheck: joplin_ping
|
|
|
|
pingCheck = waitFor ping_joplin(joplin_token)
|
|
|
|
echo pingCheck.ping_status
|
2022-10-27 13:10:16 -04:00
|
|
|
|
2022-08-06 16:51:49 -04:00
|
|
|
resp test_ping(c, pingCheck)
|
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# Test geting list of all notebooks
|
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-07-31 20:03:45 -04:00
|
|
|
get "/test_notebooks":
|
|
|
|
createTFD()
|
2022-10-27 13:10:16 -04:00
|
|
|
cld.j_notebooks = waitFor get_joplin_notebooks(joplin_token)
|
2022-08-06 16:51:49 -04:00
|
|
|
resp test_notebooks(c, cld)
|
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# Test geting list of all notes
|
2022-10-27 13:10:16 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-08-06 16:51:49 -04:00
|
|
|
get "/test_notes":
|
|
|
|
createTFD()
|
|
|
|
cld.j_notes = waitFor get_joplin_notes(joplin_token)
|
|
|
|
resp test_notes(c, cld)
|
|
|
|
|
2022-08-10 01:59:10 -04:00
|
|
|
# Test geting list of all tags
|
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-08-06 16:51:49 -04:00
|
|
|
get "/test_tags":
|
|
|
|
createTFD()
|
|
|
|
cld.j_tags = waitFor get_joplin_tags(joplin_token)
|
|
|
|
resp test_tags(c, cld)
|
|
|
|
|
2022-10-27 13:10:16 -04:00
|
|
|
# Test a viewtree
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-08-06 16:51:49 -04:00
|
|
|
get "/test_viewtree":
|
|
|
|
createTFD()
|
|
|
|
resp test_viewtree(c)
|
|
|
|
|
2022-10-27 13:11:22 -04:00
|
|
|
# Test a viewtree
|
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
|
|
|
get "/test_bouton":
|
|
|
|
createTFD()
|
|
|
|
resp test_bonton(dashData)
|
|
|
|
|
2022-10-27 13:10:16 -04:00
|
|
|
# Test geting all tags as JSON output
|
2022-08-10 01:59:10 -04:00
|
|
|
# --==--==--==--==--==--==--==--==--==--==-- #
|
2022-08-09 00:01:31 -04:00
|
|
|
get "/test_tags_json":
|
|
|
|
createTFD()
|
|
|
|
var tags: JsonNodeObj
|
|
|
|
|
|
|
|
|
|
|
|
# http://localhost:41184/notes/77ec1bfbaccd4708a9f649f42896f437&token=e5f6644fbf6a97ddc55648dae72b11caecda6c6642d8ce0d3b20129b89b196385737eb908923542c3343649ebbf865b55bda031ab4c3a16edc7723ef2ad77d8f
|
|
|
|
# http://localhost:41184/notes/77ec1bfbaccd4708a9f649f42896f437?fields=id,parent_id,title,body,created_time,updated_time,is_conflict,latitude,longitude,altitude,author,source_url,is_todo,todo_due,todo_completed,source,source_application,application_data,order,user_created_time,user_updated_time,encryption_cipher_text,encryption_applied,markup_language,is_shared,share_id,conflict_original_id,master_key_id&token=e5f6644fbf6a97ddc55648dae72b11caecda6c6642d8ce0d3b20129b89b196385737eb908923542c3343649ebbf865b55bda031ab4c3a16edc7723ef2ad77d8f
|
2022-08-06 16:51:49 -04:00
|
|
|
|
|
|
|
# # ##
|
|
|
|
# # END TESTS SECTION ##
|
2022-10-27 13:10:16 -04:00
|
|
|
# # ##
|