mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-25 07:20:44 +00:00
allow dynamic type of user accounts
This commit is contained in:
1 parent
87f664048b
commit
3f9cb1136a
18 files changed
+123
-49
No files matched your search
@@ -2,30 +2,28 @@
|
||||
|
||||
package protocol
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/v2ray/v2ray-core/common/uuid"
|
||||
)
|
||||
import "encoding/json"
|
||||
|
||||
func (u *User) UnmarshalJSON(data []byte) error {
|
||||
type rawUser struct {
|
||||
IdString string `json:"id"`
|
||||
EmailString string `json:"email"`
|
||||
LevelByte byte `json:"level"`
|
||||
AlterIdCount uint16 `json:"alterId"`
|
||||
EmailString string `json:"email"`
|
||||
LevelByte byte `json:"level"`
|
||||
}
|
||||
var rawUserValue rawUser
|
||||
if err := json.Unmarshal(data, &rawUserValue); err != nil {
|
||||
return err
|
||||
}
|
||||
id, err := uuid.ParseString(rawUserValue.IdString)
|
||||
|
||||
var rawAccount AccountJson
|
||||
if err := json.Unmarshal(data, &rawAccount); err != nil {
|
||||
return err
|
||||
}
|
||||
account, err := rawAccount.GetAccount()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
primaryID := NewID(id)
|
||||
alterIDs := NewAlterIDs(primaryID, rawUserValue.AlterIdCount)
|
||||
*u = *NewUser(primaryID, alterIDs, UserLevel(rawUserValue.LevelByte), rawUserValue.EmailString)
|
||||
|
||||
*u = *NewUser(account, UserLevel(rawUserValue.LevelByte), rawUserValue.EmailString)
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user