Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
SAAS-174 Add password reset method
Browse files Browse the repository at this point in the history
  • Loading branch information
artemgavrilov committed Jul 28, 2020
1 parent f37fcd9 commit c72e4a5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
16 changes: 16 additions & 0 deletions services/platform/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,22 @@ func (s *Service) refreshSession(ctx context.Context) error {
return nil
}

// ResetPassword initiates password reset procedure for user with given email.
func (s *Service) ResetPassword(ctx context.Context, email string) error {
cc, err := dial(ctx, s.host)
if err != nil {
return errors.Wrap(err, "failed establish connection with Percona")
}
defer cc.Close() //nolint:errcheck

_, err = api.NewAuthAPIClient(cc).ResetPassword(ctx, &api.ResetPasswordRequest{Email: email})
if err != nil {
return errors.Wrap(err, "failed to reset password")
}

return nil
}

func dial(ctx context.Context, fullHost string) (*grpc.ClientConn, error) {
host, _, err := net.SplitHostPort(fullHost)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions services/platform/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ func TestPlatformService(t *testing.T) {
err = s.refreshSession(context.Background())
assert.NoError(t, err)
})

t.Run("ResetPassword", func(t *testing.T) {
login := gofakeit.Email()
password := gofakeit.Password(true, true, true, false, false, 14)

err := s.SignUp(context.Background(), login, password)
require.NoError(t, err)

err = s.ResetPassword(context.Background(), login)
assert.NoError(t, err)
})
}

func init() { //nolint:gochecknoinits
Expand Down
1 change: 1 addition & 0 deletions services/server/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@ type telemetryService interface {
type platformService interface {
SignUp(ctx context.Context, email, password string) error
SignIn(ctx context.Context, email, password string) error
ResetPassword(ctx context.Context, email string) error
}
14 changes: 14 additions & 0 deletions services/server/mock_platform_service_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions services/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,17 @@ func (s *Server) PlatformSignIn(ctx context.Context, req *serverpb.PlatformSignI
return &serverpb.PlatformSignInResponse{}, nil
}

// PlatformResetPassword initiates Percona Platform user's password reset procedure.
func (s *Server) PlatformResetPassword(ctx context.Context, req *serverpb.PlatformResetPasswordRequest) (*serverpb.PlatformResetPasswordResponse, error) {
nCtx, cancel := context.WithTimeout(ctx, platformAPITimeout)
defer cancel()
if err := s.platformService.ResetPassword(nCtx, req.Email); err != nil {
return nil, err
}

return &serverpb.PlatformResetPasswordResponse{}, nil
}

// check interfaces
var (
_ serverpb.ServerServer = (*Server)(nil)
Expand Down

0 comments on commit c72e4a5

Please sign in to comment.