Skip to content

Commit

Permalink
Merge branch 'master' into openshift_4_16_regserv
Browse files Browse the repository at this point in the history
  • Loading branch information
ranakan19 authored Jan 31, 2025
2 parents 49804fe + 280e4ec commit d660a53
Show file tree
Hide file tree
Showing 17 changed files with 341 additions and 729 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
require (
github.com/aws/aws-sdk-go v1.44.100
github.com/codeready-toolchain/api v0.0.0-20250121053759-af12adf8e938
github.com/codeready-toolchain/toolchain-common v0.0.0-20250121053752-f7e2c17c3c6b
github.com/codeready-toolchain/toolchain-common v0.0.0-20250127073039-8ef21eb833fa
github.com/go-logr/logr v1.4.1
github.com/gofrs/uuid v4.2.0+incompatible
github.com/pkg/errors v0.9.1
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtM
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/codeready-toolchain/toolchain-common v0.0.0-20250121053752-f7e2c17c3c6b h1:AjguQB0pvRBaArWMs6pzdKu0IimYcfK4MIpM+vwf8us=
github.com/codeready-toolchain/toolchain-common v0.0.0-20250121053752-f7e2c17c3c6b/go.mod h1:YAvlMiumFFmUR8A3eF5TDjyn1KyhKbpdwCMdLKtupGA=
github.com/codeready-toolchain/api v0.0.0-20250121053759-af12adf8e938 h1:cj2H8bhNTjHVMUJnPEpLW8nLV9YMnG2nQ3oTgMJWsbI=
github.com/codeready-toolchain/api v0.0.0-20250121053759-af12adf8e938/go.mod h1:2KYfJlFwZtiKfa5QDhQfXTFh6RyALilURWBXyfKmKso=
github.com/codeready-toolchain/toolchain-common v0.0.0-20250127073039-8ef21eb833fa h1:75flfyrKUpq8Ppi/BRSaAUdBGD9wtWMDvL3kYqSRt1s=
github.com/codeready-toolchain/toolchain-common v0.0.0-20250127073039-8ef21eb833fa/go.mod h1:YAvlMiumFFmUR8A3eF5TDjyn1KyhKbpdwCMdLKtupGA=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
11 changes: 5 additions & 6 deletions pkg/application/service/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import (

type SignupService interface {
Signup(ctx *gin.Context) (*toolchainv1alpha1.UserSignup, error)
GetSignup(ctx *gin.Context, userID, username string, checkUserSignupCompleted bool) (*signup.Signup, error)
GetUserSignupFromIdentifier(userID, username string) (*toolchainv1alpha1.UserSignup, error)
PhoneNumberAlreadyInUse(userID, username, phoneNumberOrHash string) error
GetSignup(ctx *gin.Context, username string, checkUserSignupCompleted bool) (*signup.Signup, error)
PhoneNumberAlreadyInUse(username, phoneNumberOrHash string) error
}

type VerificationService interface {
InitVerification(ctx *gin.Context, userID, username, e164PhoneNumber, countryCode string) error
VerifyPhoneCode(ctx *gin.Context, userID, username, code string) error
VerifyActivationCode(ctx *gin.Context, userID, username, code string) error
InitVerification(ctx *gin.Context, username, e164PhoneNumber, countryCode string) error
VerifyPhoneCode(ctx *gin.Context, username, code string) error
VerifyActivationCode(ctx *gin.Context, username, code string) error
}

type Services interface {
Expand Down
20 changes: 8 additions & 12 deletions pkg/controller/signup.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func (s *Signup) PostHandler(ctx *gin.Context) {
// invokes the Verification service with an E.164 formatted phone number value derived from the country code and phone number
// provided by the user.
func (s *Signup) InitVerificationHandler(ctx *gin.Context) {
userID := ctx.GetString(context.SubKey)
username := ctx.GetString(context.UsernameKey)

// Read the Body content
Expand All @@ -87,9 +86,9 @@ func (s *Signup) InitVerificationHandler(ctx *gin.Context) {
}

e164Number := phonenumbers.Format(number, phonenumbers.E164)
err = s.app.VerificationService().InitVerification(ctx, userID, username, e164Number, strconv.Itoa(countryCode))
err = s.app.VerificationService().InitVerification(ctx, username, e164Number, strconv.Itoa(countryCode))
if err != nil {
log.Errorf(ctx, err, "Verification for %s could not be sent", userID)
log.Errorf(ctx, err, "Verification for %s could not be sent", username)
e := &crterrors.Error{}
switch {
case errors.As(err, &e):
Expand All @@ -100,24 +99,23 @@ func (s *Signup) InitVerificationHandler(ctx *gin.Context) {
return
}

log.Infof(ctx, "phone verification has been sent for userID %s", userID)
log.Infof(ctx, "phone verification has been sent for username %s", username)
ctx.Status(http.StatusNoContent)
ctx.Writer.WriteHeaderNow()
}

// GetHandler returns the Signup resource
func (s *Signup) GetHandler(ctx *gin.Context) {

// Get the UserSignup resource from the service by the userID
userID := ctx.GetString(context.SubKey)
// Get the UserSignup resource from the service by the username
username := ctx.GetString(context.UsernameKey)
signupResource, err := s.app.SignupService().GetSignup(ctx, userID, username, true)
signupResource, err := s.app.SignupService().GetSignup(ctx, username, true)
if err != nil {
log.Error(ctx, err, "error getting UserSignup resource")
crterrors.AbortWithError(ctx, http.StatusInternalServerError, err, "error getting UserSignup resource")
}
if signupResource == nil {
log.Infof(ctx, "UserSignup resource for userID: %s, username: %s resource not found", userID, username)
log.Infof(ctx, "UserSignup resource for username '%s' resource not found", username)
ctx.AbortWithStatus(http.StatusNotFound)
} else {
ctx.JSON(http.StatusOK, signupResource)
Expand All @@ -134,10 +132,9 @@ func (s *Signup) VerifyPhoneCodeHandler(ctx *gin.Context) {
return
}

userID := ctx.GetString(context.SubKey)
username := ctx.GetString(context.UsernameKey)

err := s.app.VerificationService().VerifyPhoneCode(ctx, userID, username, code)
err := s.app.VerificationService().VerifyPhoneCode(ctx, username, code)
if err != nil {
e := &crterrors.Error{}
switch {
Expand Down Expand Up @@ -167,10 +164,9 @@ func (s *Signup) VerifyActivationCodeHandler(ctx *gin.Context) {
return
}

userID := ctx.GetString(context.SubKey)
username := ctx.GetString(context.UsernameKey)

err := s.app.VerificationService().VerifyActivationCode(ctx, userID, username, code)
err := s.app.VerificationService().VerifyActivationCode(ctx, username, code)
if err != nil {
log.Error(ctx, err, "error validating activation code")
e := &crterrors.Error{}
Expand Down
Loading

0 comments on commit d660a53

Please sign in to comment.