diff options
| author | James Elliott <james-d-elliott@users.noreply.github.com> | 2022-03-28 12:26:30 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-28 12:26:30 +1100 |
| commit | 70ab8aab155149ac1c870fe6a3a9cd9fbe47b78f (patch) | |
| tree | 1709066b37a64fb7ba55c5cd616f541381b71105 /internal/storage/sql_provider.go | |
| parent | 2d8978c15a3d50df5e3c597efe51456271225bd2 (diff) | |
fix(web): show appropriate default and available methods (#2999)
This ensures that; the method set when a user does not have a preference is a method that is available, that if a user has a preferred method that is not available it is changed to an enabled method with preference put on methods the user has configured, that the frontend does not show the method selection option when only one method is available.
Diffstat (limited to 'internal/storage/sql_provider.go')
| -rw-r--r-- | internal/storage/sql_provider.go | 15 |
1 files changed, 2 insertions, 13 deletions
diff --git a/internal/storage/sql_provider.go b/internal/storage/sql_provider.go index 7e4922a2f..126c4ddb1 100644 --- a/internal/storage/sql_provider.go +++ b/internal/storage/sql_provider.go @@ -11,7 +11,6 @@ import ( "github.com/jmoiron/sqlx" "github.com/sirupsen/logrus" - "github.com/authelia/authelia/v4/internal/authentication" "github.com/authelia/authelia/v4/internal/configuration/schema" "github.com/authelia/authelia/v4/internal/logging" "github.com/authelia/authelia/v4/internal/model" @@ -205,7 +204,7 @@ func (p *SQLProvider) LoadPreferred2FAMethod(ctx context.Context, username strin case err == nil: return method, nil case errors.Is(err, sql.ErrNoRows): - return "", nil + return "", sql.ErrNoRows default: return "", fmt.Errorf("error selecting preferred two factor method for user '%s': %w", username, err) } @@ -216,17 +215,7 @@ func (p *SQLProvider) LoadUserInfo(ctx context.Context, username string) (info m err = p.db.GetContext(ctx, &info, p.sqlSelectUserInfo, username, username, username, username) switch { - case err == nil: - return info, nil - case errors.Is(err, sql.ErrNoRows): - if _, err = p.db.ExecContext(ctx, p.sqlUpsertPreferred2FAMethod, username, authentication.PossibleMethods[0]); err != nil { - return model.UserInfo{}, fmt.Errorf("error upserting preferred two factor method while selecting user info for user '%s': %w", username, err) - } - - if err = p.db.GetContext(ctx, &info, p.sqlSelectUserInfo, username, username, username, username); err != nil { - return model.UserInfo{}, fmt.Errorf("error selecting user info for user '%s': %w", username, err) - } - + case err == nil, errors.Is(err, sql.ErrNoRows): return info, nil default: return model.UserInfo{}, fmt.Errorf("error selecting user info for user '%s': %w", username, err) |
