Commit 7dfebc64 authored by Björn Eyselein's avatar Björn Eyselein
Browse files

Sicherungscommit

parent b5dcab32
......@@ -3,6 +3,7 @@ target
public/*
.bsp/
.idea/
project/target
project/project/target
......
version = 2.6.1
version = 2.7.5
align = more
maxColumn = 120
......
package controllers
import java.util.UUID
import javax.inject.{Inject, Singleton}
import model._
import model.graphql.GraphQLModel
import play.api.Configuration
......@@ -15,6 +12,8 @@ import sangria.execution.{ErrorWithResolver, Executor, QueryAnalysisError}
import sangria.marshalling.playJson._
import sangria.parser.QueryParser
import java.util.UUID
import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}
......@@ -55,75 +54,71 @@ class ApiController @Inject() (
def graphiql: Action[AnyContent] = Action { implicit request => Ok(views.html.graphiql("graphql")) }
def graphql: Action[GraphQLRequest] =
Action.async(parse.json[GraphQLRequest]) { implicit request =>
QueryParser.parse(request.body.query) match {
case Failure(error) => Future.successful(BadRequest(Json.obj("error" -> error.getMessage)))
case Success(queryAst) =>
Executor
.execute(
graphqlSchema,
queryAst,
operationName = request.body.operationName,
variables = request.body.variables.getOrElse(Json.obj())
)
.map(Ok(_))
.recover {
case error: QueryAnalysisError => BadRequest(error.resolveError)
case error: ErrorWithResolver => InternalServerError(error.resolveError)
}
}
def graphql: Action[GraphQLRequest] = Action.async(parse.json[GraphQLRequest]) { implicit request =>
QueryParser.parse(request.body.query) match {
case Failure(error) => Future.successful(BadRequest(Json.obj("error" -> error.getMessage)))
case Success(queryAst) =>
Executor
.execute(
graphqlSchema,
queryAst,
operationName = request.body.operationName,
variables = request.body.variables.getOrElse(Json.obj())
)
.map(Ok(_))
.recover {
case error: QueryAnalysisError => BadRequest(error.resolveError)
case error: ErrorWithResolver => InternalServerError(error.resolveError)
}
}
}
@deprecated
private def selectOrInsertUser(username: String): Future[User] =
futureUserByName(username).flatMap {
case Some(user) => Future.successful(user)
case None =>
val newUser = User(username)
insertUser(newUser).map {
case true => newUser
case false => ???
}
}
def lti: Action[AnyContent] =
Action.async { implicit request =>
def onError: Form[LtiFormValues] => Future[Result] = { formWithErrors =>
formWithErrors.errors.foreach(println)
Future(BadRequest("The form was not valid!"))
private def selectOrInsertUser(username: String): Future[User] = futureUserByName(username).flatMap {
case Some(user) => Future.successful(user)
case None =>
val newUser = User(username)
insertUser(newUser).map {
case true => newUser
case false => ???
}
}
def onRead: LtiFormValues => Future[Result] = { ltiFormValues =>
selectOrInsertUser(ltiFormValues.username).map { user =>
val uuid = UUID.randomUUID()
def lti: Action[AnyContent] = Action.async { implicit request =>
def onError: Form[LtiFormValues] => Future[Result] = { formWithErrors =>
formWithErrors.errors.foreach(println)
Future(BadRequest("The form was not valid!"))
}
val loggedInUser = LoggedInUser(user.username, user.hasAcceptedDataPrivacyStatement, user.isAdmin)
def onRead: LtiFormValues => Future[Result] = { ltiFormValues =>
selectOrInsertUser(ltiFormValues.username).map { user =>
val uuid = UUID.randomUUID()
addJwt(configuration, uuid, loggedInUser)
val loggedInUser = LoggedInUser(user.username, user.hasAcceptedDataPrivacyStatement, user.isAdmin)
Redirect(s"/lti/${uuid.toString}")
}
}
addJwt(configuration, uuid, loggedInUser)
FormMappings.ltiValuesForm.bindFromRequest().fold(onError, onRead)
Redirect(s"/lti/${uuid.toString}")
}
}
def registerAsLtiProvider: Action[AnyContent] =
Action { implicit request =>
def onError: Form[LtiToolProxyRegistrationRequestFormValues] => Result = { formWithErrors =>
formWithErrors.errors.foreach(println)
BadRequest("TODO!")
}
FormMappings.ltiValuesForm.bindFromRequest().fold(onError, onRead)
}
def onRead: LtiToolProxyRegistrationRequestFormValues => Result = { ltiToolProxyRegistrationRequestFormValues =>
println(ltiToolProxyRegistrationRequestFormValues)
def registerAsLtiProvider: Action[AnyContent] = Action { implicit request =>
def onError: Form[LtiToolProxyRegistrationRequestFormValues] => Result = { formWithErrors =>
formWithErrors.errors.foreach(println)
BadRequest("TODO!")
}
???
}
def onRead: LtiToolProxyRegistrationRequestFormValues => Result = { ltiToolProxyRegistrationRequestFormValues =>
println(ltiToolProxyRegistrationRequestFormValues)
FormMappings.ltiToolProxyRegistrationRequestForm.bindFromRequest().fold(onError, onRead)
???
}
FormMappings.ltiToolProxyRegistrationRequestForm.bindFromRequest().fold(onError, onRead)
}
}
......@@ -2,9 +2,10 @@ package model
import play.api.libs.json.{JsObject, Json, OFormat}
import play.modules.reactivemongo.ReactiveMongoComponents
import reactivemongo.api.bson.collection.BSONCollection
import reactivemongo.api.{Cursor, ReadConcern}
import reactivemongo.play.json.collection.JSONCollection
import reactivemongo.play.json.compat._
import reactivemongo.bson.BSONDocument
import reactivemongo.play.json.compat.json2bson._
import scala.concurrent.{ExecutionContext, Future}
......@@ -22,17 +23,17 @@ trait MongoQueries extends ReactiveMongoComponents {
private val db = reactiveMongoApi.database
private def futureUsersCollection: Future[JSONCollection] = db.map(_.collection("users"))
private def futureUsersCollection: Future[BSONCollection] = db.map(_.collection("users"))
private def futureLanguagesCollection: Future[JSONCollection] = db.map(_.collection("languages"))
private def futureLanguagesCollection: Future[BSONCollection] = db.map(_.collection("languages"))
private def futureCoursesCollection: Future[JSONCollection] = db.map(_.collection("courses"))
private def futureCoursesCollection: Future[BSONCollection] = db.map(_.collection("courses"))
private def futureUsersInCoursesCollection: Future[JSONCollection] = db.map(_.collection("usersInCourses"))
private def futureUsersInCoursesCollection: Future[BSONCollection] = db.map(_.collection("usersInCourses"))
private def futureCollectionsCollection: Future[JSONCollection] = db.map(_.collection("collections"))
private def futureCollectionsCollection: Future[BSONCollection] = db.map(_.collection("collections"))
private def futureFlashcardsCollection: Future[JSONCollection] = db.map(_.collection("flashcards"))
private def futureFlashcardsCollection: Future[BSONCollection] = db.map(_.collection("flashcards"))
// User
......@@ -41,7 +42,7 @@ trait MongoQueries extends ReactiveMongoComponents {
usersCollection <- futureUsersCollection
maybeUser <-
usersCollection
.find(Json.obj("username" -> username), Option.empty[JsObject])
.find(Json.obj("username" -> username), Option.empty[BSONDocument])
.one[User]
} yield maybeUser
......
......@@ -8,9 +8,9 @@ lazy val root = (project in file("."))
.enablePlugins(PlayScala)
.settings(packageName in Universal := s"${name.value}")
scalaVersion := "2.13.3"
scalaVersion := "2.13.5"
updateOptions := updateOptions.value.withCachedResolution(cachedResoluton = true)
// updateOptions := updateOptions.value.withCachedResolution(cachedResoluton = true)
PlayKeys.playDefaultPort := 9090
......@@ -26,19 +26,19 @@ libraryDependencies ++= Seq(
guice,
"org.scalatestplus.play" %% "scalatestplus-play" % "5.1.0" % Test,
// Database
"org.reactivemongo" %% "play2-reactivemongo" % "0.20.11-play28", // Apache 2.0
"org.reactivemongo" %% "reactivemongo-play-json-compat" % "0.20.11-play28", // Apache 2.0
"org.reactivemongo" %% "play2-reactivemongo" % "1.0.3-play28", // Apache 2.0
"org.reactivemongo" %% "reactivemongo-play-json-compat" % "1.0.3-play28", // Apache 2.0
// Jwt
"com.github.t3hnar" %% "scala-bcrypt" % "4.1",
"com.pauldijou" %% "jwt-play" % "4.3.0",
"com.github.t3hnar" %% "scala-bcrypt" % "4.3.0",
"com.pauldijou" %% "jwt-play" % "5.0.0",
// Scala libs
"com.github.pathikrit" %% "better-files" % "3.9.1",
"com.beachape" %% "enumeratum-play" % "1.6.0",
"com.beachape" %% "enumeratum-play-json" % "1.6.0",
"com.beachape" %% "enumeratum-play" % "1.6.3",
"com.beachape" %% "enumeratum-play-json" % "1.6.3",
// GraphQL
"org.sangria-graphql" %% "sangria" % "2.0.0",
"org.sangria-graphql" %% "sangria" % "2.1.0",
"org.sangria-graphql" %% "sangria-play-json" % "2.0.1",
// POI
"org.apache.poi" % "poi" % "4.1.2",
"org.apache.poi" % "poi-ooxml" % "4.1.2"
"org.apache.poi" % "poi" % "5.0.0",
"org.apache.poi" % "poi-ooxml" % "5.0.0"
)
......@@ -33,7 +33,8 @@ db.users.insertOne({
username: "jack",
hasAcceptedDataPrivacyStatement: false,
isAdmin: true,
pwHash: "$2a$10$MMjdZaz.flH2Z8MIlyMzweVnobsHup.3VR7dr5VtEK/qZDKLwBcwa"
// test
pwHash: "$2y$12$1S/CB9jMFZgNUnzaWrKZYu0TjPgiBdPA0FUYD5bT3LWx9IBMhHLfG"
});
/* Create courses collection */
......
sbt.version=1.3.10
sbt.version=1.5.0
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.2")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.7")
// Wart remover for scalac
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.4.9")
// Sbt Updates
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.5.1")
// Scala formatter
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.0")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.5.2")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment