Commit ff85d9dc authored by Mathieu leclaire's avatar Mathieu leclaire

Add check route

parent 7d1a0298
......@@ -32,8 +32,10 @@ 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")
)
case class MongoData(collection: MongoCollection, userSession: DBObject)
def getMongoData(user:User) = {
def getMongoData(user: User) = {
val userSession = MongoDBObject(user.login -> session.getId)
println(mongoDB.host + " => " + mongoDB.port)
val server = new ServerAddress(mongoDB.host, mongoDB.port)
......@@ -42,12 +44,26 @@ class Servlet(mongoDB: MongoDB) extends ScalatraServlet with AuthenticationSuppo
println(mongoDB.db + " ? " + mongoDB.dataSet)
MongoData(mongoClient(mongoDB.db)(mongoDB.dataSet), userSession)
}
val loginParam = "login"
get(s"/check/:$loginParam") {
val login = params(loginParam)
findInMongo(User(login)).isDefined
}
def findInMongo(user: User) = {
val mongoData = getMongoData(user)
mongoData.collection.findOne(mongoData.userSession)
}
get("/") {
contentType = "text/html"
auth("DB") match {
case Some(user) =>
val mongoData = getMongoData(user)
mongoData.collection.findOne(mongoData.userSession) match {
findInMongo(user) match {
case Some(x) =>
tags.html(
head,
......
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