append sessionid to the gdbm file

This commit is contained in:
Carlosokumu 2024-09-03 15:07:49 +03:00
parent 0c360c0cc4
commit fee51edade
Signed by: carlos
GPG Key ID: 7BD6BC8160A5C953
2 changed files with 12 additions and 8 deletions

View File

@ -107,7 +107,7 @@ func main() {
fp := path.Join(dp, sessionId) fp := path.Join(dp, sessionId)
ussdHandlers, err := ussd.NewHandlers(fp, &st) ussdHandlers, err := ussd.NewHandlers(fp, &st,sessionId)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "handler setup failed with error: %v\n", err) fmt.Fprintf(os.Stderr, "handler setup failed with error: %v\n", err)

View File

@ -24,7 +24,7 @@ import (
var ( var (
scriptDir = path.Join("services", "registration") scriptDir = path.Join("services", "registration")
translationDir = path.Join(scriptDir, "locale") translationDir = path.Join(scriptDir, "locale")
dbFile = path.Join(scriptDir, "vise.gdbm") //dbFile = path.Join(scriptDir, "userdata.gdbm")
) )
const ( const (
@ -65,8 +65,9 @@ type Handlers struct {
accountService server.AccountServiceInterface accountService server.AccountServiceInterface
} }
func NewHandlers(dir string, st *state.State) (*Handlers, error) { func NewHandlers(dir string, st *state.State, sessionId string) (*Handlers, error) {
db, err := gdbm.Open(dbFile, gdbm.ModeWrcreat) filename := path.Join(scriptDir, sessionId+"_userdata.gdbm")
db, err := gdbm.Open(filename, gdbm.ModeWrcreat)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -425,9 +426,12 @@ func (h *Handlers) Authorize(ctx context.Context, sym string, input []byte) (res
res.FlagReset = append(res.FlagReset, flags["flag_account_authorized"]) res.FlagReset = append(res.FlagReset, flags["flag_account_authorized"])
return res, nil return res, nil
} }
} else {
res.FlagSet = append(res.FlagSet, flags["flag_incorrect_pin"])
res.FlagReset = append(res.FlagReset, flags["flag_account_authorized"])
} }
} else if errors.Is(err, gdbm.ErrItemNotFound) { } else if errors.Is(err, gdbm.ErrItemNotFound) {
//PIN not set yet return res, err
} else { } else {
return res, err return res, err
} }