Created
December 22, 2019 23:36
-
-
Save tcyrus/3d4b1bd19834e98e87154bdbc341e380 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lapis = require "lapis" | |
import Model from require "lapis.db.model" | |
import respond_to, capture_errors from require "lapis.application" | |
class Users extends Model | |
class Items extends Model | |
class extends lapis.Application | |
[index: "/"]: => | |
"For API, see https://standardfile.org" | |
-- Respond to different HTTP actions to do the right thing | |
[auth: "/auth"]: respond_to { | |
POST: capture_errors => | |
csrf.assert_token @ | |
Users\create name: @params.username | |
redirect_to: @url_for "list_users" | |
PATCH: => | |
@html -> | |
form method: "POST", action: @url_for("new_user"), -> | |
input type: "hidden", | |
name: "csrf_token", value: @csrf_token | |
input type: "text", name: "username" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
schema = require "lapis.db.schema" | |
import create_table, types from schema | |
create_table "users", { | |
{"uuid", "UUID PRIMARY KEY DEFAULT gen_random_uuid()"} | |
{"email", types.text} | |
{"pw_func", types.text}, | |
{"pw_alg", types.text}, | |
{"pw_cost", types.integer}, | |
{"pw_key_size", types.integer}, | |
{"pw_nonce", types.text}, | |
{"encrypted_password", types.text}, | |
{"created_at", types.time}, | |
{"updated_at", types.time}, | |
{"pw_salt", types.text}, | |
{"version", types.text} | |
} | |
create_table "items", { | |
{"uuid", "UUID PRIMARY KEY DEFAULT gen_random_uuid()"} | |
{"content", "BYTEA NOT NULL"} | |
{"content_type", types.text}, | |
{"enc_item_key", types.text}, | |
{"auth_hash", types.text}, | |
{"user_uuid", "UUID NOT NULL"}, | |
{"deleted", types.boolean}, | |
{"encrypted_password", types.text}, | |
{"created_at", types.time}, | |
{"updated_at", types.time}, | |
{"last_user_agent", types.text null: true} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment