Add kycinfo for attendance table ane related utils
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -30,7 +30,8 @@ email:
|
|||||||
secrets:
|
secrets:
|
||||||
jwt_secret: example
|
jwt_secret: example
|
||||||
turnstile_secret: example
|
turnstile_secret: example
|
||||||
client_secret_key: example
|
client_secret_key: aes_32_byte_string
|
||||||
|
kyc_info_key: aes_32_byte_string
|
||||||
ttl:
|
ttl:
|
||||||
auth_code_ttl: 10m
|
auth_code_ttl: 10m
|
||||||
access_ttl: 15s
|
access_ttl: 15s
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ type secrets struct {
|
|||||||
JwtSecret string `yaml:"jwt_secret"`
|
JwtSecret string `yaml:"jwt_secret"`
|
||||||
TurnstileSecret string `yaml:"turnstile_secret"`
|
TurnstileSecret string `yaml:"turnstile_secret"`
|
||||||
ClientSecretKey string `yaml:"client_secret_key"`
|
ClientSecretKey string `yaml:"client_secret_key"`
|
||||||
|
KycInfoKey string `yaml:"kyc_info_key"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ttl struct {
|
type ttl struct {
|
||||||
|
|||||||
13
data/agenda.go
Normal file
13
data/agenda.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package data
|
||||||
|
|
||||||
|
import "github.com/google/uuid"
|
||||||
|
|
||||||
|
type Agenda struct {
|
||||||
|
Id uint `json:"id" gorm:"primarykey;autoIncrement"`
|
||||||
|
UUID uuid.UUID `json:"uuid" gorm:"type:uuid;uniqueIndex;not null"`
|
||||||
|
AgendaId uuid.UUID `json:"agenda_id" gorm:"type:uuid;uniqueIndex;not null"`
|
||||||
|
EventId uuid.UUID `json:"event_id" gorm:"type:uuid;uniqueIndex:unique_event_user;not null"`
|
||||||
|
UserId uuid.UUID `json:"user_id" gorm:"type:uuid;uniqueIndex:unique_event_user;not null"`
|
||||||
|
Name string `json:"name" gorm:"type:varchar(255);not null"`
|
||||||
|
Description string `json:"description" gorm:"type:text;not null"`
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ type Attendance struct {
|
|||||||
EventId uuid.UUID `json:"event_id" gorm:"type:uuid;uniqueIndex:unique_event_user;not null"`
|
EventId uuid.UUID `json:"event_id" gorm:"type:uuid;uniqueIndex:unique_event_user;not null"`
|
||||||
UserId uuid.UUID `json:"user_id" gorm:"type:uuid;uniqueIndex:unique_event_user;not null"`
|
UserId uuid.UUID `json:"user_id" gorm:"type:uuid;uniqueIndex:unique_event_user;not null"`
|
||||||
Role string `json:"role" gorm:"type:varchar(255);not null"`
|
Role string `json:"role" gorm:"type:varchar(255);not null"`
|
||||||
|
KycInfo string `json:"kyc_info" gorm:"type:text"`
|
||||||
CheckinAt time.Time `json:"checkin_at"`
|
CheckinAt time.Time `json:"checkin_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
50
pkgs/kyc/kyc.go
Normal file
50
pkgs/kyc/kyc.go
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package kyc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"nixcn-cms/internal/cryptography"
|
||||||
|
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
func EncodeB64Json(b64Json string) (*string, error) {
|
||||||
|
rawJson, err := base64.StdEncoding.DecodeString(b64Json)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("invalid base64 json")
|
||||||
|
}
|
||||||
|
|
||||||
|
var kyc KycInfo
|
||||||
|
if err := json.Unmarshal(rawJson, &kyc); err != nil {
|
||||||
|
return nil, errors.New("invalid json structure")
|
||||||
|
}
|
||||||
|
|
||||||
|
plainJson, err := json.Marshal(kyc)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
aesKey := viper.GetString("secrets.kyc_info_key")
|
||||||
|
encrypted, err := cryptography.AESCBCEncrypt(plainJson, []byte(aesKey))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &encrypted, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DecodeAES(cipherStr string) (*KycInfo, error) {
|
||||||
|
aesKey := viper.GetString("secrets.kyc_info_key")
|
||||||
|
plainBytes, err := cryptography.AESCBCDecrypt(cipherStr, []byte(aesKey))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var kyc KycInfo
|
||||||
|
if err := json.Unmarshal(plainBytes, &kyc); err != nil {
|
||||||
|
return nil, errors.New("invalid decrypted json")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &kyc, nil
|
||||||
|
}
|
||||||
7
pkgs/kyc/types.go
Normal file
7
pkgs/kyc/types.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package kyc
|
||||||
|
|
||||||
|
type KycInfo struct {
|
||||||
|
Type string `json:"type"` // Chinese / Foreigner
|
||||||
|
LegalName string `json:"legal_name"`
|
||||||
|
ResidentId string `json:"rsident_id"`
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user