feat(auth): add argon2id passwords, sessions, rate limiter, authorization and audit builders
- feat(auth): add argon2id passwords, sessions, rate limiter, authorization and audit builders - feat(cli): add check and audit commands - feat(api): add api framework, login, page routes and account, user, delegation and audit handlers - test(auth): cover passwords, sessions, rate limiter, authorization and audit builders - test(api): cover the api framework, sessions, client origin, headers and cross-origin refusal - test(api): cover account, user, delegation and audit handlers and the authorization matrix - test(ui): cover login, logout, page routes and the page authorization matrix
This commit is contained in:
1 parent
23bec143e3
commit
99fa5de747
28 files changed
+6591
-243
No files matched your search
@@ -6,7 +6,6 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
@@ -205,26 +204,3 @@ func (s userStore) TouchLastLogin(ctx context.Context, id int64, now time.Time)
|
||||
return s.exec(ctx, "touch last login",
|
||||
"UPDATE {users} SET `last_login_at` = ? WHERE `id` = ?", dbTime(now), id)
|
||||
}
|
||||
|
||||
type auditUserValue struct {
|
||||
ID int64 `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Role string `json:"role"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
DeletedAt *string `json:"deleted_at"`
|
||||
}
|
||||
|
||||
const auditTimeLayout = "2006-01-02T15:04:05.000000Z"
|
||||
|
||||
func formatAuditTime(t time.Time) string {
|
||||
return t.UTC().Format(auditTimeLayout)
|
||||
}
|
||||
|
||||
func auditUserJSON(u userRow) ([]byte, error) {
|
||||
v := auditUserValue{ID: u.ID, Username: u.Username, Role: u.Role, CreatedAt: formatAuditTime(u.CreatedAt)}
|
||||
if u.DeletedAt.Valid {
|
||||
d := formatAuditTime(u.DeletedAt.Time)
|
||||
v.DeletedAt = &d
|
||||
}
|
||||
return json.Marshal(v)
|
||||
}
|
||||
Reference in new issue
Block a user