Compare commits

..

3 Commits

3 changed files with 21 additions and 15 deletions

View File

@ -1222,7 +1222,8 @@ func (h *MenuHandlers) ResetAccountAuthorized(ctx context.Context, sym string, i
return res, nil return res, nil
} }
// CheckIdentifier retrieves the PublicKey from the JSON data file. // CheckIdentifier retrieves the Public key from the userdatastore under the key: DATA_PUBLIC_KEY and triggers an sms that
// will be sent to the associated session id
func (h *MenuHandlers) CheckIdentifier(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (h *MenuHandlers) CheckIdentifier(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result var res resource.Result
sessionId, ok := ctx.Value("SessionId").(string) sessionId, ok := ctx.Value("SessionId").(string)
@ -1230,9 +1231,18 @@ func (h *MenuHandlers) CheckIdentifier(ctx context.Context, sym string, input []
return res, fmt.Errorf("missing session") return res, fmt.Errorf("missing session")
} }
store := h.userdataStore store := h.userdataStore
publicKey, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY) publicKey, err := store.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY)
if err != nil {
logg.ErrorCtxf(ctx, "failed to read publicKey entry with", "key", storedb.DATA_PUBLIC_KEY, "error", err)
return res, err
}
res.Content = string(publicKey) res.Content = string(publicKey)
//trigger an address sms to be delivered to the associated session id
err = h.sendAddressSMS(ctx)
if err != nil {
logg.DebugCtxf(ctx, "Failed to trigger an address sms", "error", err)
return res, nil
}
return res, nil return res, nil
} }
@ -2501,36 +2511,35 @@ func (h *MenuHandlers) ClearTemporaryValue(ctx context.Context, sym string, inpu
} }
// SendAddressSMS will triger an SMS when a user navigates to the my address node.The SMS will be sent to the associated phonenumber. // SendAddressSMS will triger an SMS when a user navigates to the my address node.The SMS will be sent to the associated phonenumber.
func (h *MenuHandlers) SendAddressSMS(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (h *MenuHandlers) sendAddressSMS(ctx context.Context) error {
var res resource.Result
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 fmt.Errorf("missing session")
} }
publicKey, err := store.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY) publicKey, err := store.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY)
if err != nil { if err != nil {
logg.ErrorCtxf(ctx, "failed to read publicKey entry with", "key", storedb.DATA_PUBLIC_KEY, "error", err) logg.ErrorCtxf(ctx, "failed to read publicKey entry with", "key", storedb.DATA_PUBLIC_KEY, "error", err)
return res, err return err
} }
originPhone, err := phone.FormatPhoneNumber(sessionId) originPhone, err := phone.FormatPhoneNumber(sessionId)
if err != nil { if err != nil {
logg.DebugCtxf(ctx, "Failed to format origin phonenumber", "sessionid", sessionId) logg.DebugCtxf(ctx, "Failed to format origin phonenumber", "sessionid", sessionId)
return res, nil return nil
} }
if !phone.IsValidPhoneNumber(originPhone) { if !phone.IsValidPhoneNumber(originPhone) {
logg.InfoCtxf(ctx, "Invalid origin phone number", "sessionid:", sessionId) logg.InfoCtxf(ctx, "Invalid origin phone number", "origin phonenumber", originPhone)
return res, nil return fmt.Errorf("invalid origin phone number")
} }
err = h.accountService.SendAddressSMS(ctx, string(publicKey), sessionId) err = h.accountService.SendAddressSMS(ctx, string(publicKey), sessionId)
if err != nil { if err != nil {
logg.DebugCtxf(ctx, "Failed to send address sms", "error", err) logg.DebugCtxf(ctx, "Failed to send address sms", "error", err)
return res, nil return fmt.Errorf("Failed to send address sms: %v", err)
} }
return res, nil return nil
} }
// sendPINResetSMS will send an SMS to a user's phonenumber in the event that the associated account's PIN has been reset. // sendPINResetSMS will send an SMS to a user's phonenumber in the event that the associated account's PIN has been reset.

View File

@ -124,7 +124,6 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
ls.DbRs.AddLocalFunc("get_suggested_alias", appHandlers.GetSuggestedAlias) ls.DbRs.AddLocalFunc("get_suggested_alias", appHandlers.GetSuggestedAlias)
ls.DbRs.AddLocalFunc("confirm_new_alias", appHandlers.ConfirmNewAlias) ls.DbRs.AddLocalFunc("confirm_new_alias", appHandlers.ConfirmNewAlias)
ls.DbRs.AddLocalFunc("check_account_created", appHandlers.CheckAccountCreated) ls.DbRs.AddLocalFunc("check_account_created", appHandlers.CheckAccountCreated)
ls.DbRs.AddLocalFunc("send_address_sms", appHandlers.SendAddressSMS)
ls.first = appHandlers.Init ls.first = appHandlers.Init

View File

@ -1,6 +1,4 @@
LOAD send_address_sms 16
LOAD check_identifier 0 LOAD check_identifier 0
RELOAD check_identifier
MAP check_identifier MAP check_identifier
MOUT back 0 MOUT back 0
MOUT quit 9 MOUT quit 9