Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #16 from microservices-demo/registernames
Browse files Browse the repository at this point in the history
added names to register
  • Loading branch information
pidster authored Sep 23, 2016
2 parents e272abf + 841da60 commit f5af6b3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions api/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func MakeLoginEndpoint(s Service) endpoint.Endpoint {
func MakeRegisterEndpoint(s Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (response interface{}, err error) {
req := request.(registerRequest)
id, err := s.Register(req.Username, req.Password, req.Email)
id, err := s.Register(req.Username, req.Password, req.Email, req.FirstName, req.LastName)
return postResponse{ID: id}, err
}
}
Expand Down Expand Up @@ -204,9 +204,11 @@ type cardsResponse struct {
}

type registerRequest struct {
Username string `json:"username"`
Password string `json:"password"`
Email string `json:"email"`
Username string `json:"username"`
Password string `json:"password"`
Email string `json:"email"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
}

type statusResponse struct {
Expand Down
4 changes: 2 additions & 2 deletions api/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (mw loggingMiddleware) Login(username, password string) (user users.User, e
return mw.next.Login(username, password)
}

func (mw loggingMiddleware) Register(username, password, email string) (string, error) {
func (mw loggingMiddleware) Register(username, password, email, first, last string) (string, error) {
defer func(begin time.Time) {
mw.logger.Log(
"method", "Register",
Expand All @@ -44,7 +44,7 @@ func (mw loggingMiddleware) Register(username, password, email string) (string,
"took", time.Since(begin),
)
}(time.Now())
return mw.next.Register(username, password, email)
return mw.next.Register(username, password, email, first, last)
}

func (mw loggingMiddleware) PostUser(user users.User) (id string, err error) {
Expand Down
6 changes: 4 additions & 2 deletions api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
// Service is the user service, providing operations for users to login, register, and retrieve customer information.
type Service interface {
Login(username, password string) (users.User, error) // GET /login
Register(username, password, email string) (string, error)
Register(username, password, email, first, last string) (string, error)
GetUsers(id string) ([]users.User, error)
PostUser(u users.User) (string, error)
GetAddresses(id string) ([]users.Address, error)
Expand Down Expand Up @@ -51,11 +51,13 @@ func (s *fixedService) Login(username, password string) (users.User, error) {

}

func (s *fixedService) Register(username, password, email string) (string, error) {
func (s *fixedService) Register(username, password, email, first, last string) (string, error) {
u := users.New()
u.Username = username
u.Password = calculatePassHash(password, u.Salt)
u.Email = email
u.FirstName = first
u.LastName = last
err := db.CreateUser(&u)
return u.UserID, err
}
Expand Down

0 comments on commit f5af6b3

Please sign in to comment.