1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2014-2015 Alexandre Terrasa <alexandre@moz-code.org>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
26 redef fun get
(req
, res
) do
27 var users
= db
.collection
("users").find_all
(new JsonObject)
29 var tpl
= new Template
33 <h2>Add a new user</h2>
34 <form action="/" method="POST">
35 <input type="text" name="login" />
36 <input type="password" name="password" />
37 <input type="submit" value="save" />
44 <td>{{{user["login"] or else "null"}}}</td>
45 <td>{{{user["password"] or else "null"}}}</td>
52 redef fun post
(req
, res
) do
53 var json
= new JsonObject
54 json
["login"] = req
.post_args
["login"]
55 json
["password"] = req
.post_args
["password"]
56 db
.collection
("users").insert
(json
)
61 var mongo
= new MongoClient("mongodb://localhost:27017/")
62 var db
= mongo
.database
("mongo_example")
65 app
.use
("/", new UserList(db
))
66 app
.listen
("localhost", 3000)