respond 404 on email not found on sso connect
This commit is contained in:
@@ -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)
|
||||||
}
|
}
|
||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user