Commit 7d1a0298 authored by Julien Perret's avatar Julien Perret

refactoring on mongodb objects (collection, session)

parent 5dbe15d3
package org.openmole.gate.server
import com.mongodb.{MongoCredential, ServerAddress}
import com.mongodb.{DBObject, MongoCredential, ServerAddress}
import com.mongodb.casbah.Imports.{MongoCollection, MongoDBObject}
import com.mongodb.casbah.MongoClient
import org.openmole.gate.server.Data.User
......@@ -32,19 +32,22 @@ 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)
case class MongoData(collection: MongoCollection, userSession: DBObject)
def getMongoData(user: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)
MongoData(mongoClient(mongoDB.db)(mongoDB.dataSet), userSession)
}
get("/") {
contentType = "text/html"
auth("DB") match {
case Some(user) =>
mongoCollection.findOne(userSession) match {
val mongoData = getMongoData(user)
mongoData.collection.findOne(mongoData.userSession) match {
case Some(x) =>
tags.html(
head,
......@@ -54,7 +57,7 @@ class Servlet(mongoDB: MongoDB) extends ScalatraServlet with AuthenticationSuppo
)
)
case None =>
mongoCollection += userSession
mongoData.collection += mongoData.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