2024-09-02 22:54:03 +01:00
|
|
|
// Code generated by sqlc. DO NOT EDIT.
|
|
|
|
// versions:
|
|
|
|
// sqlc v1.25.0
|
|
|
|
// source: otp.sql
|
|
|
|
|
|
|
|
package database
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
|
|
|
const deleteOtp = `-- name: DeleteOtp :exec
|
2024-10-05 21:08:02 +01:00
|
|
|
UPDATE users
|
|
|
|
SET otp_secret='',
|
|
|
|
otp_digits=0
|
|
|
|
WHERE subject = ?
|
2024-09-02 22:54:03 +01:00
|
|
|
`
|
|
|
|
|
2024-10-05 21:08:02 +01:00
|
|
|
func (q *Queries) DeleteOtp(ctx context.Context, subject string) error {
|
2024-09-02 22:54:03 +01:00
|
|
|
_, err := q.db.ExecContext(ctx, deleteOtp, subject)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
const getOtp = `-- name: GetOtp :one
|
2024-10-05 21:08:02 +01:00
|
|
|
SELECT otp_secret, otp_digits
|
|
|
|
FROM users
|
2024-09-02 22:54:03 +01:00
|
|
|
WHERE subject = ?
|
|
|
|
`
|
|
|
|
|
|
|
|
type GetOtpRow struct {
|
2024-10-05 21:08:02 +01:00
|
|
|
OtpSecret string `json:"otp_secret"`
|
|
|
|
OtpDigits int64 `json:"otp_digits"`
|
2024-09-02 22:54:03 +01:00
|
|
|
}
|
|
|
|
|
2024-10-05 21:08:02 +01:00
|
|
|
func (q *Queries) GetOtp(ctx context.Context, subject string) (GetOtpRow, error) {
|
2024-09-02 22:54:03 +01:00
|
|
|
row := q.db.QueryRowContext(ctx, getOtp, subject)
|
|
|
|
var i GetOtpRow
|
2024-10-05 21:08:02 +01:00
|
|
|
err := row.Scan(&i.OtpSecret, &i.OtpDigits)
|
2024-09-02 22:54:03 +01:00
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const getUserEmail = `-- name: GetUserEmail :one
|
|
|
|
SELECT email
|
|
|
|
FROM users
|
|
|
|
WHERE subject = ?
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) GetUserEmail(ctx context.Context, subject string) (string, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, getUserEmail, subject)
|
|
|
|
var email string
|
|
|
|
err := row.Scan(&email)
|
|
|
|
return email, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const hasOtp = `-- name: HasOtp :one
|
2024-10-05 21:08:02 +01:00
|
|
|
SELECT CAST(1 AS BOOLEAN) AS hasOtp
|
|
|
|
FROM users
|
|
|
|
WHERE subject = ?
|
|
|
|
AND otp_secret != ''
|
2024-09-02 22:54:03 +01:00
|
|
|
`
|
|
|
|
|
2024-10-05 21:08:02 +01:00
|
|
|
func (q *Queries) HasOtp(ctx context.Context, subject string) (bool, error) {
|
2024-09-02 22:54:03 +01:00
|
|
|
row := q.db.QueryRowContext(ctx, hasOtp, subject)
|
|
|
|
var hasotp bool
|
|
|
|
err := row.Scan(&hasotp)
|
|
|
|
return hasotp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const setOtp = `-- name: SetOtp :exec
|
2024-10-05 21:08:02 +01:00
|
|
|
UPDATE users
|
|
|
|
SET otp_secret = ?,
|
|
|
|
otp_digits=?
|
|
|
|
WHERE subject = ?
|
2024-09-02 22:54:03 +01:00
|
|
|
`
|
|
|
|
|
|
|
|
type SetOtpParams struct {
|
2024-10-05 21:08:02 +01:00
|
|
|
OtpSecret string `json:"otp_secret"`
|
|
|
|
OtpDigits int64 `json:"otp_digits"`
|
|
|
|
Subject string `json:"subject"`
|
2024-09-02 22:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) SetOtp(ctx context.Context, arg SetOtpParams) error {
|
2024-10-05 21:08:02 +01:00
|
|
|
_, err := q.db.ExecContext(ctx, setOtp, arg.OtpSecret, arg.OtpDigits, arg.Subject)
|
2024-09-02 22:54:03 +01:00
|
|
|
return err
|
|
|
|
}
|