2018-04-23 12:22:27 +00:00
|
|
|
import Application from require "lapis"
|
2018-04-23 12:02:59 +00:00
|
|
|
|
2018-04-23 12:46:07 +00:00
|
|
|
import APIKeys, Tasks from require "models"
|
2018-04-23 12:22:27 +00:00
|
|
|
import autoload, locate, registry from require "locator"
|
|
|
|
import settings from autoload "utility"
|
2018-04-24 17:02:39 +00:00
|
|
|
import main from autoload "layouts"
|
2018-04-23 12:22:27 +00:00
|
|
|
|
|
|
|
class Simplex extends Application
|
|
|
|
@before_filter =>
|
|
|
|
settings.load!
|
|
|
|
registry.before_filter(@)
|
|
|
|
|
2018-04-24 17:02:39 +00:00
|
|
|
layout: main
|
|
|
|
|
2018-04-23 12:22:27 +00:00
|
|
|
@include locate "users"
|
|
|
|
@include locate "api"
|
|
|
|
|
2018-04-25 01:35:31 +00:00
|
|
|
-- TODO intentionally cause an error to see if this is working as intended
|
|
|
|
handle_error: (err, trace) =>
|
|
|
|
if @original_request.route_name\find "api_"
|
|
|
|
return status: 500, json: { errors: {err}, :trace } -- NOTE trace should be saved and NOT returned to the user
|
|
|
|
else
|
|
|
|
super!
|
|
|
|
|
2018-04-23 12:22:27 +00:00
|
|
|
[index: "/"]: =>
|
2018-04-25 02:08:59 +00:00
|
|
|
@title = "Simplex Task Manager"
|
|
|
|
|
2018-04-23 12:22:27 +00:00
|
|
|
if @user
|
2018-04-24 13:29:05 +00:00
|
|
|
@keys = APIKeys\select "WHERE user_id = ? ORDER BY id ASC", @user.id
|
|
|
|
@tasks = Tasks\select "WHERE user_id = ? ORDER BY id ASC", @user.id
|
2018-04-23 12:22:27 +00:00
|
|
|
|
|
|
|
unless @keys and #@keys > 0
|
|
|
|
@keys = {APIKeys\create(@user)}
|
|
|
|
|
|
|
|
return render: "index.logged_in"
|
|
|
|
|
|
|
|
else
|
2018-04-25 01:33:18 +00:00
|
|
|
@html ->
|
|
|
|
a href: @url_for("user_login"), "log in"
|
|
|
|
text " | "
|
|
|
|
a href: @url_for("user_new"), "new user"
|
2018-04-23 13:06:56 +00:00
|
|
|
|
2018-04-23 13:08:09 +00:00
|
|
|
[console: "/console"]: =>
|
2018-04-23 13:09:47 +00:00
|
|
|
if @user and @user.admin
|
|
|
|
console = require "lapis.console"
|
|
|
|
return console.make(env: "all")(@)
|
2018-04-25 01:33:18 +00:00
|
|
|
else
|
|
|
|
return status: 404, "Not found."
|