summaryrefslogtreecommitdiff
path: root/internal/storage/sql_provider.go
diff options
context:
space:
mode:
authorAmir Zarrinkafsh <nightah@me.com>2020-05-06 05:35:32 +1000
committerGitHub <noreply@github.com>2020-05-05 21:35:32 +0200
commit1600e0f7da7219e2398fbef68b982d0b466db266 (patch)
tree0726477687703c0953854f7f98f90c39e1f3b8a9 /internal/storage/sql_provider.go
parentc13196a86e267298edb3458d3e47918565e3d139 (diff)
[CI] Add wsl linter (#980)
* [CI] Add wsl linter * Implement wsl recommendations Co-authored-by: Clément Michaud <clement.michaud34@gmail.com>
Diffstat (limited to 'internal/storage/sql_provider.go')
-rw-r--r--internal/storage/sql_provider.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/internal/storage/sql_provider.go b/internal/storage/sql_provider.go
index 993895c8a..f71bcff6d 100644
--- a/internal/storage/sql_provider.go
+++ b/internal/storage/sql_provider.go
@@ -75,21 +75,26 @@ func (p *SQLProvider) initialize(db *sql.DB) error {
return fmt.Errorf("Unable to create table %s: %v", authenticationLogsTableName, err)
}
}
+
return nil
}
// LoadPreferred2FAMethod load the preferred method for 2FA from sqlite db.
func (p *SQLProvider) LoadPreferred2FAMethod(username string) (string, error) {
+ var method string
+
rows, err := p.db.Query(p.sqlGetPreferencesByUsername, username)
if err != nil {
return "", err
}
defer rows.Close()
+
if !rows.Next() {
return "", nil
}
- var method string
+
err = rows.Scan(&method)
+
return method, err
}
@@ -102,10 +107,12 @@ func (p *SQLProvider) SavePreferred2FAMethod(username string, method string) err
// FindIdentityVerificationToken look for an identity verification token in DB.
func (p *SQLProvider) FindIdentityVerificationToken(token string) (bool, error) {
var found bool
+
err := p.db.QueryRow(p.sqlTestIdentityVerificationTokenExistence, token).Scan(&found)
if err != nil {
return false, err
}
+
return found, nil
}
@@ -134,8 +141,10 @@ func (p *SQLProvider) LoadTOTPSecret(username string) (string, error) {
if err == sql.ErrNoRows {
return "", ErrNoTOTPSecret
}
+
return "", err
}
+
return secret, nil
}
@@ -151,6 +160,7 @@ func (p *SQLProvider) SaveU2FDeviceHandle(username string, keyHandle []byte, pub
username,
base64.StdEncoding.EncodeToString(keyHandle),
base64.StdEncoding.EncodeToString(publicKey))
+
return err
}
@@ -161,6 +171,7 @@ func (p *SQLProvider) LoadU2FDeviceHandle(username string) ([]byte, []byte, erro
if err == sql.ErrNoRows {
return nil, nil, ErrNoU2FDeviceHandle
}
+
return nil, nil, err
}
@@ -187,6 +198,8 @@ func (p *SQLProvider) AppendAuthenticationLog(attempt models.AuthenticationAttem
// LoadLatestAuthenticationLogs retrieve the latest marks from the authentication log.
func (p *SQLProvider) LoadLatestAuthenticationLogs(username string, fromDate time.Time) ([]models.AuthenticationAttempt, error) {
+ var t int64
+
rows, err := p.db.Query(p.sqlGetLatestAuthenticationLogs, fromDate.Unix(), username)
if err != nil {
@@ -194,18 +207,20 @@ func (p *SQLProvider) LoadLatestAuthenticationLogs(username string, fromDate tim
}
attempts := make([]models.AuthenticationAttempt, 0, 10)
+
for rows.Next() {
attempt := models.AuthenticationAttempt{
Username: username,
}
- var t int64
err = rows.Scan(&attempt.Successful, &t)
attempt.Time = time.Unix(t, 0)
if err != nil {
return nil, err
}
+
attempts = append(attempts, attempt)
}
+
return attempts, nil
}