diff --git a/modules/backend/src/main/scala/services/data/DataServiceError.scala b/modules/backend/src/main/scala/services/data/DataServiceError.scala index e7fe9d66a..c762e1bf1 100644 --- a/modules/backend/src/main/scala/services/data/DataServiceError.scala +++ b/modules/backend/src/main/scala/services/data/DataServiceError.scala @@ -72,8 +72,6 @@ case class ItemNotFound( def this(id: String) = this(Some("id"), Some(id)) } -case class ServerError(error: String) extends RuntimeException(error) with DataServiceError - case class CriticalError(error: String) extends RuntimeException(error) with DataServiceError case class BadJson( diff --git a/modules/portal/app/controllers/portal/account/Accounts.scala b/modules/portal/app/controllers/portal/account/Accounts.scala index bc913e66a..392ea09b4 100644 --- a/modules/portal/app/controllers/portal/account/Accounts.scala +++ b/modules/portal/app/controllers/portal/account/Accounts.scala @@ -5,9 +5,9 @@ import auth.oauth2.{OAuth2Config, UserData} import auth.sso.{DiscourseSSO, DiscourseSSOError, DiscourseSSONotEnabledError} import auth.{AuthenticationError, HashedPassword} import com.google.common.net.HttpHeaders -import controllers.{AppComponents, renderError} import controllers.base.RecaptchaHelper import controllers.portal.base.PortalController +import controllers.{AppComponents, renderError} import forms.{AccountForms, HoneyPotForm, TimeCheckForm} import models._ import play.api.Logger @@ -21,7 +21,7 @@ import play.api.libs.openid.OpenIdClient import play.api.libs.ws.WSClient import play.api.mvc.{Result, _} import services.RateLimitChecker -import services.data.{AnonymousUser, AuthenticatedUser} +import services.data.{AnonymousUser, AuthenticatedUser, ItemNotFound} import services.oauth2.OAuth2Service import java.net.ConnectException @@ -151,7 +151,7 @@ case class Accounts @Inject()( implicit val apiUser: AnonymousUser.type = AnonymousUser val uuid = UUID.randomUUID() val profileData = Map(UserProfileF.NAME -> data.name) - for { + (for { profile <- userDataApi.createNewUserProfile[UserProfile]( data = profileData, groups = conf.defaultPortalGroups) account <- accounts.create(Account( @@ -166,6 +166,10 @@ case class Accounts @Inject()( } yield { sendValidationEmail(profile.data.name, data.email, uuid) result + }).recoverWith { + case e: ItemNotFound => + logger.error(s"Backend error creating user account: $e") + badForm(boundForm.withGlobalError("errors.databaseError"), InternalServerError) } } } diff --git a/modules/portal/conf/messages b/modules/portal/conf/messages index a3bef2365..22f4b6acd 100644 --- a/modules/portal/conf/messages +++ b/modules/portal/conf/messages @@ -434,7 +434,6 @@ error.globalErrors=There were problems with that form: error.date=Date is incorrect or badly formatted error.badUrl=URL is incorrect or badly formatted. Note: for web addresses, a valid URL must be prefixed \ be the scheme, e.g. ''http://'' or ''https://'' - error.required=Required error.emailExists=Email is either invalid or is already registered error.unknownUser=Unknown user diff --git a/test/integration/portal/SignupSpec.scala b/test/integration/portal/SignupSpec.scala index 54f8834b2..2ebe4d9ae 100644 --- a/test/integration/portal/SignupSpec.scala +++ b/test/integration/portal/SignupSpec.scala @@ -106,6 +106,13 @@ class SignupSpec extends IntegrationTestRunner { } } + "give a 500 error if defaultGroups not present in DB" in new ITestApp( + specificConfig = Map("ehri.portal.defaultUserGroups" -> Seq("BAD_GROUP"))) { + val signup = FakeRequest(accountRoutes.signupPost()).withCsrf.callWith(data) + status(signup) must equalTo(INTERNAL_SERVER_ERROR) + } + + "allow log in after sign up" in new ITestApp { val testEmail2 = "newuser@example.com" val data2 = data.updated(SignupData.EMAIL, Seq(testEmail2))