tsk-19: Service login (#23)
Closes #19 Reviewed-on: phoenix/textsender-auth#23 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
type ServiceStore interface {
|
||||
CheckWithUsername(ctx context.Context, username string) (bool, error)
|
||||
GetWithUsername(ctx context.Context, username string) (*user.ServiceUser, error)
|
||||
Create(ctx context.Context, serviceUser *user.ServiceUser) error
|
||||
}
|
||||
|
||||
@@ -37,6 +38,21 @@ func (s *PGServiceStore) CheckWithUsername(ctx context.Context, username string)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PGServiceStore) GetWithUsername(ctx context.Context, username string) (*user.ServiceUser, error) {
|
||||
var serviceUser user.ServiceUser
|
||||
query := `SELECT id, username, passphrase, created FROM service_users WHERE username = $1`
|
||||
|
||||
if err := s.db.QueryRow(ctx, query, username).Scan(&serviceUser.Id, &serviceUser.Username, &serviceUser.Passphrase, &serviceUser.Created); err != nil {
|
||||
if err == pgx.ErrNoRows {
|
||||
return nil, nil
|
||||
} else {
|
||||
return nil, fmt.Errorf("Error querying row: %v", err)
|
||||
}
|
||||
} else {
|
||||
return &serviceUser, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PGServiceStore) Create(ctx context.Context, serviceUser *user.ServiceUser) error {
|
||||
query := `
|
||||
INSERT INTO service_users (username, passphrase)
|
||||
|
||||
Reference in New Issue
Block a user