respond 404 on email not found on sso connect

This commit is contained in:
2020-01-22 00:08:17 +01:00
parent 6746ca08e2
commit db744e5f31
2 changed files with 11 additions and 2 deletions

View File

@@ -14,7 +14,7 @@ class SsoManager(
private val citizenRepo: CitizenRepository
) {
fun sendMail(email: String, url: String) {
val citizen = citizenRepo.findByEmail(email) ?: error("No Citizen with this email")
val citizen = citizenRepo.findByEmail(email) ?: noEmail(email)
mailer.sendEmail {
Mail(
Email("sso@$domain"),
@@ -38,4 +38,9 @@ class SsoManager(
urlObject.parameters.append("token", JwtConfig.makeToken(citizen.user ?: error("Citizen must have User")))
return "Copy this link into your browser for connect to $domain: \n${urlObject.buildString()}"
}
class EmailNotFound(val email: String) : Exception() {
override val message: String = "No Citizen with this email : $email"
}
private fun noEmail(email: String): Nothing = throw EmailNotFound(email)
}