mirror of
https://github.com/ysoftdevs/odc-analyzer.git
synced 2026-03-18 23:34:34 +01:00
Updated external user service to return email. The email is a new identifier.
This commit is contained in:
@@ -8,6 +8,6 @@ class AllowAllCredentialsVerificationService(app: play.api.Application) extends
|
||||
sys.error("allow-all can be used in dev mode only")
|
||||
}
|
||||
|
||||
override def verifyCredentials(username: String, password: String): Future[Boolean] = Future.successful(true)
|
||||
override def verifyCredentials(username: String, password: String): Future[Either[String, String]] = Future.successful(Right(username))
|
||||
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@ package services
|
||||
import scala.concurrent.Future
|
||||
|
||||
trait CredentialsVerificationService {
|
||||
def verifyCredentials(username: String, password: String): Future[Boolean]
|
||||
def verifyCredentials(username: String, password: String): Future[Either[String, String]]
|
||||
}
|
||||
|
||||
@@ -5,12 +5,18 @@ import play.api.libs.ws.{WS, WSClient}
|
||||
|
||||
import scala.concurrent.{Future, ExecutionContext}
|
||||
|
||||
case class LoginResponse(error: Option[String], email: Option[String])
|
||||
|
||||
class ExternalCredentialsVerificationService(url: String)(implicit executionContext: ExecutionContext, wSClient: WSClient) extends CredentialsVerificationService{
|
||||
override def verifyCredentials(username: String, password: String): Future[Boolean] = {
|
||||
|
||||
private implicit val loginResponseFormat = Json.format[LoginResponse]
|
||||
|
||||
override def verifyCredentials(username: String, password: String): Future[Either[String, String]] = {
|
||||
WS.clientUrl(url).post(Json.toJson(Map("username" -> username, "password" -> password))).map{ response =>
|
||||
response.body match {
|
||||
case "OK" => true
|
||||
case "bad" => false
|
||||
val loginResponse = loginResponseFormat.reads(response.json).get
|
||||
loginResponse.error match {
|
||||
case Some(err) => Left(err)
|
||||
case None => Right(loginResponse.email.get)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user