Merge: lib/popcorn: introduce AuthHandler to check user session
authorJean Privat <jean@pryen.org>
Tue, 16 Aug 2016 21:37:29 +0000 (17:37 -0400)
committerJean Privat <jean@pryen.org>
Tue, 16 Aug 2016 21:37:29 +0000 (17:37 -0400)
commit0acaba63c0c6f3d15674a5a0cfc271570044da94
tree010e0b6073673aa31296832d0680b2f56c975892
parentca7aa440b57141b0d4cf6f43074cbb01f1214dbb
parent09a1118073e18c265e8cccc5af86f4b802115651
Merge: lib/popcorn: introduce AuthHandler to check user session

### AuthHandler allows access to session user

 Inherit this handler to access to session user from your custom handler.

 For example, you need a profile handler that checks if the user is logged
 before returning it in json format.
 ~~~nit
 import popcorn::pop_auth

 class ProfileHandler
super AuthHandler

redef fun get(req, res) do
var user = check_session_user(req, res)
if user == null then return
res.json user.json
end
 end
 ~~~

 By using `check_session_user`, we delegate to the `AuthHandler` the responsability
 to set the HTTP 403 error.
 We then check is the user is not null before pursuing.

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

Pull-Request: #2271
Reviewed-by: Jean Privat <jean@pryen.org>