forked from urdt/ussd
add check for unregistered phone numbers
This commit is contained in:
parent
106983a394
commit
d0ad6395b5
@ -748,15 +748,35 @@ func (h *Handlers) FetchCustodialBalances(ctx context.Context, sym string, input
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Handlers) ResetUnregisteredNumber(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
|
var res resource.Result
|
||||||
|
flag_unregistered_number, _ := h.flagManager.GetFlag("flag_unregistered_number")
|
||||||
|
res.FlagReset = append(res.FlagReset, flag_unregistered_number)
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Handlers) ValidateBlockedNumber(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *Handlers) ValidateBlockedNumber(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
flag_unregistered_number, _ := h.flagManager.GetFlag("flag_unregistered_number")
|
||||||
|
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
sessionId, ok := ctx.Value("SessionId").(string)
|
sessionId, ok := ctx.Value("SessionId").(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
}
|
}
|
||||||
blockedNumber := string(input)
|
blockedNumber := string(input)
|
||||||
|
_, err = store.ReadEntry(ctx, blockedNumber, utils.DATA_PUBLIC_KEY)
|
||||||
|
if err != nil {
|
||||||
|
if db.IsNotFound(err) {
|
||||||
|
logg.Printf(logging.LVL_INFO, "Invalid or unregistered number")
|
||||||
|
res.FlagSet = append(res.FlagSet, flag_unregistered_number)
|
||||||
|
return res, nil
|
||||||
|
} else {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
}
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_BLOCKED_NUMBER, []byte(blockedNumber))
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_BLOCKED_NUMBER, []byte(blockedNumber))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, nil
|
return res, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user