chore: update latest, add achievements field in works
This commit is contained in:
parent
f0e8f8fa94
commit
6d532aed85
1
bin/run.sh
Executable file
1
bin/run.sh
Executable file
@ -0,0 +1 @@
|
||||
#!/bin/bash
|
6
go.mod
6
go.mod
@ -43,8 +43,8 @@ require (
|
||||
google.golang.org/protobuf v1.27.1 // indirect
|
||||
)
|
||||
|
||||
replace github.com/jesusperez/cfgsrv => ../lib/cfgsrv
|
||||
replace github.com/jesusperez/cfgsrv => ../lib-cfgsrv
|
||||
|
||||
replace github.com/jesusperez/cvdata => ../lib/cvdata
|
||||
replace github.com/jesusperez/cvdata => ../lib-cvdata
|
||||
|
||||
replace github.com/jesusperez/datautils => ../lib/datautils
|
||||
replace github.com/jesusperez/datautils => ../lib-datautils
|
||||
|
56
loads.go
56
loads.go
@ -17,28 +17,28 @@ func loadUsersData(usersPath string) (map[string]Account, error) {
|
||||
}
|
||||
defer file.Close()
|
||||
if err := d.Decode(&usersData); err != nil {
|
||||
log.Fatalf("Decode: %v", err)
|
||||
log.Fatalf("Decode: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
return usersData, nil
|
||||
return usersData, nil
|
||||
}
|
||||
func loadUsersAccounts(usersPath string) (*UsersAccounts, error) {
|
||||
accounts,err := loadUsersData(usersPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
keyAccounts := accounts
|
||||
keyAccounts := accounts
|
||||
for key, user := range accounts {
|
||||
user.Id = key
|
||||
keyAccounts[key] = user
|
||||
if len(user.Email) > 0 {
|
||||
accounts[user.Email] = user
|
||||
accounts[user.Email] = user
|
||||
}
|
||||
}
|
||||
users := &UsersAccounts{
|
||||
Accounts: accounts,
|
||||
}
|
||||
return users, nil
|
||||
return users, nil
|
||||
}
|
||||
func loadWebAccounts(users *UsersAccounts) (*WebAccounts) {
|
||||
webusers := &WebAccounts{}
|
||||
@ -47,7 +47,7 @@ func loadWebAccounts(users *UsersAccounts) (*WebAccounts) {
|
||||
webusers.Accounts[key] = user.Passwd
|
||||
}
|
||||
}
|
||||
return webusers
|
||||
return webusers
|
||||
}
|
||||
func loadModelsUsers(modelsPath string) (map[string]ModelUser, error) {
|
||||
var mdlsUsers map[string]ModelUser
|
||||
@ -57,11 +57,11 @@ func loadModelsUsers(modelsPath string) (map[string]ModelUser, error) {
|
||||
}
|
||||
defer file.Close()
|
||||
if err := d.Decode(&mdlsUsers); err != nil {
|
||||
log.Fatalf("Decode: %v", err)
|
||||
log.Fatalf("Decode: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
// fmt.Printf("users: %+v\n", users)
|
||||
return mdlsUsers, nil
|
||||
return mdlsUsers, nil
|
||||
}
|
||||
func checkUserInvitation(key string,invitation Invitation, num int) (Invitation,bool,bool) {
|
||||
userInvitation := invitation
|
||||
@ -69,23 +69,23 @@ func checkUserInvitation(key string,invitation Invitation, num int) (Invitation,
|
||||
valid := true
|
||||
if invitation.Howmany > -1 && num > 0 {
|
||||
needSync = true
|
||||
userInvitation.Howmany = invitation.Howmany - num
|
||||
userInvitation.Howmany = invitation.Howmany - num
|
||||
if userInvitation.Howmany < 0 {
|
||||
userInvitation.Howmany = 0
|
||||
userInvitation.Active = false
|
||||
userInvitation.Howmany = 0
|
||||
userInvitation.Active = false
|
||||
valid = false
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(invitation.Expire) > 0 {
|
||||
res,err := time.Parse(time.RFC3339,invitation.Expire)
|
||||
if err == nil {
|
||||
if res.Before(time.Now()) {
|
||||
needSync = true
|
||||
userInvitation.Active = false
|
||||
needSync = true
|
||||
userInvitation.Active = false
|
||||
valid = false
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("Error parse invitation %s expire %s: %v",key,invitation.Expire,err)
|
||||
fmt.Printf("Error parse invitation %s expire %s: %v",key,invitation.Expire,err)
|
||||
}
|
||||
}
|
||||
return userInvitation,valid,needSync
|
||||
@ -102,19 +102,19 @@ func checkUsersInvitations(invitations map[string]Invitation,writeSync bool,invi
|
||||
savedInvitations[key] = invitation
|
||||
}
|
||||
if (valid) {
|
||||
usersInvitations[key] = invitation
|
||||
usersInvitations[key] = invitation
|
||||
}
|
||||
}
|
||||
}
|
||||
if (writeSync && needSync) {
|
||||
strdata, yamlerr := yaml.Marshal(savedInvitations)
|
||||
if yamlerr != nil {
|
||||
fmt.Printf("Error parse invitations: %v",yamlerr)
|
||||
} else {
|
||||
if res := utils.WriteData(string(strdata),invitationsPath) ; res != nil {
|
||||
fmt.Printf("Error write invitations: %v",res)
|
||||
strdata, yamlerr := yaml.Marshal(savedInvitations)
|
||||
if yamlerr != nil {
|
||||
fmt.Printf("Error parse invitations: %v",yamlerr)
|
||||
} else {
|
||||
if res := utils.WriteData(string(strdata),invitationsPath) ; res != nil {
|
||||
fmt.Printf("Error write invitations: %v",res)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return usersInvitations
|
||||
}
|
||||
@ -126,7 +126,7 @@ func loadUsersInvitations(invitationsPath string) (map[string]Invitation, error)
|
||||
}
|
||||
defer file.Close()
|
||||
if err := d.Decode(&invitations); err != nil {
|
||||
log.Fatalf("Decode: %v", err)
|
||||
log.Fatalf("Decode: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
return invitations, nil
|
||||
@ -134,10 +134,10 @@ func loadUsersInvitations(invitationsPath string) (map[string]Invitation, error)
|
||||
func getUsersInvitations(invitationsPath string,writeSync bool) (map[string]Invitation, error) {
|
||||
invitations,err := loadUsersInvitations(invitationsPath)
|
||||
if err != nil {
|
||||
fmt.Printf("Error load invitations: %v",err)
|
||||
fmt.Printf("Error load invitations: %v",err)
|
||||
return nil,err
|
||||
}
|
||||
return checkUsersInvitations(invitations,writeSync,invitationsPath), nil
|
||||
return checkUsersInvitations(invitations,writeSync,invitationsPath), nil
|
||||
}
|
||||
func loadConfig(path string) (*cfg.Config, error) {
|
||||
config := &cfg.Config{}
|
||||
@ -168,7 +168,7 @@ func loadConfig(path string) (*cfg.Config, error) {
|
||||
func newDataConfig(runFlags RunFlags) (*cfg.Config, error) {
|
||||
config,err := loadConfig(runFlags.cfgPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Decode: %v", err)
|
||||
log.Fatalf("Decode: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
DEBUGLEVEL = config.DebugLevel
|
||||
@ -179,7 +179,7 @@ func loadDataConfig(runFlags RunFlags) (*cfg.Config, error) {
|
||||
cfg, err := newDataConfig(runFlags)
|
||||
if err != nil {
|
||||
log.Fatalf("Load data config: %v", err)
|
||||
return cfg, err
|
||||
return cfg, err
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
26
models.go
26
models.go
@ -39,10 +39,10 @@ func createRootModels(config *cfg.Config) error {
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
if err != nil {
|
||||
fmt.Printf("Error create %s: %v\n",modelsFullPath, err)
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
var rootModels cvdata.Models
|
||||
rootModels.Models = models
|
||||
data, err := yaml.Marshal(rootModels)
|
||||
@ -51,7 +51,7 @@ func createRootModels(config *cfg.Config) error {
|
||||
return err
|
||||
}
|
||||
dataModelsPath := fmt.Sprintf("%s/%s",config.DataPath,config.DataModelsRoot)
|
||||
if res := utils.WriteData(string(data),dataModelsPath) ; res != nil {
|
||||
if res := utils.WriteData(string(data),dataModelsPath) ; res != nil {
|
||||
fmt.Printf("Error write %s: %v\n", dataModelsPath, err)
|
||||
return res
|
||||
}
|
||||
@ -61,7 +61,7 @@ func createRootModels(config *cfg.Config) error {
|
||||
return err
|
||||
}
|
||||
dataModelsPath = fmt.Sprintf("%s/%s",config.DataDistPath,strings.Replace(config.DataModelsRoot,".yaml",".json",-1))
|
||||
if res := utils.WriteData(string(data),dataModelsPath) ; res != nil {
|
||||
if res := utils.WriteData(string(data),dataModelsPath) ; res != nil {
|
||||
fmt.Printf("Error write %s: %v\n", dataModelsPath, err)
|
||||
return res
|
||||
}
|
||||
@ -73,10 +73,10 @@ func genJsonModels(config *cfg.Config) error {
|
||||
var errgit error
|
||||
var cmd *exec.Cmd
|
||||
if cmd,errgit = utils.GitPull(config.RepoPath,config.RepoName,config.BackgGit,config.QuietGit); errgit != nil {
|
||||
fmt.Printf("Error pull %s (%s): %v\n", config.RepoPath, config.RepoName,errgit)
|
||||
fmt.Printf("Error pull %s (%s): %v\n", config.RepoPath, config.RepoName,errgit)
|
||||
if config.BackgGit {
|
||||
if errgit = cmd.Wait(); errgit != nil {
|
||||
fmt.Printf("Error pull %s (%s): %v\n", config.RepoPath, config.RepoName,errgit)
|
||||
fmt.Printf("Error pull %s (%s): %v\n", config.RepoPath, config.RepoName,errgit)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -89,7 +89,7 @@ func genJsonModels(config *cfg.Config) error {
|
||||
if info.IsDir() {
|
||||
if _, err := os.Stat(fmt.Sprintf("%s/core.yaml",path)); err == nil {
|
||||
if !strings.Contains(path,"lang") {
|
||||
dir := filepath.Base(path)
|
||||
dir := filepath.Base(path)
|
||||
exclude := false
|
||||
for _,itm := range config.GenExcludeList {
|
||||
if itm == dir {
|
||||
@ -103,11 +103,11 @@ func genJsonModels(config *cfg.Config) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
})
|
||||
return err
|
||||
}
|
||||
func makeModelJson(cfg *cfg.Config, modelName string, genPath string, quiet bool, useRepo bool) error {
|
||||
@ -125,10 +125,10 @@ func makeModelJson(cfg *cfg.Config, modelName string, genPath string, quiet bool
|
||||
path := fmt.Sprintf("%s/%s.json",genPath,modelName)
|
||||
if res := utils.WriteData(string(data),path) ; res != nil {
|
||||
fmt.Printf("Error write cv %s: %v\n", modelName, err)
|
||||
return err
|
||||
return err
|
||||
} else {
|
||||
if quiet {
|
||||
fmt.Printf("CV %s writed to: %s\n", modelName,path)
|
||||
fmt.Printf("CV %s writed to: %s\n", modelName,path)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -147,7 +147,7 @@ func gendata(runFlags RunFlags) int {
|
||||
if errModel != nil {
|
||||
return 1
|
||||
}
|
||||
errModel = makeModelJson(cfg, runFlags.modelName, runFlags.genPath,true,true)
|
||||
errModel = makeModelJson(cfg, runFlags.modelName, runFlags.genPath,true,true)
|
||||
if errModel != nil {
|
||||
return 1
|
||||
}
|
||||
|
24
types.go
24
types.go
@ -50,17 +50,17 @@ type Account struct {
|
||||
Id string `yaml:"id"`
|
||||
}
|
||||
type UsersAccounts struct {
|
||||
Accounts map[string]Account `yaml:"accounts"`
|
||||
Accounts map[string]Account `yaml:"accounts"`
|
||||
}
|
||||
type NewUserData struct {
|
||||
Username string `yaml:"username" json:"username"`
|
||||
Passwd string `yaml:"password" json:"password"`
|
||||
Email string `yaml:"email" json:"email"`
|
||||
Email string `yaml:"email" json:"email"`
|
||||
Role string `yaml:"role" json:"role"`
|
||||
Data string `yaml:"data" json:"data"`
|
||||
}
|
||||
}
|
||||
type WebAccounts struct {
|
||||
Accounts gin.Accounts `yaml:"accounts"`
|
||||
Accounts gin.Accounts `yaml:"accounts"`
|
||||
}
|
||||
type Login struct {
|
||||
Username string `form:"username" json:"username" binding:"required"`
|
||||
@ -84,9 +84,9 @@ type ConfigPostData struct {
|
||||
}
|
||||
type LogInfo struct {
|
||||
Run string `yaml:"run" json:"run"`
|
||||
Route string `yaml:"route" json:"route"`
|
||||
Lang string `yaml:"lang" json:"lang"`
|
||||
Agent string `yaml:"agent" json:"agent"`
|
||||
Route string `yaml:"route" json:"route"`
|
||||
Lang string `yaml:"lang" json:"lang"`
|
||||
Agent string `yaml:"agent" json:"agent"`
|
||||
Ip string `yaml:"ip" json:"ip"`
|
||||
Tkn string `yaml:"tkn" json:"tkn"`
|
||||
}
|
||||
@ -114,21 +114,21 @@ type UsersData struct {
|
||||
AuthzPolicy string `yaml:"authzPolicy" json:"authzPolicy"`
|
||||
}
|
||||
type UsersDataPost struct {
|
||||
Id string `yaml:"id" json:"id"`
|
||||
Id string `yaml:"id" json:"id"`
|
||||
Val string `yaml:"val" json:"val"`
|
||||
Data UsersData `yaml:"data" json:"data"`
|
||||
}
|
||||
type UsersRecoveryPost struct {
|
||||
Id string `yaml:"id" json:"id"`
|
||||
Id string `yaml:"id" json:"id"`
|
||||
Val string `yaml:"val" json:"val"`
|
||||
}
|
||||
type UsersRecover struct {
|
||||
Id string `yaml:"id" json:"id"`
|
||||
Data Account `yaml:"data" json:"data"`
|
||||
Id string `yaml:"id" json:"id"`
|
||||
Data Account `yaml:"data" json:"data"`
|
||||
}
|
||||
type SaveDataInfo struct {
|
||||
Title string
|
||||
Data string
|
||||
Data string
|
||||
Id string
|
||||
Path string
|
||||
Prfx string
|
||||
|
Loading…
Reference in New Issue
Block a user