Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ayaanqui committed Apr 29, 2024
1 parent 40541ed commit 45abbd5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 23 deletions.
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ go 1.21

require (
github.com/99designs/gqlgen v0.17.44
github.com/cloudinary/cloudinary-go/v2 v2.7.0
github.com/go-chi/chi/v5 v5.0.12
github.com/go-jet/jet/v2 v2.11.0
github.com/ory/dockertest/v3 v3.10.0
github.com/sendgrid/rest v2.6.9+incompatible
github.com/sendgrid/sendgrid-go v3.14.0+incompatible
github.com/vektah/gqlparser/v2 v2.5.11
golang.org/x/crypto v0.21.0
)
Expand All @@ -18,7 +21,6 @@ require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cloudinary/cloudinary-go/v2 v2.7.0 // indirect
github.com/containerd/continuity v0.4.3 // indirect
github.com/creasty/defaults v1.5.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down Expand Up @@ -59,10 +61,9 @@ require (
github.com/opencontainers/runc v1.1.12 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sendgrid/rest v2.6.9+incompatible // indirect
github.com/sendgrid/sendgrid-go v3.14.0+incompatible // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/thanhpk/randstr v1.0.6 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
Expand Down Expand Up @@ -94,7 +95,7 @@ require (
github.com/go-playground/validator/v10 v10.18.0
github.com/gohugoio/hugo v0.111.3 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/google/uuid v1.6.0 // indirect
github.com/google/uuid v1.6.0
github.com/lib/pq v1.10.9
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ github.com/tdewolff/parse/v2 v2.6.5 h1:lYvWBk55GkqKl0JJenGpmrgu/cPHQQ6/Mm1hBGswo
github.com/tdewolff/parse/v2 v2.6.5/go.mod h1:woz0cgbLwFdtbjJu8PIKxhW05KplTFQkOdX78o+Jgrs=
github.com/tdewolff/test v1.0.7 h1:8Vs0142DmPFW/bQeHRP3MV19m1gvndjUb1sn8yy74LM=
github.com/tdewolff/test v1.0.7/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE=
github.com/thanhpk/randstr v1.0.6 h1:psAOktJFD4vV9NEVb3qkhRSMvYh4ORRaj1+w/hn4B+o=
github.com/thanhpk/randstr v1.0.6/go.mod h1:M/H2P1eNLZzlDwAzpkkkUvoyNNMbzRGhESZuEQk3r0U=
github.com/urfave/cli v1.22.12 h1:igJgVw1JdKH+trcLWLeLwZjU9fEfPesQ+9/e4MQ44S8=
github.com/urfave/cli v1.22.12/go.mod h1:sSBEIC79qR6OvcmsD4U3KABeOTxDqQtdDnaFuUN30b8=
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
Expand Down
6 changes: 2 additions & 4 deletions services/user_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/stadio-app/stadio-backend/graph/gmodel"
"github.com/stadio-app/stadio-backend/types"
"github.com/stadio-app/stadio-backend/utils"
"github.com/thanhpk/randstr"
"golang.org/x/crypto/bcrypt"
"google.golang.org/api/googleapi"
"google.golang.org/api/oauth2/v2"
Expand Down Expand Up @@ -236,10 +237,7 @@ func (service Service) CreateAuthState(ctx context.Context, user gmodel.User, au
}

func (service Service) CreateEmailVerification(ctx context.Context, user gmodel.User) (model.EmailVerification, error) {
code, code_err := utils.GenerateRandomUrlEncodedString(EMAIL_VERIFICATION_CODE_LEN)
if code_err != nil {
return model.EmailVerification{}, code_err
}
code := randstr.String(EMAIL_VERIFICATION_CODE_LEN)

query := table.EmailVerification.INSERT(
table.EmailVerification.UserID,
Expand Down
15 changes: 0 additions & 15 deletions utils/strings.go
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
package utils

import (
"crypto/rand"
"encoding/base64"
)

// Generate random string URL encoded
func GenerateRandomUrlEncodedString(length int) (string, error) {
buffer := make([]byte, length)
_, err := rand.Read(buffer)
if err != nil {
return "", err
}
return base64.URLEncoding.EncodeToString(buffer)[:length], nil
}

0 comments on commit 45abbd5

Please sign in to comment.