2 * Copyright (C) 2008 Martin Willi
3 * Copyright (C) 2008 Philip Boetschi, Adrian Doerig
4 * Hochschule fuer Technik Rapperswil
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 #include "auth_filter.h"
23 typedef struct private_auth_filter_t private_auth_filter_t
;
26 * private data of auth_filter
28 struct private_auth_filter_t
{
46 * Implementation of filter_t.run
48 static bool run(private_auth_filter_t
*this, request_t
*request
,
49 char *controller
, char *action
)
51 if (this->user
->get_user(this->user
))
56 query
= this->db
->query(this->db
, "SELECT login FROM user WHERE id = ?",
57 DB_INT
, this->user
->get_user(this->user
),
59 if (query
&& query
->enumerate(query
, &login
))
61 request
->set(request
, "login", login
);
62 query
->destroy(query
);
66 this->user
->set_user(this->user
, 0);
68 if (controller
&& streq(controller
, "user") && action
&&
69 (streq(action
, "add") || streq(action
, "login") || streq(action
, "help")))
70 { /* add/login allowed */
73 request
->redirect(request
, "user/login");
78 * Implementation of filter_t.destroy
80 static void destroy(private_auth_filter_t
*this)
88 filter_t
*auth_filter_create(user_t
*user
, database_t
*db
)
90 private_auth_filter_t
*this= malloc_thing(private_auth_filter_t
);
92 this->public.filter
.destroy
= (void(*)(filter_t
*))destroy
;
93 this->public.filter
.run
= (bool(*)(filter_t
*, request_t
*,char*,char*,char*,char*,char*,char*))run
;
98 return &this->public.filter
;