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 private val citizenRepo: CitizenRepository
) { ) {
fun sendMail(email: String, url: String) { 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 { mailer.sendEmail {
Mail( Mail(
Email("sso@$domain"), Email("sso@$domain"),
@@ -38,4 +38,9 @@ class SsoManager(
urlObject.parameters.append("token", JwtConfig.makeToken(citizen.user ?: error("Citizen must have User"))) 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()}" 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)
} }

View File

@@ -59,7 +59,11 @@ fun Route.auth(
post<SsoRequest> { post<SsoRequest> {
val content = call.receive<SsoRequest.Content>() val content = call.receive<SsoRequest.Content>()
try {
ssoManager.sendMail(content.email, content.url) ssoManager.sendMail(content.email, content.url)
} catch (e: SsoManager.EmailNotFound) {
call.respond(HttpStatusCode.NotFound)
}
call.respond(HttpStatusCode.NoContent) call.respond(HttpStatusCode.NoContent)
} }