Annotation of embedaddon/strongswan/src/manager/controller/auth_controller.c, revision 1.1.1.1
1.1 misho 1: /*
2: * Copyright (C) 2007 Martin Willi
3: * HSR 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, fast_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, fast_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, fast_request_t *request)
65: {
66: this->manager->logout(this->manager);
67: request->redirect(request, "auth/login");
68: }
69:
70: METHOD(fast_controller_t, get_name, char*,
71: private_auth_controller_t *this)
72: {
73: return "auth";
74: }
75:
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)
79: {
80: if (action)
81: {
82: if (streq(action, "login"))
83: {
84: return login(this, request);
85: }
86: else if (streq(action, "check"))
87: {
88: return check(this, request);
89: }
90: else if (streq(action, "logout"))
91: {
92: return logout(this, request);
93: }
94: }
95: request->redirect(request, "auth/login");
96: }
97:
98: METHOD(fast_controller_t, destroy, void,
99: private_auth_controller_t *this)
100: {
101: free(this);
102: }
103:
104: /*
105: * see header file
106: */
107: fast_controller_t *auth_controller_create(fast_context_t *context, void *param)
108: {
109: private_auth_controller_t *this;
110:
111: INIT(this,
112: .public = {
113: .controller = {
114: .get_name = _get_name,
115: .handle = _handle,
116: .destroy = _destroy,
117: },
118: },
119: .manager = (manager_t*)context,
120: );
121:
122: return &this->public.controller;
123: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>