removed some raw EAP debug output
[strongswan.git] / src / manager / controller / auth_controller.c
1 /*
2 * Copyright (C) 2007 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
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>.
9 *
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
13 * for more details.
14 */
15
16 #include "auth_controller.h"
17 #include "../manager.h"
18
19 #include <library.h>
20
21
22 typedef struct private_auth_controller_t private_auth_controller_t;
23
24 /**
25 * private data of the task manager
26 */
27 struct private_auth_controller_t {
28
29 /**
30 * public functions
31 */
32 auth_controller_t public;
33
34 /**
35 * manager instance
36 */
37 manager_t *manager;
38 };
39
40 static void login(private_auth_controller_t *this, request_t *request)
41 {
42 request->set(request, "action", "check");
43 request->set(request, "title", "Login");
44 request->render(request, "templates/auth/login.cs");
45 }
46
47 static void check(private_auth_controller_t *this, request_t *request)
48 {
49 char *username, *password;
50
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))
55 {
56 request->redirect(request, "ikesa/list");
57 }
58 else
59 {
60 request->redirect(request, "auth/login");
61 }
62 }
63
64 static void logout(private_auth_controller_t *this, request_t *request)
65 {
66 this->manager->logout(this->manager);
67 request->redirect(request, "auth/login");
68 }
69
70 /**
71 * Implementation of controller_t.get_name
72 */
73 static char* get_name(private_auth_controller_t *this)
74 {
75 return "auth";
76 }
77
78 /**
79 * Implementation of controller_t.handle
80 */
81 static void handle(private_auth_controller_t *this,
82 request_t *request, char *action)
83 {
84 if (action)
85 {
86 if (streq(action, "login"))
87 {
88 return login(this, request);
89 }
90 else if (streq(action, "check"))
91 {
92 return check(this, request);
93 }
94 else if (streq(action, "logout"))
95 {
96 return logout(this, request);
97 }
98 }
99 request->redirect(request, "auth/login");
100 }
101
102 /**
103 * Implementation of controller_t.destroy
104 */
105 static void destroy(private_auth_controller_t *this)
106 {
107 free(this);
108 }
109
110 /*
111 * see header file
112 */
113 controller_t *auth_controller_create(context_t *context, void *param)
114 {
115 private_auth_controller_t *this = malloc_thing(private_auth_controller_t);
116
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;
120
121 this->manager = (manager_t*)context;
122
123 return &this->public.controller;
124 }
125