simplex/app.moon
2018-04-24 18:35:31 -07:00

47 lines
1.3 KiB
Plaintext

import Application from require "lapis"
import APIKeys, Tasks from require "models"
import autoload, locate, registry from require "locator"
import settings from autoload "utility"
import main from autoload "layouts"
class Simplex extends Application
@before_filter =>
settings.load!
registry.before_filter(@)
layout: main
@include locate "users"
@include locate "api"
-- 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!
[index: "/"]: =>
if @user
@keys = APIKeys\select "WHERE user_id = ? ORDER BY id ASC", @user.id
@tasks = Tasks\select "WHERE user_id = ? ORDER BY id ASC", @user.id
unless @keys and #@keys > 0
@keys = {APIKeys\create(@user)}
return render: "index.logged_in"
else
@html ->
a href: @url_for("user_login"), "log in"
text " | "
a href: @url_for("user_new"), "new user"
[console: "/console"]: =>
if @user and @user.admin
console = require "lapis.console"
return console.make(env: "all")(@)
else
return status: 404, "Not found."