fix: support legacy auto ids during registration
This commit is contained in:
@@ -1988,7 +1988,14 @@ func (a *adapter) AuthAddRecord(uid t.Uid, scheme, unique string, authLvl auth.L
|
||||
return err
|
||||
}
|
||||
if _, err := a.db.ExecContext(ctx, "INSERT INTO im_auth(id,userid,authLvl,secret,expires) VALUES(?,?,?,?,?)",
|
||||
authID, store.DecodeUid(uid), authLvl, secret, exp); err != nil {
|
||||
authID, store.DecodeUid(uid), authLvl, secret, exp); isIDOutOfRange(err) {
|
||||
_, err = a.db.ExecContext(ctx, "INSERT INTO im_auth(userid,authLvl,secret,expires) VALUES(?,?,?,?)",
|
||||
store.DecodeUid(uid), authLvl, secret, exp)
|
||||
if err != nil && isDupe(err) {
|
||||
return t.ErrDuplicate
|
||||
}
|
||||
return err
|
||||
} else if err != nil {
|
||||
if isDupe(err) {
|
||||
return t.ErrDuplicate
|
||||
}
|
||||
@@ -2649,6 +2656,12 @@ func createSubscription(tx *sqlx.Tx, sub *t.Subscription, undelete bool) error {
|
||||
"INSERT INTO im_subscriptions(id,createdat,updatedat,deletedat,userid,topic,modeWant,modeGiven,private) "+
|
||||
"VALUES(?,?,?,NULL,?,?,?,?,?)",
|
||||
subID, sub.CreatedAt, sub.UpdatedAt, decoded_uid, sub.Topic, sub.ModeWant.String(), sub.ModeGiven.String(), jpriv)
|
||||
if isIDOutOfRange(err) {
|
||||
_, err = tx.Exec(
|
||||
"INSERT INTO im_subscriptions(createdat,updatedat,deletedat,userid,topic,modeWant,modeGiven,private) "+
|
||||
"VALUES(?,?,NULL,?,?,?,?,?)",
|
||||
sub.CreatedAt, sub.UpdatedAt, decoded_uid, sub.Topic, sub.ModeWant.String(), sub.ModeGiven.String(), jpriv)
|
||||
}
|
||||
|
||||
if err != nil && isDupe(err) {
|
||||
if undelete {
|
||||
@@ -4277,6 +4290,11 @@ func (a *adapter) CredUpsert(cred *t.Credential) (bool, error) {
|
||||
_, err = tx.Exec("INSERT INTO im_credentials(id,createdat,updatedat,method,value,synthetic,userid,resp,done) "+
|
||||
"VALUES(?,?,?,?,?,?,?,?,?)",
|
||||
credID, cred.CreatedAt, cred.UpdatedAt, cred.Method, cred.Value, synth, userId, cred.Resp, cred.Done)
|
||||
if isIDOutOfRange(err) {
|
||||
_, err = tx.Exec("INSERT INTO im_credentials(createdat,updatedat,method,value,synthetic,userid,resp,done) "+
|
||||
"VALUES(?,?,?,?,?,?,?,?)",
|
||||
cred.CreatedAt, cred.UpdatedAt, cred.Method, cred.Value, synth, userId, cred.Resp, cred.Done)
|
||||
}
|
||||
if err != nil {
|
||||
if isDupe(err) {
|
||||
return true, t.ErrDuplicate
|
||||
@@ -5079,6 +5097,14 @@ func isDuplicateColumn(err error) bool {
|
||||
return ok && myerr.Number == 1060
|
||||
}
|
||||
|
||||
func isIDOutOfRange(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
myerr, ok := err.(*ms.MySQLError)
|
||||
return ok && myerr.Number == 1264 && strings.Contains(strings.ToLower(myerr.Message), "id")
|
||||
}
|
||||
|
||||
func mysqlDefaultString(value, fallback string) string {
|
||||
if strings.TrimSpace(value) == "" {
|
||||
return fallback
|
||||
|
||||
Reference in New Issue
Block a user