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"
|
|
|
|
|
|
|
|
class Simplex extends Application
|
|
|
|
@before_filter =>
|
|
|
|
settings.load!
|
|
|
|
registry.before_filter(@)
|
|
|
|
|
|
|
|
@include locate "users"
|
|
|
|
@include locate "api"
|
|
|
|
|
|
|
|
[index: "/"]: =>
|
|
|
|
-- NOTE TEMPORARY
|
|
|
|
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
|
|
|
|
return redirect_to: @url_for "user_login", nil, redirect: @url_for "index"
|
|
|
|
|
|
|
|
[new_api_key: "/new-api-key"]: =>
|
|
|
|
if @user
|
2018-04-24 05:42:56 +00:00
|
|
|
if api_key = APIKeys\create(@user)
|
|
|
|
return json: { success: true, :api_key }
|
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")(@)
|