|
|
|
@@ -8,6 +8,7 @@ import (
|
|
|
|
|
"path"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
"unicode"
|
|
|
|
|
|
|
|
|
|
"gopkg.in/leonelquinteros/gotext.v1"
|
|
|
|
|
|
|
|
|
@@ -242,6 +243,28 @@ func (h *MenuHandlers) CreateAccount(ctx context.Context, sym string, input []by
|
|
|
|
|
return res, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *MenuHandlers) CheckAccountCreated(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
|
|
|
|
var res resource.Result
|
|
|
|
|
flag_account_created, _ := h.flagManager.GetFlag("flag_account_created")
|
|
|
|
|
|
|
|
|
|
store := h.userdataStore
|
|
|
|
|
|
|
|
|
|
sessionId, ok := ctx.Value("SessionId").(string)
|
|
|
|
|
if !ok {
|
|
|
|
|
return res, fmt.Errorf("missing session")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := store.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if !db.IsNotFound(err) {
|
|
|
|
|
return res, err
|
|
|
|
|
}
|
|
|
|
|
return res, nil
|
|
|
|
|
}
|
|
|
|
|
res.FlagSet = append(res.FlagSet, flag_account_created)
|
|
|
|
|
return res, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ResetValidPin resets the flag_valid_pin flag.
|
|
|
|
|
func (h *MenuHandlers) ResetValidPin(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
|
|
|
|
var res resource.Result
|
|
|
|
@@ -1121,7 +1144,12 @@ func (h *MenuHandlers) GetCurrentProfileInfo(ctx context.Context, sym string, in
|
|
|
|
|
logg.ErrorCtxf(ctx, "Failed to read account alias entry with", "key", "error", storedb.DATA_ACCOUNT_ALIAS, err)
|
|
|
|
|
return res, err
|
|
|
|
|
}
|
|
|
|
|
res.Content = string(profileInfo)
|
|
|
|
|
alias := string(profileInfo)
|
|
|
|
|
if alias == "" {
|
|
|
|
|
res.Content = defaultValue
|
|
|
|
|
} else {
|
|
|
|
|
res.Content = alias
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
@@ -1165,8 +1193,10 @@ func (h *MenuHandlers) GetProfileInfo(ctx context.Context, sym string, input []b
|
|
|
|
|
offerings := getEntryOrDefault(store.ReadEntry(ctx, sessionId, storedb.DATA_OFFERINGS))
|
|
|
|
|
alias := getEntryOrDefault(store.ReadEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS))
|
|
|
|
|
|
|
|
|
|
if alias != defaultValue {
|
|
|
|
|
if alias != defaultValue && alias != "" {
|
|
|
|
|
alias = strings.Split(alias, ".")[0]
|
|
|
|
|
} else {
|
|
|
|
|
alias = defaultValue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Construct the full name
|
|
|
|
@@ -1247,20 +1277,10 @@ func (h *MenuHandlers) UpdateAllProfileItems(ctx context.Context, sym string, in
|
|
|
|
|
if !ok {
|
|
|
|
|
return res, fmt.Errorf("missing session")
|
|
|
|
|
}
|
|
|
|
|
flag_alias_set, _ := h.flagManager.GetFlag("flag_alias_set")
|
|
|
|
|
aliasSet := h.st.MatchFlag(flag_alias_set, true)
|
|
|
|
|
|
|
|
|
|
err := h.insertProfileItems(ctx, sessionId, &res)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return res, err
|
|
|
|
|
}
|
|
|
|
|
//Only request an alias if it has not been set yet:
|
|
|
|
|
if !aliasSet {
|
|
|
|
|
err = h.constructAccountAlias(ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return res, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -2083,6 +2103,7 @@ func (h *MenuHandlers) CheckVouchers(ctx context.Context, sym string, input []by
|
|
|
|
|
|
|
|
|
|
// Write data entries
|
|
|
|
|
for key, value := range dataMap {
|
|
|
|
|
logg.InfoCtxf(ctx, "Writing data entry for sessionId: %s", sessionId, "key", key, "value", value)
|
|
|
|
|
if err := userStore.WriteEntry(ctx, sessionId, key, []byte(value)); err != nil {
|
|
|
|
|
logg.ErrorCtxf(ctx, "Failed to write data entry for sessionId: %s", sessionId, "key", key, "error", err)
|
|
|
|
|
continue
|
|
|
|
@@ -2110,6 +2131,7 @@ func (h *MenuHandlers) GetVoucherList(ctx context.Context, sym string, input []b
|
|
|
|
|
|
|
|
|
|
// Read vouchers from the store
|
|
|
|
|
voucherData, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_VOUCHER_SYMBOLS)
|
|
|
|
|
logg.InfoCtxf(ctx, "reading GetVoucherList entries for sessionId: %s", sessionId, "key", storedb.DATA_VOUCHER_SYMBOLS, "voucherData", voucherData)
|
|
|
|
|
if err != nil {
|
|
|
|
|
logg.ErrorCtxf(ctx, "failed to read voucherData entires with", "key", storedb.DATA_VOUCHER_SYMBOLS, "error", err)
|
|
|
|
|
return res, err
|
|
|
|
@@ -2122,6 +2144,8 @@ func (h *MenuHandlers) GetVoucherList(ctx context.Context, sym string, input []b
|
|
|
|
|
|
|
|
|
|
formattedData := h.ReplaceSeparatorFunc(string(voucherData))
|
|
|
|
|
|
|
|
|
|
logg.InfoCtxf(ctx, "final output for sessionId: %s", sessionId, "key", storedb.DATA_VOUCHER_SYMBOLS, "formattedData", formattedData)
|
|
|
|
|
|
|
|
|
|
res.Content = string(formattedData)
|
|
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
@@ -2508,7 +2532,8 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
|
|
|
|
|
return res, nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
aliasResult, err := h.accountService.RequestAlias(ctx, string(pubKey), string(input))
|
|
|
|
|
sanitizedInput := sanitizeAliasHint(string(input))
|
|
|
|
|
aliasResult, err := h.accountService.RequestAlias(ctx, string(pubKey), sanitizedInput)
|
|
|
|
|
if err != nil {
|
|
|
|
|
logg.ErrorCtxf(ctx, "failed to retrieve alias", "alias", string(aliasHint), "error_alias_request", err)
|
|
|
|
|
return res, fmt.Errorf("Failed to retrieve alias: %s", err.Error())
|
|
|
|
@@ -2525,6 +2550,17 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
|
|
|
|
|
return res, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func sanitizeAliasHint(input string) string {
|
|
|
|
|
for i, r := range input {
|
|
|
|
|
// Check if the character is a special character (non-alphanumeric)
|
|
|
|
|
if !unicode.IsLetter(r) && !unicode.IsNumber(r) {
|
|
|
|
|
return input[:i]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// If no special character is found, return the whole input
|
|
|
|
|
return input
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetSuggestedAlias loads and displays the suggested alias name from the temporary value
|
|
|
|
|
func (h *MenuHandlers) GetSuggestedAlias(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
|
|
|
|
var res resource.Result
|
|
|
|
|