committing everything before round 2

This commit is contained in:
2026-08-12 14:14:09 -06:00
parent 27ae08690e
commit d14488d2f2
36 changed files with 562 additions and 55 deletions
+21
View File
@@ -0,0 +1,21 @@
package auth
import (
"github.com/alexedwards/scs/v2"
"golang.org/x/crypto/bcrypt"
)
// remember, if anyone attempts to login as the system or zombie user, fail them. hard.
// sessionManager needs to be figured out. do i inherit that from somewhere else?
// does it get associated with any other one like PHP's `session_open()` if i call it here?
func set(writer http.ResponseWriter, request *http.Request) {
sessionManager.Put(request.Context(), "sessionKey", "message to be passed around")
}
func get(writer http.ResponseWriter, request *http.Request) String {
return sessionManager.GetString(request.Context(), "sessionKey")
}
+3
View File
@@ -0,0 +1,3 @@
package auth
//import ()
+4
View File
@@ -0,0 +1,4 @@
package auth
//import ()
+16
View File
@@ -0,0 +1,16 @@
package auth
import (
"net/http"
)
func requireAuth(next http.Handler) http.Handler {
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
if !sessionManager.Exists(request.Context(), "userID") {
http.Redirect(writer, request, "/login", http.StatusSeeOther)
return
}
next.ServeHTTP(writer, request)
})
}
Binary file not shown.
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/bash
for up_file in *.up.sql; do
down_file="${up_file%.up.sql}.down.sql"
quoted_text=$(sed -n '3s/[^"]*\("[^"]*"\).*/\1/p' "$up_file")
first_line=$(head -n 1 "$up_file")
if [[ "$first_line" != *".up.sql" ]]; then
sed -i "1s/$/\.up\.sql/" "$up_file"
fi
head -n 3 "$up_file" > "$down_file"
echo "DROP TABLE IF EXISTS ${quoted_text};" >> "$down_file"
tail -n 1 "$up_file" >> "$down_file"
done
sed -i 's/\bCREATE\b/DROP/g' *.down.sql
for file in *.sql; do
[ -f "$file" ] || continue
line3=$(sed -n '3p' "$file")
len=${#line3}
if [ "$len" -lt 64 ]; then
needed=$((64 - len))
dashes=$(printf '%*s' "$needed" | tr ' ' '-')
sed -i "3s/$/$dashes/" "$file"
fi
done
for file in *.down.sql; do
[ -f "$file" ] || continue
first_line=$(head -n 1 "$file")
if [[ "$first_line" == *".up.sql" ]]; then
sed -i '1s/\.up\.sql$/\.down\.sql/' "$file"
fi
done
+2
View File
@@ -0,0 +1,2 @@
*
!.gitignore
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File