polished up TOTP enrolment
This commit is contained in:
parent
d2ac66a81a
commit
b91b6e7ce0
7 changed files with 81 additions and 31 deletions
|
@ -78,7 +78,7 @@ func GetTOTPsForAccount(db *sqlx.DB, accountID string) ([]model.TOTP, error) {
|
|||
err := db.Select(
|
||||
&totps,
|
||||
"SELECT * FROM totp " +
|
||||
"WHERE account=$1 " +
|
||||
"WHERE account=$1 AND confirmed=true " +
|
||||
"ORDER BY created_at ASC",
|
||||
accountID,
|
||||
)
|
||||
|
@ -130,6 +130,15 @@ func GetTOTP(db *sqlx.DB, accountID string, name string) (*model.TOTP, error) {
|
|||
return &totp, nil
|
||||
}
|
||||
|
||||
func ConfirmTOTP(db *sqlx.DB, accountID string, name string) error {
|
||||
_, err := db.Exec(
|
||||
"UPDATE totp SET confirmed=true WHERE account=$1 AND name=$2",
|
||||
accountID,
|
||||
name,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
func CreateTOTP(db *sqlx.DB, totp *model.TOTP) error {
|
||||
_, err := db.Exec(
|
||||
"INSERT INTO totp (account, name, secret) " +
|
||||
|
@ -149,3 +158,8 @@ func DeleteTOTP(db *sqlx.DB, accountID string, name string) error {
|
|||
)
|
||||
return err
|
||||
}
|
||||
|
||||
func DeleteUnconfirmedTOTPs(db *sqlx.DB) error {
|
||||
_, err := db.Exec("DELETE FROM totp WHERE confirmed=false")
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue