1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2016 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.
19 # Here a simple example on how to use sessions with popcorn:
24 # var is_logged = false
30 # redef fun get(req, res) do
32 # <p>Is logged: {{{req.session.as(not null).is_logged}}}</p>
33 # <form action="/" method="POST">
34 # <input type="submit" value="Login" />
38 # redef fun post(req, res) do
39 # req.session.as(not null).is_logged = true
45 # app.use_before("/*", new SessionInit)
46 # app.use("/", new AppLogin)
47 # app.listen("localhost", 3000)
50 # Notice the use of the `SessionInit` on the `/*` route. You must use the
51 # `SessionInit` first to initialize the request session.
52 # Without that, your request session will be set to `null`.
57 # Initialize session in request if non existent.
59 # Should be called before any use of the session.
64 # app.use_before("/*", new SessionInit)
65 # # ... other middlewares
66 # app.listen("localhost", 3000)
71 redef fun all
(req
, res
) do if req
.session
== null then req
.session
= new Session