Skip to content

Commit

Permalink
Do not delete user on verification email error (#1736)
Browse files Browse the repository at this point in the history
  • Loading branch information
qube authored and ndegory committed Oct 26, 2017
1 parent f5a766f commit b0763f9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 23 deletions.
23 changes: 2 additions & 21 deletions api/rpc/account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ func (s *Server) SignUp(ctx context.Context, in *SignUpRequest) (*empty.Empty, e
// Create user
user, err := s.Accounts.CreateUser(ctx, in.Name, in.Email, in.Password)
if err != nil {
log.Errorf("User creation failed (%s)", in.Name)
if errd := s.Accounts.DeleteNotVerifiedUser(ctx, in.Name); errd != nil {
log.Infof("User deletion also failed (%s)", in.Name)
}
return nil, convertError(err)
}

Expand All @@ -123,37 +119,22 @@ func (s *Server) SignUp(ctx context.Context, in *SignUpRequest) (*empty.Empty, e
}
return nil, convertError(err)
}
log.Infoln("Successfully created user", user.Name)

switch s.Config.Registration {
case configuration.RegistrationEmail:
if user.Email == "" {
log.Errorf("Fail to send verification notification to user %s, no email set", user.Name)
if errd := s.Accounts.DeleteNotVerifiedUser(ctx, user.Name); errd != nil {
log.Errorf("Fail to delete user %s", user.Name)
} else {
log.Infof("user %s has been deleted", user.Name)
}
return nil, convertError(fmt.Errorf("unable to send email to %s, there's no email set for this user", user.Name))
}
// Create a verification token valid for an hour
token, err := s.Tokens.CreateVerificationToken(user.Name)
if err != nil {
if errd := s.Accounts.DeleteNotVerifiedUser(ctx, user.Name); errd != nil {
return nil, convertError(fmt.Errorf("user deletion error [%v] after a VerificationToken error [%v]", errd, err))
}
return nil, convertError(err)
}

// Send the verification email
if err := s.Mailer.SendAccountVerificationEmail(user.Email, user.Name, token, in.Url); err != nil {
if errd := s.Accounts.DeleteNotVerifiedUser(ctx, user.Name); errd != nil {
return nil, convertError(fmt.Errorf("Delete user error [%v] comming after SendAccountVerificationEmail error [%v]", errd, err))
}
return nil, err
return nil, convertError(err)
}
log.Infof("Verification email sent to %s (%s)", user.Email, user.Name)
}
log.Infoln("Successfully created user", user.Name)
return &empty.Empty{}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/amplifier/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func main() {
DockerURL: docker.DefaultURL,
DockerVersion: docker.DefaultVersion,
Registration: configuration.RegistrationDefault,
Notifications: true,
Notifications: configuration.NotificationsDefault,
}

// Override with configuration file
Expand Down
3 changes: 2 additions & 1 deletion data/accounts/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (s *Store) CreateUser(ctx context.Context, name string, email string, passw
return nil, EmailAlreadyUsed
}

// Check if organization with the same name already exists.
// Check if an organization with the same name already exists.
orgAlreadyExists, err := s.GetOrganization(ctx, name)
if err != nil {
return nil, err
Expand Down Expand Up @@ -247,6 +247,7 @@ func (s *Store) CreateUser(ctx context.Context, name string, email string, passw
return nil, err
}
if err := s.storage.Create(ctx, path.Join(usersRootKey, name), user, nil, 0); err != nil {
s.storage.Delete(ctx, path.Join(usersRootKey, name), false, nil)
return nil, err
}
return user, nil
Expand Down

0 comments on commit b0763f9

Please sign in to comment.