2 * Copyright (C) 2007 Martin Willi
3 * Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include "auth_controller.h"
17 #include "../manager.h"
22 typedef struct private_auth_controller_t private_auth_controller_t
;
25 * private data of the task manager
27 struct private_auth_controller_t
{
32 auth_controller_t
public;
40 static void login(private_auth_controller_t
*this, request_t
*request
)
42 request
->set(request
, "action", "check");
43 request
->set(request
, "title", "Login");
44 request
->render(request
, "templates/auth/login.cs");
47 static void check(private_auth_controller_t
*this, request_t
*request
)
49 char *username
, *password
;
51 username
= request
->get_query_data(request
, "username");
52 password
= request
->get_query_data(request
, "password");
53 if (username
&& password
&&
54 this->manager
->login(this->manager
, username
, password
))
56 request
->redirect(request
, "ikesa/list");
60 request
->redirect(request
, "auth/login");
64 static void logout(private_auth_controller_t
*this, request_t
*request
)
66 this->manager
->logout(this->manager
);
67 request
->redirect(request
, "auth/login");
71 * Implementation of controller_t.get_name
73 static char* get_name(private_auth_controller_t
*this)
79 * Implementation of controller_t.handle
81 static void handle(private_auth_controller_t
*this,
82 request_t
*request
, char *action
)
86 if (streq(action
, "login"))
88 return login(this, request
);
90 else if (streq(action
, "check"))
92 return check(this, request
);
94 else if (streq(action
, "logout"))
96 return logout(this, request
);
99 request
->redirect(request
, "auth/login");
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
.handle
= (void(*)(controller_t
*,request_t
*,char*,char*,char*,char*,char*))handle
;
119 this->public.controller
.destroy
= (void(*)(controller_t
*))destroy
;
121 this->manager
= (manager_t
*)context
;
123 return &this->public.controller
;