From e0fa5216574f062bc04d329c8eb460be9cd578c2 Mon Sep 17 00:00:00 2001 From: MrMelon54 Date: Mon, 13 May 2024 20:25:44 +0100 Subject: [PATCH] Transition to new logger --- database/manage-users.sql.go | 5 ++++- database/queries/manage-users.sql | 3 ++- database/queries/users.sql | 6 +++--- database/users.sql.go | 12 ++++++------ go.sum | 16 +++++----------- pages/edit.go.html | 4 ++-- pages/index.go.html | 2 +- pages/manage-apps.go.html | 12 ++++++------ pages/manage-users.go.html | 10 +++++----- pages/pages.go | 1 + server/db.go | 1 + server/home.go | 2 +- 12 files changed, 37 insertions(+), 37 deletions(-) diff --git a/database/manage-users.sql.go b/database/manage-users.sql.go index 3901ec9..0107baa 100644 --- a/database/manage-users.sql.go +++ b/database/manage-users.sql.go @@ -17,6 +17,7 @@ SELECT subject, name, username, picture, + website, email, email_verified, role, @@ -31,6 +32,7 @@ type GetUserListRow struct { Name string `json:"name"` Username string `json:"username"` Picture string `json:"picture"` + Website string `json:"website"` Email string `json:"email"` EmailVerified bool `json:"email_verified"` Role types.UserRole `json:"role"` @@ -52,6 +54,7 @@ func (q *Queries) GetUserList(ctx context.Context, offset int64) ([]GetUserListR &i.Name, &i.Username, &i.Picture, + &i.Website, &i.Email, &i.EmailVerified, &i.Role, @@ -90,7 +93,7 @@ func (q *Queries) UpdateUserRole(ctx context.Context, arg UpdateUserRoleParams) } const userEmailExists = `-- name: UserEmailExists :one -SELECT CAST(EXISTS(SELECT 1 FROM users WHERE email = ? AND email_verified = 1) AS BOOLEAN) AS email_exists +SELECT EXISTS(SELECT 1 FROM users WHERE email = ? AND email_verified = 1) == 1 AS email_exists ` func (q *Queries) UserEmailExists(ctx context.Context, email string) (bool, error) { diff --git a/database/queries/manage-users.sql b/database/queries/manage-users.sql index c92db49..351a022 100644 --- a/database/queries/manage-users.sql +++ b/database/queries/manage-users.sql @@ -3,6 +3,7 @@ SELECT subject, name, username, picture, + website, email, email_verified, role, @@ -23,4 +24,4 @@ SET email_verified = 1 WHERE subject = ?; -- name: UserEmailExists :one -SELECT CAST(EXISTS(SELECT 1 FROM users WHERE email = ? AND email_verified = 1) AS BOOLEAN) AS email_exists; +SELECT EXISTS(SELECT 1 FROM users WHERE email = ? AND email_verified = 1) == 1 AS email_exists; diff --git a/database/queries/users.sql b/database/queries/users.sql index 4b0a85b..3ea85fb 100644 --- a/database/queries/users.sql +++ b/database/queries/users.sql @@ -1,5 +1,5 @@ -- name: HasUser :one -SELECT CAST(count(subject) AS BOOLEAN) AS hasUser +SELECT count(subject) > 0 AS hasUser FROM users; -- name: addUser :exec @@ -7,7 +7,7 @@ INSERT INTO users (subject, name, username, password, email, email_verified, rol VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?); -- name: checkLogin :one -SELECT subject, name, password, CAST(EXISTS(SELECT 1 FROM otp WHERE otp.subject = users.subject) AS BOOLEAN) AS has_otp, email, email_verified +SELECT subject, name, password, EXISTS(SELECT 1 FROM otp WHERE otp.subject = users.subject) == 1 AS has_otp, email, email_verified FROM users WHERE username = ? LIMIT 1; @@ -69,7 +69,7 @@ FROM otp WHERE subject = ?; -- name: HasOtp :one -SELECT CAST(EXISTS(SELECT 1 FROM otp WHERE subject = ?) AS BOOLEAN); +SELECT EXISTS(SELECT 1 FROM otp WHERE subject = ?) == 1 as hasOtp; -- name: GetUserEmail :one SELECT email diff --git a/database/users.sql.go b/database/users.sql.go index 5b40415..dd2ceb0 100644 --- a/database/users.sql.go +++ b/database/users.sql.go @@ -114,18 +114,18 @@ func (q *Queries) GetUserRole(ctx context.Context, subject string) (types.UserRo } const hasOtp = `-- name: HasOtp :one -SELECT CAST(EXISTS(SELECT 1 FROM otp WHERE subject = ?) AS BOOLEAN) +SELECT EXISTS(SELECT 1 FROM otp WHERE subject = ?) == 1 as hasOtp ` func (q *Queries) HasOtp(ctx context.Context, subject string) (bool, error) { row := q.db.QueryRowContext(ctx, hasOtp, subject) - var column_1 bool - err := row.Scan(&column_1) - return column_1, err + var hasotp bool + err := row.Scan(&hasotp) + return hasotp, err } const hasUser = `-- name: HasUser :one -SELECT CAST(count(subject) AS BOOLEAN) AS hasUser +SELECT count(subject) > 0 AS hasUser FROM users ` @@ -252,7 +252,7 @@ func (q *Queries) changeUserPassword(ctx context.Context, arg changeUserPassword } const checkLogin = `-- name: checkLogin :one -SELECT subject, name, password, CAST(EXISTS(SELECT 1 FROM otp WHERE otp.subject = users.subject) AS BOOLEAN) AS has_otp, email, email_verified +SELECT subject, name, password, EXISTS(SELECT 1 FROM otp WHERE otp.subject = users.subject) == 1 AS has_otp, email, email_verified FROM users WHERE username = ? LIMIT 1 diff --git a/go.sum b/go.sum index fadfa17..abf1b77 100644 --- a/go.sum +++ b/go.sum @@ -5,8 +5,7 @@ github.com/1f349/mjwt v0.2.5 h1:IxjLaali22ayTzZ628lH7j0JDdYJoj6+CJ/VktCqtXQ= github.com/1f349/mjwt v0.2.5/go.mod h1:KEs6jd9JjWrQW+8feP2pGAU7pdA3aYTqjkT/YQr73PU= github.com/1f349/overlapfs v0.0.1 h1:LAxBolrXFAgU0yqZtXg/C/aaPq3eoQSPpBc49BHuTp0= github.com/1f349/overlapfs v0.0.1/go.mod h1:I6aItQycr7nrzplmfNXp/QF9tTmKRSgY3fXmu/7Ky2o= -github.com/1f349/violet v0.0.13 h1:lJpTz15Ea83Uc1VAISXTjtKuzr8Pe8NM4cMGp3Aiyhk= -github.com/1f349/violet v0.0.13/go.mod h1:Ga5/hWqI+EkR6J1mAMNzs7aJhuGcA89XFqgQaDXC7Jo= +github.com/1f349/violet v0.0.14 h1:MpBZ4n1dJjdiIwYMTfh0PBIFll3kjqowxR6DLasafqE= github.com/1f349/violet v0.0.14/go.mod h1:iAREhm+wxnGXkmuvmBhOuhUx2T7/5w7stLYNgQGbqC8= github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU= github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= @@ -91,12 +90,12 @@ github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/klauspost/compress v1.15.11 h1:Lcadnb3RKGin4FYM/orgq0qde+nc15E5Cbqg4B9Sx9c= github.com/klauspost/compress v1.15.11/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= @@ -136,8 +135,6 @@ github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= -github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= @@ -227,8 +224,6 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= -golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -285,9 +280,8 @@ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miE google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/pages/edit.go.html b/pages/edit.go.html index 3686e93..ef67d3d 100644 --- a/pages/edit.go.html +++ b/pages/edit.go.html @@ -9,7 +9,7 @@

{{.ServiceName}}

-
Logged in as: {{.User.Name}} ({{.User.Sub}})
+
Logged in as: {{.User.Name}} ({{.User.Subject}})
@@ -43,7 +43,7 @@
- + {{range .ListZoneInfo}} diff --git a/pages/index.go.html b/pages/index.go.html index 85d438b..a0513be 100644 --- a/pages/index.go.html +++ b/pages/index.go.html @@ -9,7 +9,7 @@

{{.ServiceName}}

-
Logged in as: {{.User.Name}} ({{.User.Sub}})
+
Logged in as: {{.User.Name}} ({{.User.Subject}})
diff --git a/pages/manage-apps.go.html b/pages/manage-apps.go.html index d2578c2..9b4feb0 100644 --- a/pages/manage-apps.go.html +++ b/pages/manage-apps.go.html @@ -46,9 +46,9 @@ - +
- +
@@ -96,23 +96,23 @@ {{range .Apps}} - {{.Sub}} + {{.Subject}} {{.Name}} {{.Domain}} {{.Public}} - {{.SSO}} + {{.Sso}} {{.Active}} {{.Owner}} - +
- +
diff --git a/pages/manage-users.go.html b/pages/manage-users.go.html index 5791b3e..226e2f2 100644 --- a/pages/manage-users.go.html +++ b/pages/manage-users.go.html @@ -18,9 +18,9 @@
- +
- +
@@ -71,7 +71,7 @@ {{range .Users}} - {{.Sub}} + {{.Subject}} {{.Name}} {{.Username}} @@ -92,12 +92,12 @@ {{.UpdatedAt}} {{.Active}} - {{if eq $.CurrentAdmin .Sub}} + {{if eq $.CurrentAdmin .Subject}} {{else}} - +
diff --git a/pages/pages.go b/pages/pages.go index 8741533..048963a 100644 --- a/pages/pages.go +++ b/pages/pages.go @@ -41,6 +41,7 @@ func LoadPages(wd string) (err error) { } func RenderPageTemplate(wr io.Writer, name string, data any) { + logger.Logger.Helper() err := wwwTemplates.ExecuteTemplate(wr, name+".go.html", data) if err != nil { logger.Logger.Warn("Failed to render page", "name", name, "err", err) diff --git a/server/db.go b/server/db.go index 90a8738..9f5f5f8 100644 --- a/server/db.go +++ b/server/db.go @@ -13,6 +13,7 @@ func (h *HttpServer) DbTx(rw http.ResponseWriter, action func(db *database.Queri err := action(h.db) if err != nil { http.Error(rw, "Database error", http.StatusInternalServerError) + logger.Logger.Helper() logger.Logger.Warn("Database action error", "err", err) return true } diff --git a/server/home.go b/server/home.go index 6cd9a54..a5ac337 100644 --- a/server/home.go +++ b/server/home.go @@ -53,7 +53,7 @@ func (h *HttpServer) Home(rw http.ResponseWriter, req *http.Request, _ httproute pages.RenderPageTemplate(rw, "index", map[string]any{ "ServiceName": h.conf.ServiceName, "Auth": auth, - "User": userWithName, + "User": database.User{Subject: auth.ID, Name: userWithName, Role: userRole}, "Nonce": lNonce, "OtpEnabled": hasTwoFactor, "IsAdmin": userRole == types.RoleAdmin,