Files
story/internal/onboarding/operator_login.go
T

59 lines
1.6 KiB
Go
Raw Normal View History

package onboarding
import (
"context"
"net/http"
)
// Each view is a request-local value. Pools and immutable configuration are
// shared; customer and operator credentials, sessions and cookies are separate.
func (s *Service) operatorView() *Service {
view := *s
view.operatorLogin = true
return &view
}
func (s *Service) loginSessionTable() string {
if s.operatorLogin {
return "operator_login_session"
}
return "customer_login_session"
}
func (s *Service) loginSMSTable() string {
if s.operatorLogin {
return "operator_sms_challenge"
}
return "customer_sms_challenge"
}
func (s *Service) phoneCredentialTable() string {
if s.operatorLogin {
return "operator_phone_credential"
}
return "customer_phone_credential"
}
func (s *Service) accountSessionTable() string {
if s.operatorLogin {
return "operator_account_session"
}
return "onboarding_account_session"
}
func (s *Service) accountPredicate() string {
if s.operatorLogin {
return "ua.account_kind='operator' AND ua.platform_role IN ('ops_admin','ops_operator','ops_approver','ops_viewer')"
}
return "ua.account_kind='customer' AND ua.platform_role='customer'"
}
func (s *Service) logoutKinds() []bool {
if s.operatorLogin {
return []bool{true}
}
return []bool{true, false}
}
func (s *Service) OperatorAuth(next http.Handler) http.Handler {
return s.operatorView().CustomerAuth(next)
}
func (s *Service) ProvisionOperatorPhone(ctx context.Context, userID, issuer, subject, phone, password, requestID string) (bool, error) {
return s.operatorView().provisionPhone(ctx, userID, issuer, subject, phone, password, requestID)
}