Commit 4b3627bba5221a97582397b8b4ccfb0edd51d2d1

Authored by Marko Tikvić
1 parent 67337ffa8f
Exists in master and in 1 other branch v2

added role ID to the credentials struct

Showing 2 changed files with 10 additions and 6 deletions   Show diff stats
... ... @@ -40,6 +40,7 @@ type TokenClaims struct {
40 40 type CredentialsStruct struct {
41 41 Username string `json:"username"`
42 42 Password string `json:"password"`
  43 + RoleID uint32 `json:"roleID"`
43 44 }
44 45  
45 46 // ValidateCredentials hashes pass and salt and returns comparison result with resultHash
... ...
... ... @@ -88,7 +88,11 @@ func QueEntityModelUpdate(entityType string, v interface{}) {
88 88 updateQue[entityType], _ = json.Marshal(v)
89 89 }
90 90  
91   -func UpdateEntityModels(forceUpdate bool) (total, upd, add int, err error) {
  91 +func UpdateEntityModels(command string) (total, upd, add int, err error) {
  92 + if command != "force" && command != "missing" {
  93 + return total, 0, 0, errors.New("uknown command: " + command)
  94 + }
  95 +
92 96 if !inited {
93 97 return 0, 0, 0, errors.New("webutil: metadata not initialized but update was tried.")
94 98 }
... ... @@ -100,7 +104,7 @@ func UpdateEntityModels(forceUpdate bool) (total, upd, add int, err error) {
100 104  
101 105 for k, _ := range updateQue {
102 106 if _, exists := metadata[k]; exists {
103   - if forceUpdate {
  107 + if command == "force" {
104 108 forUpdate = append(forUpdate, k)
105 109 }
106 110 } else {
... ... @@ -109,8 +113,6 @@ func UpdateEntityModels(forceUpdate bool) (total, upd, add int, err error) {
109 113 }
110 114  
111 115 for _, k := range forUpdate {
112   - fmt.Printf("for update: %s\n", k)
113   -
114 116 _, err := metadataDB.PrepAndExe(`update entities set
115 117 entity_model = :1
116 118 where entity_type = :2`,
... ... @@ -122,12 +124,11 @@ func UpdateEntityModels(forceUpdate bool) (total, upd, add int, err error) {
122 124 continue
123 125 }
124 126 upd++
  127 + fmt.Printf("webutility: updated %s payload model\n", k)
125 128 }
126 129  
127 130 blankPayload, _ := json.Marshal(Payload{})
128 131 for _, k := range forAdd {
129   - fmt.Printf("for add: %s\n", k)
130   -
131 132 _, err := metadataDB.PrepAndExe(`insert into entities
132 133 (projekat, metadata, entity_type, entity_model)
133 134 values(:1, :2, :3, :4)`,
... ... @@ -142,6 +143,8 @@ func UpdateEntityModels(forceUpdate bool) (total, upd, add int, err error) {
142 143 }
143 144 metadata[k] = Payload{}
144 145 add++
  146 + fmt.Printf("webutility: added %s to the payload models\n", k)
  147 +
145 148 }
146 149  
147 150 return total, upd, add, nil
... ...