mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 11:34:26 +00:00
ef012d0081
* feat: add phone change and code verification for user v2 api * feat: add phone change and code verification for user v2 api * fix: add ignored phone.proto * fix: integration tests * Update proto/zitadel/user/v2alpha/user_service.proto * Update idp_template.go --------- Co-authored-by: Livio Spring <livio.a@gmail.com>
62 lines
2.0 KiB
Go
62 lines
2.0 KiB
Go
package user
|
|
|
|
import (
|
|
"context"
|
|
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
caos_errs "github.com/zitadel/zitadel/internal/errors"
|
|
object "github.com/zitadel/zitadel/pkg/grpc/object/v2alpha"
|
|
user "github.com/zitadel/zitadel/pkg/grpc/user/v2alpha"
|
|
)
|
|
|
|
func (s *Server) SetPhone(ctx context.Context, req *user.SetPhoneRequest) (resp *user.SetPhoneResponse, err error) {
|
|
var resourceOwner string // TODO: check if still needed
|
|
var phone *domain.Phone
|
|
|
|
switch v := req.GetVerification().(type) {
|
|
case *user.SetPhoneRequest_SendCode:
|
|
phone, err = s.command.ChangeUserPhone(ctx, req.GetUserId(), resourceOwner, req.GetPhone(), s.userCodeAlg)
|
|
case *user.SetPhoneRequest_ReturnCode:
|
|
phone, err = s.command.ChangeUserPhoneReturnCode(ctx, req.GetUserId(), resourceOwner, req.GetPhone(), s.userCodeAlg)
|
|
case *user.SetPhoneRequest_IsVerified:
|
|
phone, err = s.command.ChangeUserPhoneVerified(ctx, req.GetUserId(), resourceOwner, req.GetPhone())
|
|
case nil:
|
|
phone, err = s.command.ChangeUserPhone(ctx, req.GetUserId(), resourceOwner, req.GetPhone(), s.userCodeAlg)
|
|
default:
|
|
err = caos_errs.ThrowUnimplementedf(nil, "USERv2-Ahng0", "verification oneOf %T in method SetPhone not implemented", v)
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &user.SetPhoneResponse{
|
|
Details: &object.Details{
|
|
Sequence: phone.Sequence,
|
|
ChangeDate: timestamppb.New(phone.ChangeDate),
|
|
ResourceOwner: phone.ResourceOwner,
|
|
},
|
|
VerificationCode: phone.PlainCode,
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) VerifyPhone(ctx context.Context, req *user.VerifyPhoneRequest) (*user.VerifyPhoneResponse, error) {
|
|
details, err := s.command.VerifyUserPhone(ctx,
|
|
req.GetUserId(),
|
|
"", // TODO: check if still needed
|
|
req.GetVerificationCode(),
|
|
s.userCodeAlg,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &user.VerifyPhoneResponse{
|
|
Details: &object.Details{
|
|
Sequence: details.Sequence,
|
|
ChangeDate: timestamppb.New(details.EventDate),
|
|
ResourceOwner: details.ResourceOwner,
|
|
},
|
|
}, nil
|
|
}
|