Skip to content

Commit

Permalink
fix: update phone admin methods
Browse files Browse the repository at this point in the history
  • Loading branch information
J0 committed Sep 12, 2024
1 parent 7e472ad commit afd4467
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
8 changes: 3 additions & 5 deletions internal/api/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,9 @@ func (a *API) adminUserUpdateFactor(w http.ResponseWriter, r *http.Request) erro
return terr
}
}
if params.FactorType != "" {
if params.FactorType != models.TOTP {
return badRequestError(ErrorCodeValidationFailed, "Factor Type not valid")
}
if terr := factor.UpdateFactorType(tx, params.FactorType); terr != nil {

if params.Phone != "" && factor.IsPhoneFactor() {
if terr := factor.UpdatePhone(tx, params.Phone); terr != nil {
return terr
}
}
Expand Down
12 changes: 6 additions & 6 deletions internal/models/factor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (factorState FactorState) String() string {

const TOTP = "totp"
const Phone = "phone"
const WebAuthn = "webauthn"

type AuthenticationMethod int

Expand Down Expand Up @@ -245,18 +246,17 @@ func (f *Factor) UpdateFriendlyName(tx *storage.Connection, friendlyName string)
return tx.UpdateOnly(f, "friendly_name", "updated_at")
}

func (f *Factor) UpdatePhone(tx *storage.Connection, phone string) error {
f.Phone = phone

Check failure on line 250 in internal/models/factor.go

View workflow job for this annotation

GitHub Actions / test (1.22.x)

cannot use phone (variable of type string) as storage.NullString value in assignment
return tx.UpdateOnly(f, "phone", "updated_at")
}

// UpdateStatus modifies the factor status
func (f *Factor) UpdateStatus(tx *storage.Connection, state FactorState) error {
f.Status = state.String()
return tx.UpdateOnly(f, "status", "updated_at")
}

// UpdateFactorType modifies the factor type
func (f *Factor) UpdateFactorType(tx *storage.Connection, factorType string) error {
f.FactorType = factorType
return tx.UpdateOnly(f, "factor_type", "updated_at")
}

func (f *Factor) DowngradeSessionsToAAL1(tx *storage.Connection) error {
sessions, err := FindSessionsByFactorID(tx, f.ID)
if err != nil {
Expand Down

0 comments on commit afd4467

Please sign in to comment.