committing everything before round 2
This commit is contained in:
@@ -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")
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package auth
|
||||
|
||||
//import ()
|
||||
@@ -0,0 +1,4 @@
|
||||
package auth
|
||||
|
||||
//import ()
|
||||
|
||||
@@ -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.
@@ -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
|
||||
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
Reference in New Issue
Block a user