Skip to content

Commit

Permalink
option to put emails with constant login codes info cfg (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-cronus authored Aug 21, 2024
1 parent 7e24a55 commit 4569c1b
Show file tree
Hide file tree
Showing 19 changed files with 83 additions and 230 deletions.
3 changes: 3 additions & 0 deletions application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ wintr/connectors/storage/v2: &db
replicaURLs:
- postgresql://root:pass@localhost:5433/eskimo
kyc/social:
welcomeBonusV2Amount: 500
config-json-url: https://somewhere.com/something/somebogus.json
environment: local
enable-alerts: false
Expand Down Expand Up @@ -105,6 +106,8 @@ auth/email-link:
jwtSecret: bogus
confirmationCode:
maxWrongAttemptsCount: 3
constCodes:
[email protected]: 111
petName: Tenanter
appName: Tenant
teamName: Tenant
Expand Down
12 changes: 7 additions & 5 deletions auth/email_link/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const (
loginQueueTTLKey = "login_queue_ttl"
loginRateLimitKey = "login_rate_limit"
initEmailRateLimit = "1000:1m"
loginCodeLength = 3
)

type (
Expand All @@ -116,18 +117,19 @@ type (
LoginSession struct {
JwtSecret string `yaml:"jwtSecret"`
} `yaml:"loginSession"`
ConfirmationCode struct {
ConstCodes map[string]string `yaml:"constCodes" mapstructure:"constCodes"`
MaxWrongAttemptsCount int64 `yaml:"maxWrongAttemptsCount"`
} `yaml:"confirmationCode"`
EmailValidation struct {
AuthLink string `yaml:"authLink"`
ExpirationTime stdlibtime.Duration `yaml:"expirationTime" mapstructure:"expirationTime"`
BlockDuration stdlibtime.Duration `yaml:"blockDuration"`
} `yaml:"emailValidation"`
ConfirmationCode struct {
MaxWrongAttemptsCount int64 `yaml:"maxWrongAttemptsCount"`
} `yaml:"confirmationCode"`
DisableEmailSending bool `yaml:"disableEmailSending"`
QueueProcessing bool `yaml:"queueProcessing"`
QueueAliveTTL stdlibtime.Duration `yaml:"queueAliveTTL" mapstructure:"queueAliveTTL"` //nolint:tagliatelle // .
ExtraLoadBalancersCount int `yaml:"extraLoadBalancersCount"`
DisableEmailSending bool `yaml:"disableEmailSending"`
QueueProcessing bool `yaml:"queueProcessing"`
}
loginID struct {
Email string `json:"email,omitempty" example:"[email protected]"`
Expand Down
2 changes: 1 addition & 1 deletion auth/email_link/email_modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (c *client) handleEmailModification(ctx context.Context, els *emailLinkSign
}
if notifyEmail != "" {
now := time.Now()
resetConfirmationCode := generateConfirmationCode()
resetConfirmationCode := c.generateConfirmationCode("")
uErr := c.upsertEmailLinkSignIn(ctx, oldEmail, els.DeviceUniqueID, resetConfirmationCode, els.Language, now)
if uErr != nil {
return multierror.Append( //nolint:wrapcheck // .
Expand Down
5 changes: 5 additions & 0 deletions auth/email_link/emaillink.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ func NewClient(ctx context.Context, cancel context.CancelFunc, userModifier User
if cfg.QueueProcessing {
go cl.processEmailQueue(ctx)
}
for emailForConstCode, code := range cfg.ConfirmationCode.ConstCodes {
if len(code) > loginCodeLength {
log.Panic(errors.Errorf("const code %v for email %v is too long, max length is %v", code, emailForConstCode, loginCodeLength))
}
}
}
go cl.startOldLoginAttemptsCleaner(ctx)

Expand Down
10 changes: 7 additions & 3 deletions auth/email_link/link_start_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"crypto/rand"
"fmt"
"math"
"math/big"
"sync/atomic"
stdlibtime "time"
Expand Down Expand Up @@ -55,7 +56,7 @@ func (c *client) SendSignInLinkToEmail(ctx context.Context, emailValue, deviceUn
return 0, "", "", errors.Wrapf(vErr, "can't validate modification email for:%#v", oldID)
}
}
confirmationCode := generateConfirmationCode()
confirmationCode := c.generateConfirmationCode(id.Email)
loginSession, err = c.generateLoginSession(&id, clientIP, oldEmail, loginSessionNumber)
if err != nil {
return 0, "", "", errors.Wrap(err, "can't call generateLoginSession")
Expand Down Expand Up @@ -337,8 +338,11 @@ func (c *client) generateLoginSession(id *loginID, clientIP, oldEmail string, lo
return payload, nil
}

func generateConfirmationCode() string {
result, err := rand.Int(rand.Reader, big.NewInt(999)) //nolint:gomnd // It's max value.
func (c *client) generateConfirmationCode(emailForSpecificCode string) string {
if code, hasConstCode := c.cfg.ConfirmationCode.ConstCodes[emailForSpecificCode]; hasConstCode {
return code
}
result, err := rand.Int(rand.Reader, big.NewInt(int64(math.Pow10(loginCodeLength)-1)))
log.Panic(err, "random wrong")

return fmt.Sprintf("%03d", result.Int64()+1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/eskimo-hut/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func validateHiddenProfileElements(req *server.Request[ModifyUserRequestBody, Mo
}
}
if !valid {
invalidHiddenProfileElement = &actual //nolint:revive,exportloopref // Its safe. Its the last iteration.
invalidHiddenProfileElement = &actual //nolint:exportloopref // Its safe. Its the last iteration.

break
}
Expand Down
64 changes: 19 additions & 45 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
module github.com/ice-blockchain/eskimo

go 1.22
go 1.23

require (
dario.cat/mergo v1.0.0
dario.cat/mergo v1.0.1
github.com/PuerkitoBio/goquery v1.9.2
github.com/goccy/go-json v0.10.3
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/google/uuid v1.6.0
github.com/hashicorp/go-multierror v1.1.1
github.com/ice-blockchain/freezer v1.502.0
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb
github.com/ice-blockchain/wintr v1.150.0
github.com/imroc/req/v3 v3.43.7
Expand All @@ -22,74 +21,59 @@ require (
github.com/stretchr/testify v1.9.0
github.com/swaggo/swag v1.16.3
github.com/telegram-mini-apps/init-data-golang v1.1.5
github.com/testcontainers/testcontainers-go v0.32.0
github.com/testcontainers/testcontainers-go v0.33.0
github.com/zeebo/xxh3 v1.0.2
golang.org/x/mod v0.20.0
golang.org/x/net v0.28.0
)

require (
cloud.google.com/go v0.115.0 // indirect
cloud.google.com/go/auth v0.8.0 // indirect
cloud.google.com/go v0.115.1 // indirect
cloud.google.com/go/auth v0.9.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect
cloud.google.com/go/compute/metadata v0.5.0 // indirect
cloud.google.com/go/firestore v1.16.0 // indirect
cloud.google.com/go/iam v1.1.13 // indirect
cloud.google.com/go/longrunning v0.5.12 // indirect
cloud.google.com/go/iam v1.2.0 // indirect
cloud.google.com/go/longrunning v0.6.0 // indirect
cloud.google.com/go/storage v1.43.0 // indirect
firebase.google.com/go/v4 v4.14.1 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/ClickHouse/ch-go v0.62.0 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/MicahParks/keyfunc v1.9.0 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Microsoft/hcsshim v0.12.5 // indirect
github.com/alitto/pond v1.9.1 // indirect
github.com/Microsoft/hcsshim v0.12.6 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.13.0 // indirect
github.com/bsm/redislock v0.9.4 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/bytedance/sonic v1.12.1 // indirect
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudflare/circl v1.3.9 // indirect
github.com/cloudflare/circl v1.4.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.13.0 // indirect
github.com/containerd/cgroups/v3 v3.0.3 // indirect
github.com/containerd/containerd v1.7.20 // indirect
github.com/containerd/continuity v0.4.3 // indirect
github.com/containerd/errdefs v0.1.0 // indirect
github.com/crate-crypto/go-kzg-4844 v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/dennwc/varint v1.0.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/dmarkham/enumer v1.5.10 // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker v27.1.1+incompatible // indirect
github.com/docker/docker v27.1.2+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/ethereum/c-kzg-4844 v1.0.3 // indirect
github.com/ethereum/go-ethereum v1.14.8 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
github.com/georgysavva/scany/v2 v2.1.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.10.0 // indirect
github.com/go-faster/city v1.0.1 // indirect
github.com/go-faster/errors v0.7.1 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
Expand All @@ -99,20 +83,19 @@ require (
github.com/go-playground/validator/v10 v10.22.0 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/goccy/go-reflect v1.2.0 // indirect
github.com/gofrs/flock v0.12.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20231225225746-43d5d4cd4e0e // indirect
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
github.com/google/s2a-go v0.1.8 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/uint256 v1.3.1 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
Expand All @@ -127,7 +110,6 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/moby/sys/mount v0.3.4 // indirect
github.com/moby/sys/mountinfo v0.7.2 // indirect
github.com/moby/term v0.5.0 // indirect
Expand All @@ -139,43 +121,37 @@ require (
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/opencontainers/runc v1.1.13 // indirect
github.com/pascaldekloe/name v1.0.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_golang v1.20.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/quic-go v0.46.0 // indirect
github.com/refraction-networking/utls v1.6.7 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/sagikazarmark/locafero v0.6.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/segmentio/asm v1.2.0 // indirect
github.com/sendgrid/rest v2.6.9+incompatible // indirect
github.com/sendgrid/sendgrid-go v3.15.0+incompatible // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.19.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/supranational/blst v0.3.13 // indirect
github.com/swaggo/files v1.0.1 // indirect
github.com/swaggo/gin-swagger v1.6.0 // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.8.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/twmb/franz-go v1.17.1 // indirect
github.com/twmb/franz-go/pkg/kadm v1.13.0 // indirect
github.com/twmb/franz-go/pkg/kmsg v1.8.0 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
Expand All @@ -185,7 +161,6 @@ require (
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/mock v0.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/arch v0.9.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect
Expand All @@ -195,17 +170,16 @@ require (
golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.6.0 // indirect
golang.org/x/tools v0.24.0 // indirect
google.golang.org/api v0.191.0 // indirect
google.golang.org/api v0.193.0 // indirect
google.golang.org/appengine/v2 v2.0.6 // indirect
google.golang.org/genproto v0.0.0-20240812133136-8ffd90a71988 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240812133136-8ffd90a71988 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240812133136-8ffd90a71988 // indirect
google.golang.org/genproto v0.0.0-20240820151423-278611b39280 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240820151423-278611b39280 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240820151423-278611b39280 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/uint128 v1.3.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

replace (
Expand Down
Loading

0 comments on commit 4569c1b

Please sign in to comment.