Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix revalidate query #329

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Fixed
- Invalid amount of arguments in query scan when e-mail revalidation is disabled

## [0.13.0] - 2023-08-10
### Added
- E-mail address revalidation, addressing issues where user's e-mail addresses can be (temporary) invalid
Expand Down
11 changes: 9 additions & 2 deletions server/keyshare/myirmaserver/postgresdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func (db *postgresDB) verifyLoginToken(ctx context.Context, token, username stri

func (db *postgresDB) user(ctx context.Context, id int64) (user, error) {
var result user
revalidation := db.db.EmailRevalidation(ctx)

// fetch username
err := db.db.QueryUserContext(ctx, "SELECT username, language, (coredata IS NULL) AS delete_in_progress FROM irma.users WHERE id = $1",
Expand All @@ -188,7 +189,7 @@ func (db *postgresDB) user(ctx context.Context, id int64) (user, error) {

query := "SELECT email, (delete_on IS NOT NULL) AS delete_in_progress {{revalidate}} FROM irma.emails WHERE user_id = $1 AND (delete_on >= $2 OR delete_on IS NULL)"

if db.db.EmailRevalidation(ctx) {
if revalidation {
query = strings.ReplaceAll(query, "{{revalidate}}", ", (revalidate_on IS NOT NULL) AS revalidate_in_progress")
} else {
query = strings.ReplaceAll(query, "{{revalidate}}", "")
Expand All @@ -200,7 +201,13 @@ func (db *postgresDB) user(ctx context.Context, id int64) (user, error) {
query,
func(rows *sql.Rows) error {
var email userEmail
err = rows.Scan(&email.Email, &email.DeleteInProgress, &email.RevalidateInProgress)

if revalidation {
err = rows.Scan(&email.Email, &email.DeleteInProgress, &email.RevalidateInProgress)
} else {
err = rows.Scan(&email.Email, &email.DeleteInProgress)
}

result.Emails = append(result.Emails, email)
return err
},
Expand Down