fix: remove tenant dependency from member login
This commit is contained in:
@@ -95,11 +95,11 @@ func (s *Store) RegisterAccount(ctx context.Context, input AccountRegistration)
|
||||
InviteCode: input.InviteCode, MemberStatus: memberStatusActive, MemberCategory: memberCategoryReal}, nil
|
||||
}
|
||||
|
||||
func (s *Store) AccountByMobile(ctx context.Context, tenantID int64, mobile string) (*Account, error) {
|
||||
func (s *Store) AccountByMobile(ctx context.Context, mobile string) (*Account, error) {
|
||||
if s == nil || s.db == nil {
|
||||
return nil, errors.New("store is unavailable")
|
||||
}
|
||||
return accountByMobile(ctx, s.db, tenantID, mobile)
|
||||
return accountByMobile(ctx, s.db, mobile)
|
||||
}
|
||||
|
||||
func (s *Store) RecordLogin(ctx context.Context, tenantID, memberID int64) error {
|
||||
@@ -112,11 +112,11 @@ type queryer interface {
|
||||
GetContext(context.Context, any, string, ...any) error
|
||||
}
|
||||
|
||||
func accountByMobile(ctx context.Context, db queryer, tenantID int64, mobile string) (*Account, error) {
|
||||
func accountByMobile(ctx context.Context, db queryer, mobile string) (*Account, error) {
|
||||
var row Account
|
||||
err := db.GetContext(ctx, &row, `SELECT tenant_id, id AS member_id, member_no, username, mobile,
|
||||
password_hash, invite_code, member_status, risk_status AS member_category
|
||||
FROM hg_app_member WHERE tenant_id=? AND mobile=? AND deleted_at IS NULL LIMIT 1`, tenantID, mobile)
|
||||
FROM hg_app_member WHERE mobile=? AND deleted_at IS NULL LIMIT 1`, mobile)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, ErrInvalidCredentials
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type accountQueryRecorder struct {
|
||||
query string
|
||||
args []any
|
||||
}
|
||||
|
||||
func (r *accountQueryRecorder) GetContext(_ context.Context, dest any, query string, args ...any) error {
|
||||
r.query = query
|
||||
r.args = args
|
||||
account := dest.(*Account)
|
||||
*account = Account{MemberID: 9, Mobile: "13311111111", MemberStatus: memberStatusActive}
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestAccountByMobileDoesNotFilterTenant(t *testing.T) {
|
||||
recorder := &accountQueryRecorder{}
|
||||
account, err := accountByMobile(context.Background(), recorder, "13311111111")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if account.MemberID != 9 {
|
||||
t.Fatalf("MemberID = %d, want 9", account.MemberID)
|
||||
}
|
||||
if strings.Contains(strings.ToLower(recorder.query), "tenant_id=?") {
|
||||
t.Fatalf("query must not filter tenant: %s", recorder.query)
|
||||
}
|
||||
if len(recorder.args) != 1 || recorder.args[0] != "13311111111" {
|
||||
t.Fatalf("query args = %#v", recorder.args)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user