2 * Copyright (C) 2007 Martin Willi
3 * HSR 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, fast_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, fast_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, fast_request_t
*request
)
66 this->manager
->logout(this->manager
);
67 request
->redirect(request
, "auth/login");
70 METHOD(fast_controller_t
, get_name
, char*,
71 private_auth_controller_t
*this)
76 METHOD(fast_controller_t
, handle
, void,
77 private_auth_controller_t
*this, fast_request_t
*request
, char *action
,
78 char *p2
, char *p3
, char *p4
, char *p5
)
82 if (streq(action
, "login"))
84 return login(this, request
);
86 else if (streq(action
, "check"))
88 return check(this, request
);
90 else if (streq(action
, "logout"))
92 return logout(this, request
);
95 request
->redirect(request
, "auth/login");
98 METHOD(fast_controller_t
, destroy
, void,
99 private_auth_controller_t
*this)
107 fast_controller_t
*auth_controller_create(fast_context_t
*context
, void *param
)
109 private_auth_controller_t
*this;
114 .get_name
= _get_name
,
119 .manager
= (manager_t
*)context
,
122 return &this->public.controller
;