Skip to content

Commit

Permalink
Apply spotless formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed Aug 10, 2023
1 parent 62432b0 commit 1cb6993
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import jakarta.persistence.Id
@Entity(name = "email_domain_blacklist")
data class DomainBlacklist(
@Id
val domain: String
val domain: String,
)

@ApplicationScoped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ class NameRecordRepository : PanacheRepositoryBase<NameRecord, Int> {
"previousName = ?1 and changeTime >= ?2 and userId != ?3",
previousName,
changeTime,
userId
userId,
) > 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ import com.faforever.userservice.backend.domain.DomainBlacklistRepository
import com.faforever.userservice.backend.domain.User
import com.faforever.userservice.backend.domain.UserRepository
import com.faforever.userservice.config.FafProperties
import io.quarkus.mailer.Mail
import io.quarkus.mailer.Mailer
import jakarta.enterprise.context.ApplicationScoped
import jakarta.transaction.Transactional
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.util.regex.Pattern


@ApplicationScoped
class EmailService(
private val userRepository: UserRepository,
Expand All @@ -30,7 +27,7 @@ class EmailService(
enum class ValidationResult {
VALID,
INVALID,
BLACKLISTED
BLACKLISTED,
}

fun changeUserEmail(newEmail: String, user: User) {
Expand All @@ -49,7 +46,7 @@ class EmailService(
!EMAIL_PATTERN.matcher(email).matches() -> ValidationResult.INVALID

domainBlacklistRepository.existsByDomain(
email.substring(email.lastIndexOf('@') + 1)
email.substring(email.lastIndexOf('@') + 1),
) -> ValidationResult.BLACKLISTED

else -> ValidationResult.VALID
Expand All @@ -76,4 +73,3 @@ class EmailService(
)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.slf4j.LoggerFactory
import java.nio.file.Files
import java.nio.file.Path


@Startup
@Singleton
class MailBodyBuilder(private val properties: FafProperties) {
Expand All @@ -22,7 +21,8 @@ class MailBodyBuilder(private val properties: FafProperties) {
enum class Template(vararg variables: String) {
ACCOUNT_ACTIVATION("username", "activationUrl"),
WELCOME_TO_FAF("username"),
PASSWORD_RESET("username", "passwordResetUrl");
PASSWORD_RESET("username", "passwordResetUrl"),
;

val variables: Set<String>

Expand Down Expand Up @@ -102,25 +102,27 @@ class MailBodyBuilder(private val properties: FafProperties) {

fun buildAccountActivationBody(username: String, activationUrl: String) =
populate(
Template.ACCOUNT_ACTIVATION, mapOf(
Template.ACCOUNT_ACTIVATION,
mapOf(
"username" to username,
"activationUrl" to activationUrl
)
"activationUrl" to activationUrl,
),
)

fun buildWelcomeToFafBody(username: String) =
populate(
Template.WELCOME_TO_FAF, mapOf(
"username" to username
)
Template.WELCOME_TO_FAF,
mapOf(
"username" to username,
),
)

fun buildPasswordResetBody(username: String, passwordResetUrl: String)=
populate(
Template.PASSWORD_RESET, mapOf(
fun buildPasswordResetBody(username: String, passwordResetUrl: String) =
populate(
Template.PASSWORD_RESET,
mapOf(
"username" to username,
"passwordResetUrl" to passwordResetUrl
)
"passwordResetUrl" to passwordResetUrl,
),
)
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import jakarta.enterprise.context.ApplicationScoped
@ApplicationScoped
class MailSender(
private val mailer: Mailer,
) {
) {
fun sendMail(toEmail: String, subject: String, content: String) {
mailer.send(
Mail.withText(toEmail, subject, content)
Mail.withText(toEmail, subject, content),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,28 @@ class MetricHelper(meterRegistry: MeterRegistry) {
// User Registration Counters
val userRegistrationCounter: Counter = meterRegistry.counter(
USER_REGISTRATIONS_COUNT,
STEP_TAG, "registration"
STEP_TAG,
"registration",
)
val userActivationCounter: Counter = meterRegistry.counter(
USER_REGISTRATIONS_COUNT,
STEP_TAG, "activation"
STEP_TAG,
"activation",
)
val userSteamLinkRequestedCounter: Counter = meterRegistry.counter(
USER_REGISTRATIONS_COUNT,
STEP_TAG, "steamLinkRequested"
STEP_TAG,
"steamLinkRequested",
)
val userSteamLinkDoneCounter: Counter = meterRegistry.counter(
USER_REGISTRATIONS_COUNT,
STEP_TAG, "steamLinkDone"
STEP_TAG,
"steamLinkDone",
)
val userSteamLinkFailedCounter: Counter = meterRegistry.counter(
USER_REGISTRATIONS_COUNT,
STEP_TAG, "steamLinkFailed"
STEP_TAG,
"steamLinkFailed",
)

// Username Change Counters
Expand All @@ -41,32 +46,44 @@ class MetricHelper(meterRegistry: MeterRegistry) {
// Password Reset Counters
val userPasswordResetRequestCounter: Counter = meterRegistry.counter(
USER_PASSWORD_RESET_COUNT,
STEP_TAG, "request",
MODE_TAG, "email"
STEP_TAG,
"request",
MODE_TAG,
"email",
)
val userPasswordResetViaSteamRequestCounter: Counter = meterRegistry.counter(
USER_PASSWORD_RESET_COUNT,
STEP_TAG, "request",
MODE_TAG, "steam"
STEP_TAG,
"request",
MODE_TAG,
"steam",
)
val userPasswordResetDoneCounter: Counter = meterRegistry.counter(
USER_PASSWORD_RESET_COUNT,
STEP_TAG, "done",
MODE_TAG, "email"
STEP_TAG,
"done",
MODE_TAG,
"email",
)
val userPasswordResetFailedCounter: Counter = meterRegistry.counter(
USER_PASSWORD_RESET_COUNT,
STEP_TAG, "failed",
MODE_TAG, "email"
STEP_TAG,
"failed",
MODE_TAG,
"email",
)
val userPasswordResetDoneViaSteamCounter: Counter = meterRegistry.counter(
USER_PASSWORD_RESET_COUNT,
STEP_TAG, "done",
MODE_TAG, "steam"
STEP_TAG,
"done",
MODE_TAG,
"steam",
)
val userPasswordResetFailedViaSteamCounter: Counter = meterRegistry.counter(
USER_PASSWORD_RESET_COUNT,
STEP_TAG, "failed",
MODE_TAG, "steam"
STEP_TAG,
"failed",
MODE_TAG,
"steam",
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ interface RecaptchaClient {

@POST
@Path("/siteverify")
fun validateResponse(@QueryParam("secret") secret: String, @QueryParam("response") response: String?): VerifyResponse

fun validateResponse(
@QueryParam("secret") secret: String,
@QueryParam("response") response: String?,
): VerifyResponse
}

@ApplicationScoped
Expand Down Expand Up @@ -54,5 +56,5 @@ data class VerifyResponse(
val success: Boolean,
val challengeTs: OffsetDateTime?,
val hostname: String,
@JsonProperty("error-codes") val errorCodes: List<String>?
@JsonProperty("error-codes") val errorCodes: List<String>?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enum class EmailStatus {

data class RegisteredUser(
val username: String,
val email: String
val email: String,
)

@ApplicationScoped
Expand Down Expand Up @@ -61,8 +61,9 @@ class RegistrationService(
FafTokenType.REGISTRATION,
Duration.ofSeconds(fafProperties.account().registration().linkExpirationSeconds()),
mapOf(
KEY_USERNAME to username, KEY_EMAIL to email
)
KEY_USERNAME to username,
KEY_EMAIL to email,
),
)
val activationUrl = fafProperties.account().registration().activationUrlFormat().format(token)
emailService.sendActivationMail(username, email, activationUrl)
Expand All @@ -78,8 +79,8 @@ class RegistrationService(
FafTokenType.REGISTRATION,
Duration.ofSeconds(fafProperties.account().passwordReset().linkExpirationSeconds()),
mapOf(
KEY_USER_ID to user.id.toString()
)
KEY_USER_ID to user.id.toString(),
),
)
val passwordResetUrl = fafProperties.account().passwordReset().passwordResetUrlFormat().format(token)
emailService.sendPasswordResetMail(user.username, user.email, passwordResetUrl)
Expand All @@ -94,7 +95,7 @@ class RegistrationService(

val reserved = nameRecordRepository.existsByPreviousNameAndChangeTimeAfter(
username,
OffsetDateTime.now().minusMonths(fafProperties.account().username().usernameReservationTimeInMonths())
OffsetDateTime.now().minusMonths(fafProperties.account().username().usernameReservationTimeInMonths()),
)

return if (reserved) UsernameStatus.USERNAME_RESERVED else UsernameStatus.USERNAME_AVAILABLE
Expand All @@ -115,7 +116,7 @@ class RegistrationService(
val claims: Map<String, String>
try {
claims = fafTokenService.getTokenClaims(FafTokenType.REGISTRATION, registrationToken)
} catch (exception : Exception) {
} catch (exception: Exception) {
LOG.error("Unable to extract claims", exception)
throw InvalidRegistrationException()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ class FafTokenService(

fun createToken(fafTokenType: FafTokenType, lifetime: TemporalAmount, attributes: Map<String, String>): String {
if (attributes.containsKey(KEY_ACTION)) {
throw IllegalArgumentException(MessageFormat.format("'{0}' is a protected attributed and must not be used", KEY_ACTION))
throw IllegalArgumentException(
MessageFormat.format("'{0}' is a protected attributed and must not be used", KEY_ACTION),
)
}

val jwtBuilder = JWTClaimsSet.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ class InvalidRegistrationExceptionView : CompactVerticalLayout(), HasErrorParame
add(errorLayout)
}

override fun setErrorParameter(event: BeforeEnterEvent?, parameter: ErrorParameter<InvalidRegistrationException>?): Int {
override fun setErrorParameter(
event: BeforeEnterEvent?,
parameter: ErrorParameter<InvalidRegistrationException>?,
): Int {
return HttpServletResponse.SC_INTERNAL_SERVER_ERROR
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ class LoginView(private val hydraService: HydraService, private val fafPropertie
when (loginError) {
is LoginResult.UserNoGameOwnership -> {
header.setTitle(getTranslation("verification.title"))
errorMessage.text = getTranslation("verification.reason") + " " + fafProperties.account().accountLinkUrl()
errorMessage.text = getTranslation("verification.reason") + " " +
fafProperties.account().accountLinkUrl()
}

is LoginResult.TechnicalError -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ class ActivateView(private val registrationService: RegistrationService, fafProp
.bind("password")

binder.forField(confirmedPassword)
.withValidator({ confirmedPassword -> confirmedPassword == password.value }, getTranslation("register.password.match")
.withValidator(
{ confirmedPassword -> confirmedPassword == password.value },
getTranslation("register.password.match"),
).bind("confirmedPassword")

binder.addStatusChangeListener { submit.isEnabled = it.binder.isValid }

}

private fun activate() {
Expand All @@ -98,7 +99,7 @@ class ActivateView(private val registrationService: RegistrationService, fafProp
return
}

val ipAddress = IpAddress(VaadinSession.getCurrent().browser.address);
val ipAddress = IpAddress(VaadinSession.getCurrent().browser.address)

registrationService.activate(registeredUser, ipAddress, password.value)

Expand All @@ -120,4 +121,4 @@ class ActivateView(private val registrationService: RegistrationService, fafProp
throw InvalidRegistrationException()
}
}
}
}
Loading

0 comments on commit 1cb6993

Please sign in to comment.