mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
WIP save point. Server + W2-4/W3-3 complete and gate-green; F3 voice E2EE identity keys + TOFU implemented and MITM-verified-closed; the F3 voice-panel UI (safety-number display, verified/mismatch badge, re-pin modal) is still TODO. - W2-4 attachment link (coverage confirmed); W3-3a XFF CIDR pre-parse; W3-3b update-binary TOCTOU (single-handle verify + O_EXCL staging) - F3 server: migration 017 identity_public_key, PATCH /users/me persist, ready/member_join/user_update carry key, signed voice_e2ee_announce - F3 client: ECDSA identity keypair (keyring + pin store), publish wired into ready, verifyPeerAnnounce pin-before-legacy, rePinPeerIdentity recovery - Gates: server full CI mirror green (-race/-deadlock/lint/4 build tags); client typecheck/lint/format + 3337 vitest green. Rust CI-verify only. Next: build F3 voice-panel UI, then adversarial review, then finalize commit. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
225 lines
5.7 KiB
Go
225 lines
5.7 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: users.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const banUser = `-- name: BanUser :exec
|
|
UPDATE users SET banned = 1, ban_reason = ?, ban_expires = ? WHERE id = ?
|
|
`
|
|
|
|
type BanUserParams struct {
|
|
BanReason *string `json:"banReason"`
|
|
BanExpires *string `json:"banExpires"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) BanUser(ctx context.Context, arg BanUserParams) error {
|
|
_, err := q.db.ExecContext(ctx, banUser, arg.BanReason, arg.BanExpires, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const countUsers = `-- name: CountUsers :one
|
|
SELECT COUNT(*) FROM users
|
|
`
|
|
|
|
func (q *Queries) CountUsers(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, countUsers)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const countUsersWithoutTOTP = `-- name: CountUsersWithoutTOTP :one
|
|
SELECT COUNT(*) FROM users WHERE banned = 0 AND totp_secret IS NULL
|
|
`
|
|
|
|
func (q *Queries) CountUsersWithoutTOTP(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, countUsersWithoutTOTP)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createUser = `-- name: CreateUser :execresult
|
|
INSERT INTO users (username, password, role_id) VALUES (?, ?, ?)
|
|
`
|
|
|
|
type CreateUserParams struct {
|
|
Username string `json:"username"`
|
|
Password string `json:"password"`
|
|
RoleID int64 `json:"roleId"`
|
|
}
|
|
|
|
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (sql.Result, error) {
|
|
return q.db.ExecContext(ctx, createUser, arg.Username, arg.Password, arg.RoleID)
|
|
}
|
|
|
|
const getUserByID = `-- name: GetUserByID :one
|
|
SELECT id, username, password, avatar, role_id, totp_secret, status,
|
|
created_at, last_seen, banned, ban_reason, ban_expires, identity_public_key
|
|
FROM users WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) GetUserByID(ctx context.Context, id int64) (User, error) {
|
|
row := q.db.QueryRowContext(ctx, getUserByID, id)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.Password,
|
|
&i.Avatar,
|
|
&i.RoleID,
|
|
&i.TotpSecret,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.LastSeen,
|
|
&i.Banned,
|
|
&i.BanReason,
|
|
&i.BanExpires,
|
|
&i.IdentityPublicKey,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getUserByUsername = `-- name: GetUserByUsername :one
|
|
SELECT id, username, password, avatar, role_id, totp_secret, status,
|
|
created_at, last_seen, banned, ban_reason, ban_expires, identity_public_key
|
|
FROM users WHERE username = ? COLLATE NOCASE
|
|
`
|
|
|
|
func (q *Queries) GetUserByUsername(ctx context.Context, username string) (User, error) {
|
|
row := q.db.QueryRowContext(ctx, getUserByUsername, username)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.Password,
|
|
&i.Avatar,
|
|
&i.RoleID,
|
|
&i.TotpSecret,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.LastSeen,
|
|
&i.Banned,
|
|
&i.BanReason,
|
|
&i.BanExpires,
|
|
&i.IdentityPublicKey,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listMembers = `-- name: ListMembers :many
|
|
SELECT u.id, u.username, u.avatar, u.status, LOWER(r.name), u.identity_public_key
|
|
FROM users u
|
|
JOIN roles r ON u.role_id = r.id
|
|
WHERE u.banned = 0
|
|
ORDER BY u.username ASC
|
|
LIMIT 1000
|
|
`
|
|
|
|
type ListMembersRow struct {
|
|
ID int64 `json:"id"`
|
|
Username string `json:"username"`
|
|
Avatar *string `json:"avatar"`
|
|
Status string `json:"status"`
|
|
Lower string `json:"lower"`
|
|
IdentityPublicKey *string `json:"identityPublicKey"`
|
|
}
|
|
|
|
func (q *Queries) ListMembers(ctx context.Context) ([]ListMembersRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, listMembers)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListMembersRow{}
|
|
for rows.Next() {
|
|
var i ListMembersRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.Avatar,
|
|
&i.Status,
|
|
&i.Lower,
|
|
&i.IdentityPublicKey,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const resetAllUserStatuses = `-- name: ResetAllUserStatuses :exec
|
|
UPDATE users SET status = 'offline' WHERE status != 'offline'
|
|
`
|
|
|
|
func (q *Queries) ResetAllUserStatuses(ctx context.Context) error {
|
|
_, err := q.db.ExecContext(ctx, resetAllUserStatuses)
|
|
return err
|
|
}
|
|
|
|
const unbanUser = `-- name: UnbanUser :exec
|
|
UPDATE users SET banned = 0, ban_reason = NULL, ban_expires = NULL WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) UnbanUser(ctx context.Context, id int64) error {
|
|
_, err := q.db.ExecContext(ctx, unbanUser, id)
|
|
return err
|
|
}
|
|
|
|
const updateUserIdentityKey = `-- name: UpdateUserIdentityKey :exec
|
|
UPDATE users SET identity_public_key = ? WHERE id = ?
|
|
`
|
|
|
|
type UpdateUserIdentityKeyParams struct {
|
|
IdentityPublicKey *string `json:"identityPublicKey"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateUserIdentityKey(ctx context.Context, arg UpdateUserIdentityKeyParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateUserIdentityKey, arg.IdentityPublicKey, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const updateUserStatus = `-- name: UpdateUserStatus :exec
|
|
UPDATE users SET status = ?, last_seen = datetime('now') WHERE id = ?
|
|
`
|
|
|
|
type UpdateUserStatusParams struct {
|
|
Status string `json:"status"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateUserStatus(ctx context.Context, arg UpdateUserStatusParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateUserStatus, arg.Status, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const updateUserTOTPSecret = `-- name: UpdateUserTOTPSecret :exec
|
|
UPDATE users SET totp_secret = ? WHERE id = ?
|
|
`
|
|
|
|
type UpdateUserTOTPSecretParams struct {
|
|
TotpSecret *string `json:"totpSecret"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateUserTOTPSecret(ctx context.Context, arg UpdateUserTOTPSecretParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateUserTOTPSecret, arg.TotpSecret, arg.ID)
|
|
return err
|
|
}
|