more initial impl of auth utils
This commit is contained in:
		
							parent
							
								
									b29d1a1ef1
								
							
						
					
					
						commit
						6c1220b544
					
				| @ -58,7 +58,7 @@ object Auth { | ||||
|         println( | ||||
|           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] = | ||||
|       IO(s"got request to leave for $sessionId") | ||||
| @ -71,7 +71,7 @@ object Auth { | ||||
|       roomService: RoomService[F] | ||||
|   ) extends Auth[F] { | ||||
| 
 | ||||
|     val authcookie = "authcookie" | ||||
|     val authcookieName = "authcookie" | ||||
| 
 | ||||
|     override def joinRoom( | ||||
|         roomName: String, | ||||
| @ -89,20 +89,30 @@ object Auth { | ||||
|           .leftMap(_.toString()) | ||||
|         newSessionId = Random.nextLong() | ||||
|         _ <- 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 | ||||
|     } | ||||
| 
 | ||||
|     override def authUser | ||||
|         : 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] = { | ||||
|       // i suppose leaving the room should just be authed route & method | ||||
|       ??? | ||||
|       sessions.update(_.removed(sessionId)) | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|  | ||||
| @ -63,7 +63,7 @@ object Models { | ||||
|   final case class Room( | ||||
|       id: RoomID, | ||||
|       players: List[Player], | ||||
|       owner: PlayerID, | ||||
|       owner: PlayerID, // TODO switch to nickname | ||||
|       password: String, | ||||
|       allowedCards: List[String], | ||||
|       round: RoundState, | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user