| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | #include "authn.hh" |
|---|
| 21 | #include "request.hh" |
|---|
| 22 | #include "templated_resource.hh" |
|---|
| 23 | |
|---|
| 24 | #include "../db/db.hh" |
|---|
| 25 | #include "../html/util.hh" |
|---|
| 26 | #include "../server.hh" |
|---|
| 27 | #include "../tlate/group_value.hh" |
|---|
| 28 | #include "../tlate/list_value.hh" |
|---|
| 29 | #include "../tlate/tlate.hh" |
|---|
| 30 | |
|---|
| 31 | namespace http |
|---|
| 32 | { |
|---|
| 33 | class grouplist : public templated_resource |
|---|
| 34 | { |
|---|
| 35 | public: |
|---|
| 36 | grouplist(server::conn_cb cb) |
|---|
| 37 | : templated_resource(cb, "index.html") |
|---|
| 38 | {} |
|---|
| 39 | protected: |
|---|
| 40 | void set_attributes(boost::shared_ptr<request>, |
|---|
| 41 | tlate::data_model::ptr); |
|---|
| 42 | }; |
|---|
| 43 | |
|---|
| 44 | void grouplist::set_attributes(boost::shared_ptr<request> req, |
|---|
| 45 | tlate::data_model::ptr am) |
|---|
| 46 | { |
|---|
| 47 | boost::shared_ptr<db::user> u = req->get_user(); |
|---|
| 48 | using html::quote; |
|---|
| 49 | tlate::list_value::ptr sv(new tlate::list_value); |
|---|
| 50 | for (db::db::group_iterator git = cb.dbase().groups_begin(); |
|---|
| 51 | git != cb.dbase().groups_end(); git++) |
|---|
| 52 | { |
|---|
| 53 | boost::shared_ptr<db::group> gr = git->second; |
|---|
| 54 | tlate::group_value::ptr grv |
|---|
| 55 | (new tlate::group_value(gr, u)); |
|---|
| 56 | sv->push_back(grv); |
|---|
| 57 | } |
|---|
| 58 | am->insert("groups", sv); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | }; |
|---|
| 62 | |
|---|
| 63 | namespace |
|---|
| 64 | { |
|---|
| 65 | class factory : public server::http_resource_factory |
|---|
| 66 | { |
|---|
| 67 | public: |
|---|
| 68 | factory() { |
|---|
| 69 | server::register_http_resource("/", this); |
|---|
| 70 | } |
|---|
| 71 | boost::shared_ptr<http::resource> operator() |
|---|
| 72 | (server::conn_cb cb, std::string) { |
|---|
| 73 | boost::shared_ptr<http::resource> rv |
|---|
| 74 | (new http::grouplist(cb)); |
|---|
| 75 | return rv; |
|---|
| 76 | } |
|---|
| 77 | }; |
|---|
| 78 | factory f; |
|---|
| 79 | } |
|---|