feat: my user mfas (#264)

This commit is contained in:
Fabi 2020-06-24 10:47:11 +02:00 committed by GitHub
parent e54778828e
commit f7aed1c864
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 3 deletions

View File

@ -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)
}

View File

@ -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

View File

@ -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) {

View File

@ -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
}
}