2 * @file auth_controller.c
4 * @brief Implementation of auth_controller_t.
9 * Copyright (C) 2007 Martin Willi
10 * Hochschule fuer Technik Rapperswil
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 #include "auth_controller.h"
24 #include "../manager.h"
31 typedef struct private_auth_controller_t private_auth_controller_t
;
34 * private data of the task manager
36 struct private_auth_controller_t
{
41 auth_controller_t
public;
49 static void login(private_auth_controller_t
*this,
50 request_t
*request
, response_t
*response
)
52 template_t
*t
= template_create("templates/auth/login.cs");
53 t
->set(t
, "action", "check");
54 t
->render(t
, response
);
58 static void check(private_auth_controller_t
*this,
59 request_t
*request
, response_t
*response
)
61 char *username
, *password
;
63 username
= request
->get_post_data(request
, "username");
64 password
= request
->get_post_data(request
, "password");
65 if (username
&& password
&&
66 this->manager
->login(this->manager
, username
, password
))
68 response
->redirect(response
, "status/test");
72 response
->redirect(response
, "auth/login");
76 static void logout(private_auth_controller_t
*this,
77 request_t
*request
, response_t
*response
)
79 this->manager
->logout(this->manager
);
80 response
->redirect(response
, "auth/login");
84 * Implementation of controller_t.get_name
86 static char* get_name(private_auth_controller_t
*this)
92 * Implementation of controller_t.get_handler
94 static controller_handler_t
get_handler(private_auth_controller_t
*this, char *name
)
96 if (streq(name
, "login")) return (controller_handler_t
)login
;
97 if (streq(name
, "check")) return (controller_handler_t
)check
;
98 if (streq(name
, "logout")) return (controller_handler_t
)logout
;
103 * Implementation of controller_t.destroy
105 static void destroy(private_auth_controller_t
*this)
113 controller_t
*auth_controller_create(context_t
*context
, void *param
)
115 private_auth_controller_t
*this = malloc_thing(private_auth_controller_t
);
117 this->public.controller
.get_name
= (char*(*)(controller_t
*))get_name
;
118 this->public.controller
.get_handler
= (controller_handler_t(*)(controller_t
*,char*))get_handler
;
119 this->public.controller
.destroy
= (void(*)(controller_t
*))destroy
;
121 this->manager
= (manager_t
*)context
;
123 return &this->public.controller
;