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

Small Refactorings

parent e524a4d2
......@@ -16,29 +16,28 @@ import scala.language.postfixOps
class LoginController @Inject()(cc: ControllerComponents, val dbConfigProvider: DatabaseConfigProvider, val tableDefs: TableDefs)(implicit ec: ExecutionContext)
extends AbstractController(cc) with HasDatabaseConfigProvider[JdbcProfile] with play.api.i18n.I18nSupport {
def lti: Action[AnyContent] = Action.async {
implicit request =>
request.body.asFormUrlEncoded match {
case None => Future(BadRequest("Body did not contain awaited values..."))
case Some(data) =>
def onError: Form[LtiFormValues] => Future[Result] = { formWithErrors =>
formWithErrors.errors.foreach(println)
Future(BadRequest("The form was not valid!"))
}
def lti: Action[AnyContent] = Action.async { implicit request =>
request.body.asFormUrlEncoded match {
case None => Future(BadRequest("Body did not contain awaited values..."))
case Some(data) =>
def onError: Form[LtiFormValues] => Future[Result] = { formWithErrors =>
formWithErrors.errors.foreach(println)
Future(BadRequest("The form was not valid!"))
}
def onRead: LtiFormValues => Future[Result] = { ltiFormValues =>
def onRead: LtiFormValues => Future[Result] = { ltiFormValues =>
for {
user <- selectOrInsertUser(ltiFormValues.username)
course <- selectOrInsertCourse(ltiFormValues.courseIdentifier, ltiFormValues.courseName)
_ <- selectOrInsertUserInCourse(user, course)
} yield Redirect(routes.HomeController.index()).withSession(idName -> user.username)
for {
user <- selectOrInsertUser(ltiFormValues.username)
course <- selectOrInsertCourse(ltiFormValues.courseIdentifier, ltiFormValues.courseName)
_ <- selectOrInsertUserInCourse(user, course)
} yield Redirect(routes.HomeController.index()).withSession(idName -> user.username)
}
}
FormMappings.ltiValuesForm.bindFromRequest().fold(onError, onRead)
}
FormMappings.ltiValuesForm.bindFromRequest().fold(onError, onRead)
}
}
private def selectOrInsertUser(username: String): Future[User] = tableDefs.futureUserByUserName(username) flatMap {
......
......@@ -24,11 +24,8 @@ GET /deselectLanguage/:langId
GET /languages/:langId/collections/:collId controllers.HomeController.collection(langId: Int, collId: Int)
GET /languages/:langId/collections/:collId/startLearning/:isRepeating controllers.HomeController.startLearning(langId: Int, collId: Int, isRepeating: Boolean)
GET /languages/:langId/collections/:collId/cards/:cardId/learn/:isRepeating controllers.HomeController.learn(langId: Int, collId: Int, cardId:Int, isRepeating: Boolean)
#GET /languages/:langId/collections/:collId/cards/:cardId/repeat controllers.HomeController.repeat(langId: Int, collId: Int, cardId:Int)
POST /languages/:langId/collections/:collId/cards/:cardId/checkSolution controllers.HomeController.checkSolution(langId:Int, collId: Int, cardId: Int)
......@@ -45,9 +42,5 @@ GET /languages/:langId/collections/:collId/admin
POST /languages/:langId/collection/:collId/uploadCardsFile controllers.AdminController.uploadCardsFile(langId: Int, collId: Int)
#GET /languages/:langId/collections/:collId/importForm controllers.AdminController.importForm(langId: Int, collId: Int)
#GET /languages/:langId/collections/:collId/import controllers.AdminController.performImport(langId: Int, collId: Int)
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
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