mirror of
https://github.com/zitadel/zitadel.git
synced 2025-01-06 13:37:40 +00:00
feat: my user mfas (#264)
This commit is contained in:
parent
e54778828e
commit
f7aed1c864
@ -170,6 +170,10 @@ func (repo *UserRepo) ChangePassword(ctx context.Context, userID, old, new strin
|
||||
return err
|
||||
}
|
||||
|
||||
func (repo *UserRepo) MyUserMfas(ctx context.Context) ([]*model.MultiFactor, error) {
|
||||
return repo.View.UserMfas(auth.GetCtxData(ctx).UserID)
|
||||
}
|
||||
|
||||
func (repo *UserRepo) AddMfaOTP(ctx context.Context, userID string) (*model.OTP, error) {
|
||||
return repo.UserEvents.AddOTP(ctx, userID)
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ type myUserRepo interface {
|
||||
|
||||
ChangeMyPassword(ctx context.Context, old, new string) error
|
||||
|
||||
MyUserMfas(ctx context.Context) ([]*model.MultiFactor, error)
|
||||
AddMyMfaOTP(ctx context.Context) (*model.OTP, error)
|
||||
VerifyMyMfaOTPSetup(ctx context.Context, code string) error
|
||||
RemoveMyMfaOTP(ctx context.Context) error
|
||||
|
@ -4,8 +4,6 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
)
|
||||
|
||||
func (s *Server) GetMyUser(ctx context.Context, _ *empty.Empty) (*UserView, error) {
|
||||
@ -49,7 +47,11 @@ func (s *Server) GetMyUserAddress(ctx context.Context, _ *empty.Empty) (*UserAdd
|
||||
}
|
||||
|
||||
func (s *Server) GetMyMfas(ctx context.Context, _ *empty.Empty) (*MultiFactors, error) {
|
||||
return nil, errors.ThrowUnimplemented(nil, "GRPC-vkl9i", "Not implemented")
|
||||
mfas, err := s.repo.MyUserMfas(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &MultiFactors{Mfas: mfasFromModel(mfas)}, nil
|
||||
}
|
||||
|
||||
func (s *Server) UpdateMyUserProfile(ctx context.Context, request *UpdateUserProfileRequest) (*UserProfile, error) {
|
||||
|
@ -309,3 +309,29 @@ func mfaStateFromModel(state usr_model.MfaState) MFAState {
|
||||
return MFAState_MFASTATE_UNSPECIFIED
|
||||
}
|
||||
}
|
||||
|
||||
func mfasFromModel(mfas []*usr_model.MultiFactor) []*MultiFactor {
|
||||
converted := make([]*MultiFactor, len(mfas))
|
||||
for i, mfa := range mfas {
|
||||
converted[i] = mfaFromModel(mfa)
|
||||
}
|
||||
return converted
|
||||
}
|
||||
|
||||
func mfaFromModel(mfa *usr_model.MultiFactor) *MultiFactor {
|
||||
return &MultiFactor{
|
||||
State: mfaStateFromModel(mfa.State),
|
||||
Type: mfaTypeFromModel(mfa.Type),
|
||||
}
|
||||
}
|
||||
|
||||
func mfaTypeFromModel(mfatype usr_model.MfaType) MfaType {
|
||||
switch mfatype {
|
||||
case usr_model.MfaTypeOTP:
|
||||
return MfaType_MFATYPE_OTP
|
||||
case usr_model.MfaTypeSMS:
|
||||
return MfaType_MFATYPE_SMS
|
||||
default:
|
||||
return MfaType_MFATYPE_UNSPECIFIED
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user