-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from lwileczek/feat/login
User login page, but doesn't really work
- Loading branch information
Showing
19 changed files
with
595 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: "Go - Basic Checks" | ||
on: | ||
push: | ||
branches: [ "trunk" ] | ||
paths: | ||
- '**.go' | ||
pull_request: | ||
paths: | ||
- '**.go' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
go-version: [ '1.21.x', '1.22.x' ] | ||
|
||
steps: | ||
- name: Download This Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Go ${{ matrix.go-version }} | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
|
||
- name: Display Go version | ||
run: go version | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Generate | ||
run: go generate -v ./... | ||
|
||
- name: Vet | ||
run: go vet ./... | ||
|
||
- name: Test | ||
run: go test -v ./... -short |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,8 @@ app/kodata | |
bootstrap | ||
main | ||
|
||
# Generated static pages | ||
pages | ||
|
||
# For testing files | ||
tmp |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
build: | ||
mkdir -p static/img | ||
npm run build | ||
go generate ./... | ||
go build -o server ./app/main.go | ||
|
||
run: | ||
mkdir -p static/img | ||
npm run build | ||
go generate ./... | ||
go run ./app/main.go | ||
|
||
deployLambda: | ||
bash utils/deploy.sh | ||
|
||
buildContainer: | ||
npm run build | ||
go generate ./... | ||
mkdir app/kodata | ||
cp -r static templates app/kodata | ||
ko build ./app/... |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/* | ||
source code: https://github.com/modfin/pg-xid | ||
ref: https://stackoverflow.com/a/48382296 | ||
Copyright 2022 Rasmus Holm | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
DO $$ BEGIN | ||
CREATE DOMAIN public.xid AS CHAR(20) CHECK (VALUE ~ '^[a-v0-9]{20}$'); | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
|
||
CREATE SEQUENCE IF NOT EXISTS public.xid_serial MINVALUE 0 MAXVALUE 16777215 CYCLE; -- ((255<<16) + (255<<8) + 255)) | ||
|
||
SELECT setval('xid_serial', (random() * 16777215)::INT); -- ((255<<16) + (255<<8) + 255)) | ||
|
||
CREATE OR REPLACE FUNCTION public._xid_machine_id() | ||
RETURNS INT | ||
LANGUAGE plpgsql | ||
IMMUTABLE | ||
AS | ||
$$ | ||
DECLARE | ||
BEGIN | ||
RETURN (SELECT system_identifier & 16777215 FROM pg_control_system()); | ||
END | ||
$$; | ||
|
||
CREATE OR REPLACE FUNCTION public.xid_encode(_id int[]) | ||
RETURNS public.xid | ||
LANGUAGE plpgsql | ||
AS | ||
$$ | ||
DECLARE | ||
_encoding CHAR(1)[] = '{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v}'; | ||
BEGIN | ||
RETURN _encoding[1 + (_id[1] >> 3)] | ||
|| _encoding[1 + ((_id[2] >> 6) & 31 | (_id[1] << 2) & 31)] | ||
|| _encoding[1 + ((_id[2] >> 1) & 31)] | ||
|| _encoding[1 + ((_id[3] >> 4) & 31 | (_id[2] << 4) & 31)] | ||
|| _encoding[1 + (_id[4] >> 7 | (_id[3] << 1) & 31)] | ||
|| _encoding[1 + ((_id[4] >> 2) & 31)] | ||
|| _encoding[1 + (_id[5] >> 5 | (_id[4] << 3) & 31)] | ||
|| _encoding[1 + (_id[5] & 31)] | ||
|| _encoding[1 + (_id[6] >> 3)] | ||
|| _encoding[1 + ((_id[7] >> 6) & 31 | (_id[6] << 2) & 31)] | ||
|| _encoding[1 + ((_id[7] >> 1) & 31)] | ||
|| _encoding[1 + ((_id[8] >> 4) & 31 | (_id[7] << 4) & 31)] | ||
|| _encoding[1 + (_id[9] >> 7 | (_id[8] << 1) & 31)] | ||
|| _encoding[1 + ((_id[9] >> 2) & 31)] | ||
|| _encoding[1 + ((_id[10] >> 5) | (_id[9] << 3) & 31)] | ||
|| _encoding[1 + (_id[10] & 31)] | ||
|| _encoding[1 + (_id[11] >> 3)] | ||
|| _encoding[1 + ((_id[12] >> 6) & 31 | (_id[11] << 2) & 31)] | ||
|| _encoding[1 + ((_id[12] >> 1) & 31)] | ||
|| _encoding[1 + ((_id[12] << 4) & 31)]; | ||
END; | ||
$$; | ||
|
||
CREATE OR REPLACE FUNCTION public.xid_decode(_xid public.xid) | ||
RETURNS int[] | ||
LANGUAGE plpgsql | ||
AS | ||
$$ | ||
DECLARE | ||
_dec int[] = '{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}'; | ||
_b bytea; | ||
BEGIN | ||
_b := _xid::BYTEA; | ||
return ARRAY [ | ||
((_dec[get_byte(_b, 0)] << 3) | (_dec[get_byte(_b, 1)] >> 2)) & 255, | ||
((_dec[get_byte(_b, 1)] << 6) | (_dec[get_byte(_b, 2)] << 1) | (_dec[get_byte(_b, 3)] >> 4)) & 255, | ||
((_dec[get_byte(_b, 3)] << 4) | (_dec[get_byte(_b, 4)] >> 1)) & 255, | ||
((_dec[get_byte(_b, 4)] << 7) | (_dec[get_byte(_b, 5)] << 2) | (_dec[get_byte(_b, 6)] >> 3)) & 255, | ||
((_dec[get_byte(_b, 6)] << 5) | (_dec[get_byte(_b, 7)])) & 255, | ||
((_dec[get_byte(_b, 8)] << 3) | (_dec[get_byte(_b, 9)] >> 2)) & 255, | ||
((_dec[get_byte(_b, 9)] << 6) | (_dec[get_byte(_b, 10)] << 1) | (_dec[get_byte(_b, 11)] >> 4)) & 255, | ||
((_dec[get_byte(_b, 11)] << 4) | (_dec[get_byte(_b, 12)] >> 1)) & 255, | ||
((_dec[get_byte(_b, 12)] << 7) | (_dec[get_byte(_b, 13)] << 2) | (_dec[get_byte(_b, 14)] >> 3)) & 255, | ||
((_dec[get_byte(_b, 14)] << 5) | (_dec[get_byte(_b, 15)])) & 255, | ||
((_dec[get_byte(_b, 16)] << 3) | (_dec[get_byte(_b, 17)] >> 2)) & 255, | ||
((_dec[get_byte(_b, 17)] << 6) | (_dec[get_byte(_b, 18)] << 1) | (_dec[get_byte(_b, 19)] >> 4)) & 255 | ||
]; | ||
END; | ||
$$; | ||
|
||
CREATE OR REPLACE FUNCTION xid(_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP) | ||
RETURNS public.xid | ||
LANGUAGE plpgsql | ||
AS | ||
$$ | ||
DECLARE | ||
_t INT; | ||
_m INT; | ||
_p INT; | ||
_c INT; | ||
BEGIN | ||
_t := floor(EXTRACT(epoch FROM _at)); | ||
_m := _xid_machine_id(); | ||
_p := pg_backend_pid(); | ||
_c := nextval('xid_serial')::INT; | ||
|
||
return public.xid_encode(ARRAY [ | ||
(_t >> 24) & 255, (_t >> 16) & 255, (_t >> 8) & 255 , _t & 255, | ||
(_m >> 16) & 255, (_m >> 8) & 255 , _m & 255, | ||
(_p >> 8) & 255, _p & 255, | ||
(_c >> 16) & 255, (_c >> 8) & 255 , _c & 255 | ||
]); | ||
END; | ||
$$; | ||
|
||
CREATE OR REPLACE FUNCTION public.xid_time(_xid public.xid) | ||
RETURNS TIMESTAMPTZ | ||
LANGUAGE plpgsql | ||
AS | ||
$$ | ||
DECLARE | ||
_id int[]; | ||
BEGIN | ||
_id := public.xid_decode(_xid); | ||
return to_timestamp((_id[1] << 24)::BIGINT + (_id[2] << 16) + (_id[3] << 8) + (_id[4])); | ||
END; | ||
$$; | ||
|
||
CREATE OR REPLACE FUNCTION public.xid_machine(_xid public.xid) | ||
RETURNS INT[] | ||
LANGUAGE plpgsql | ||
AS | ||
$$ | ||
DECLARE | ||
_id int[]; | ||
BEGIN | ||
_id := public.xid_decode(_xid); | ||
return ARRAY [_id[5], _id[6], _id[7]]; | ||
END; | ||
$$; | ||
|
||
CREATE OR REPLACE FUNCTION public.xid_pid(_xid public.xid) | ||
RETURNS INT | ||
LANGUAGE plpgsql | ||
AS | ||
$$ | ||
DECLARE | ||
_id int[]; | ||
BEGIN | ||
_id := public.xid_decode(_xid); | ||
return (_id[8] << 8) + (_id[9]); | ||
END; | ||
$$; | ||
|
||
CREATE OR REPLACE FUNCTION public.xid_counter(_xid public.xid) | ||
RETURNS INT | ||
LANGUAGE plpgsql | ||
AS | ||
$$ | ||
DECLARE | ||
_id int[]; | ||
BEGIN | ||
_id := public.xid_decode(_xid); | ||
return (_id[10] << 16) + (_id[11] << 8) + (_id[12]); | ||
END; | ||
$$; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
-- Table to store users so they can login | ||
CREATE TABLE users ( | ||
-- unique id | ||
id SERIAL not null primary key, | ||
id CHAR(21) NOT NULL PRIMARY KEY DEFAULT 'u' || xid(), | ||
-- some name for the user | ||
name VARCHAR(48) not null, | ||
name VARCHAR(48) NOT NULL, | ||
-- salt for this user's password | ||
salt CHAR(8) not null, | ||
salt CHAR(8) NOT NULL, | ||
-- hashed password | ||
passwd CHAR(64) not null | ||
passwd CHAR(64) NOT NULL, | ||
-- Time the user was created | ||
created_at DATE DEFAULT NOW()::date, | ||
-- Admin: if the user is an admin user or not | ||
admin BOOLEAN DEFAULT FALSE | ||
); | ||
|
||
INSERT INTO users(name, salt, passwd) VALUES('admin', 'CWWo5vK7', 'efc48adf01fc6f785244f28677bee8a884541861c4d2b3a4ff4db691cab6259e'); | ||
INSERT INTO users(name, salt, passwd, admin) VALUES('admin', 'CWWo5vK7', 'efc48adf01fc6f785244f28677bee8a884541861c4d2b3a4ff4db691cab6259e', true); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- Table to store user sessionss for logins | ||
CREATE TABLE IF NOT EXISTS sessions ( | ||
-- unique id | ||
session_id CHAR(64) PRIMARY KEY, | ||
-- Time the session was created | ||
created_at TIMESTAMP DEFAULT NOW(), | ||
-- The ID of the task the image is related too | ||
user_id public.xid NOT NULL, | ||
CONSTRAINT fk_task | ||
FOREIGN KEY (user_id) | ||
REFERENCES users(id) | ||
); |
This file contains 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
Oops, something went wrong.