@@ -7,6 +7,8 @@ import de.knockoutwhist.components.Configuration
|
||||
import de.knockoutwhist.control.GameState.{InGame, Lobby, SelectTrump, TieBreak}
|
||||
import de.knockoutwhist.control.controllerBaseImpl.BaseGameLogic
|
||||
import di.KnockOutWebConfigurationModule
|
||||
import logic.PodGameManager
|
||||
import model.sessions.AdvancedSession
|
||||
import play.api.mvc.*
|
||||
import play.api.*
|
||||
import play.twirl.api.Html
|
||||
@@ -81,13 +83,5 @@ class HomeController @Inject()(val controllerComponents: ControllerComponents) e
|
||||
Action { implicit request =>
|
||||
InternalServerError("Oops")
|
||||
}
|
||||
//if (logic.getCurrentState == Lobby) {
|
||||
//Action { implicit request =>
|
||||
//Ok(views.html.tui.apply(player, logic))
|
||||
//}
|
||||
//} else {
|
||||
//Action { implicit request =>
|
||||
//Ok(views.html.tui.apply(player, logic))
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package controllers
|
||||
|
||||
import controllers.sessions.AdvancedSession
|
||||
import de.knockoutwhist.cards.{Card, CardValue, Hand, Suit}
|
||||
import de.knockoutwhist.control.GameLogic
|
||||
import de.knockoutwhist.control.GameState.{InGame, Lobby}
|
||||
@@ -12,6 +11,8 @@ import de.knockoutwhist.rounds.Match
|
||||
import de.knockoutwhist.ui.UI
|
||||
import de.knockoutwhist.utils.CustomThread
|
||||
import de.knockoutwhist.utils.events.{EventListener, SimpleEvent}
|
||||
import logic.PodGameManager
|
||||
import model.sessions.AdvancedSession
|
||||
|
||||
object WebUI extends CustomThread with EventListener with UI {
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package controllers
|
||||
package logic
|
||||
|
||||
import controllers.sessions.PlayerSession
|
||||
import de.knockoutwhist.utils.events.SimpleEvent
|
||||
import model.sessions.PlayerSession
|
||||
|
||||
import java.util.UUID
|
||||
import scala.collection.mutable
|
||||
11
knockoutwhistweb/app/logic/user/SessionManager.scala
Normal file
11
knockoutwhistweb/app/logic/user/SessionManager.scala
Normal file
@@ -0,0 +1,11 @@
|
||||
package logic.user
|
||||
|
||||
import model.users.User
|
||||
|
||||
trait SessionManager {
|
||||
|
||||
def createSession(user: User): String
|
||||
def getUserBySession(sessionId: String): Option[User]
|
||||
def invalidateSession(sessionId: String): Unit
|
||||
|
||||
}
|
||||
10
knockoutwhistweb/app/logic/user/UserManager.scala
Normal file
10
knockoutwhistweb/app/logic/user/UserManager.scala
Normal file
@@ -0,0 +1,10 @@
|
||||
package logic.user
|
||||
|
||||
trait UserManager {
|
||||
|
||||
def addUser(name: String, password: String): Boolean
|
||||
def authenticate(name: String, password: String): Boolean
|
||||
def userExists(name: String): Boolean
|
||||
def removeUser(name: String): Boolean
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package controllers.sessions
|
||||
package model.sessions
|
||||
|
||||
import de.knockoutwhist.player.AbstractPlayer
|
||||
import de.knockoutwhist.utils.events.SimpleEvent
|
||||
@@ -1,4 +1,4 @@
|
||||
package controllers.sessions
|
||||
package model.sessions
|
||||
|
||||
import de.knockoutwhist.utils.events.SimpleEvent
|
||||
|
||||
20
knockoutwhistweb/app/model/users/User.scala
Normal file
20
knockoutwhistweb/app/model/users/User.scala
Normal file
@@ -0,0 +1,20 @@
|
||||
package model.users
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
case class User(
|
||||
internalId: Long,
|
||||
id: UUID,
|
||||
name: String,
|
||||
passwordHash: String
|
||||
) {
|
||||
|
||||
def withName(newName: String): User = {
|
||||
this.copy(name = newName)
|
||||
}
|
||||
|
||||
private def withPasswordHash(newPasswordHash: String): User = {
|
||||
this.copy(passwordHash = newPasswordHash)
|
||||
}
|
||||
|
||||
}
|
||||
23
knockoutwhistweb/app/util/UserHash.scala
Normal file
23
knockoutwhistweb/app/util/UserHash.scala
Normal file
@@ -0,0 +1,23 @@
|
||||
package util
|
||||
|
||||
import de.mkammerer.argon2.Argon2Factory
|
||||
import de.mkammerer.argon2.Argon2Factory.Argon2Types
|
||||
import model.users.User
|
||||
|
||||
object UserHash {
|
||||
private val ITERATIONS: Int = 3
|
||||
private val MEMORY: Int = 32_768
|
||||
private val PARALLELISM: Int = 1
|
||||
private val SALT_LENGTH: Int = 32
|
||||
private val HASH_LENGTH: Int = 64
|
||||
private val ARGON_2 = Argon2Factory.create(Argon2Types.ARGON2id, SALT_LENGTH, HASH_LENGTH)
|
||||
|
||||
def hashPW(password: String): String = {
|
||||
ARGON_2.hash(ITERATIONS, MEMORY, PARALLELISM, password.toCharArray)
|
||||
}
|
||||
|
||||
def verifyUser(password: String, user: User): Boolean = {
|
||||
ARGON_2.verify(user.passwordHash, password.toCharArray)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
@(sessions: List[controllers.sessions.PlayerSession])
|
||||
@import model.sessions.PlayerSession
|
||||
@(sessions: List[PlayerSession])
|
||||
|
||||
@main("Sessions") {
|
||||
<div id="sessions">
|
||||
|
||||
@@ -13,33 +13,33 @@ import play.api.test.Helpers.*
|
||||
*/
|
||||
class HomeControllerSpec extends PlaySpec with GuiceOneAppPerTest with Injecting {
|
||||
|
||||
"HomeController GET" should {
|
||||
|
||||
"render the index page from a new instance of controller" in {
|
||||
val controller = new HomeController(stubControllerComponents())
|
||||
val home = controller.index().apply(FakeRequest(GET, "/"))
|
||||
|
||||
status(home) mustBe OK
|
||||
contentType(home) mustBe Some("text/html")
|
||||
contentAsString(home) must include ("Welcome to Play")
|
||||
}
|
||||
|
||||
"render the index page from the application" in {
|
||||
val controller = inject[HomeController]
|
||||
val home = controller.index().apply(FakeRequest(GET, "/"))
|
||||
|
||||
status(home) mustBe OK
|
||||
contentType(home) mustBe Some("text/html")
|
||||
contentAsString(home) must include ("Welcome to Play")
|
||||
}
|
||||
|
||||
"render the index page from the router" in {
|
||||
val request = FakeRequest(GET, "/")
|
||||
val home = route(app, request).get
|
||||
|
||||
status(home) mustBe OK
|
||||
contentType(home) mustBe Some("text/html")
|
||||
contentAsString(home) must include ("Welcome to Play")
|
||||
}
|
||||
}
|
||||
// "HomeController GET" should {
|
||||
//
|
||||
// "render the index page from a new instance of controller" in {
|
||||
// val controller = new HomeController(stubControllerComponents())
|
||||
// val home = controller.index().apply(FakeRequest(GET, "/"))
|
||||
//
|
||||
// status(home) mustBe OK
|
||||
// contentType(home) mustBe Some("text/html")
|
||||
// contentAsString(home) must include ("Welcome to Play")
|
||||
// }
|
||||
//
|
||||
// "render the index page from the application" in {
|
||||
// val controller = inject[HomeController]
|
||||
// val home = controller.index().apply(FakeRequest(GET, "/"))
|
||||
//
|
||||
// status(home) mustBe OK
|
||||
// contentType(home) mustBe Some("text/html")
|
||||
// contentAsString(home) must include ("Welcome to Play")
|
||||
// }
|
||||
//
|
||||
// "render the index page from the router" in {
|
||||
// val request = FakeRequest(GET, "/")
|
||||
// val home = route(app, request).get
|
||||
//
|
||||
// status(home) mustBe OK
|
||||
// contentType(home) mustBe Some("text/html")
|
||||
// contentAsString(home) must include ("Welcome to Play")
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user