Commit cb007180 authored by Mathieu leclaire's avatar Mathieu leclaire

Get Mongo initialization out the / route

parent 9bee3626
......@@ -31,19 +31,19 @@ class Servlet(mongoDB: MongoDB) extends ScalatraServlet with AuthenticationSuppo
tags.link(tags.rel := "stylesheet", tags.`type` := "text/css", href := "css/bootstrap.min.css"),
tags.script(tags.`type` := "text/javascript", tags.src := "js/gate.js")
)
val userSession = MongoDBObject(user.login -> session.getId)
println(mongoDB.host + " => " + mongoDB.port)
val server = new ServerAddress(mongoDB.host, mongoDB.port)
val credentials = MongoCredential.createCredential("accountUser", "products", "password".toCharArray)
val mongoClient = MongoClient(server, List(credentials))
println(mongoDB.db + " ? " + mongoDB.dataSet)
val mongoCollection = mongoClient(mongoDB.db)(mongoDB.dataSet)
get("/") {
contentType = "text/html"
auth("DB") match {
case Some(user) =>
val userSession = MongoDBObject(user.login -> session.getId)
println(mongoDB.host + " => " + mongoDB.port)
val server = new ServerAddress(mongoDB.host, mongoDB.port)
val credentials = MongoCredential.createCredential("accountUser", "products", "password".toCharArray)
val mongoClient = MongoClient(server, List(credentials))
println(mongoDB.db + " ? " + mongoDB.dataSet)
val mongoColl = mongoClient(mongoDB.db)(mongoDB.dataSet)
mongoColl.findOne(userSession) match {
mongoCollection.findOne(userSession) match {
case Some(x) =>
tags.html(
head,
......@@ -53,7 +53,7 @@ class Servlet(mongoDB: MongoDB) extends ScalatraServlet with AuthenticationSuppo
)
)
case None =>
mongoColl += userSession
mongoCollection += userSession
tags.html(
head,
tags.body(
......
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