more initial impl of auth utils

This commit is contained in:
efim 2023-04-26 08:39:43 +04:00
parent b29d1a1ef1
commit 6c1220b544
2 changed files with 18 additions and 8 deletions

View File

@ -58,7 +58,7 @@ object Auth {
println( println(
s"> access room for $roomName $roomPassword $nickName, to return stub 111" s"> access room for $roomName $roomPassword $nickName, to return stub 111"
) )
) >> IO.pure(Right(ResponseCookie("authcookie", "1"))) ) >> IO.pure(Right(ResponseCookie("authcookieName", "1")))
override def deleteSession(sessionId: Long): IO[Unit] = override def deleteSession(sessionId: Long): IO[Unit] =
IO(s"got request to leave for $sessionId") IO(s"got request to leave for $sessionId")
@ -71,7 +71,7 @@ object Auth {
roomService: RoomService[F] roomService: RoomService[F]
) extends Auth[F] { ) extends Auth[F] {
val authcookie = "authcookie" val authcookieName = "authcookie"
override def joinRoom( override def joinRoom(
roomName: String, roomName: String,
@ -89,20 +89,30 @@ object Auth {
.leftMap(_.toString()) .leftMap(_.toString())
newSessionId = Random.nextLong() newSessionId = Random.nextLong()
_ <- EitherT.liftF(sessions.update(_.updated(newSessionId, (roomId, playerId)))) _ <- EitherT.liftF(sessions.update(_.updated(newSessionId, (roomId, playerId))))
} yield ResponseCookie(name = authcookie, content = newSessionId.toString(), secure = true) } yield ResponseCookie(
name = authcookieName,
content = newSessionId.toString(),
secure = true
)
result.value result.value
} }
override def authUser override def authUser
: Kleisli[[A] =>> cats.data.OptionT[F, A], Request[F], (PlayerID, RoomID)] = { : Kleisli[[A] =>> cats.data.OptionT[F, A], Request[F], (PlayerID, RoomID)] = {
// check authcookie presence, exchange it for playerID ad roomID Kleisli { (request: Request[F]) =>
??? OptionT(sessions.get.map { sessionsMap =>
for {
authcookie <- request.cookies.find(_.name == authcookieName)
sessionId <- authcookie.content.toLongOption
(roomId, playerId) <- sessionsMap.get(sessionId)
} yield (playerId, roomId)
})
}
} }
override def deleteSession(sessionId: Long): F[Unit] = { override def deleteSession(sessionId: Long): F[Unit] = {
// i suppose leaving the room should just be authed route & method sessions.update(_.removed(sessionId))
???
} }
} }

View File

@ -63,7 +63,7 @@ object Models {
final case class Room( final case class Room(
id: RoomID, id: RoomID,
players: List[Player], players: List[Player],
owner: PlayerID, owner: PlayerID, // TODO switch to nickname
password: String, password: String,
allowedCards: List[String], allowedCards: List[String],
round: RoundState, round: RoundState,