]> err.no Git - scalable-opengroupware.org/blob - UI/MainUI/SOGoRootPage.m
bb696b81a59b93e0afaad9ebe60c1fc993d25efe
[scalable-opengroupware.org] / UI / MainUI / SOGoRootPage.m
1 /*
2   Copyright (C) 2004-2005 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21
22 #import <NGObjWeb/WOApplication.h>
23 #import <NGObjWeb/WOContext.h>
24 #import <NGObjWeb/WOCookie.h>
25 #import <NGObjWeb/WORequest.h>
26 #import <NGObjWeb/WOResponse.h>
27
28 #import <NGExtensions/NGBase64Coding.h>
29 #import <NGExtensions/NSNull+misc.h>
30 #import <NGExtensions/NSString+misc.h>
31 #import <NGExtensions/NSObject+Logs.h>
32
33 #import <SoObjects/SOGo/SOGoWebAuthenticator.h>
34 #import <SoObjects/SOGo/SOGoUser.h>
35
36 #import "SOGoRootPage.h"
37
38 @implementation SOGoRootPage
39
40 - (void) dealloc
41 {
42   [userName release];
43   [super dealloc];
44 }
45
46 /* accessors */
47
48 - (void) setUserName: (NSString *) _value
49 {
50   ASSIGNCOPY (userName, _value);
51 }
52
53 - (NSString *) userName
54 {
55   return userName;
56 }
57
58 - (NSString *) connectURL
59 {
60   return [NSString stringWithFormat: @"%@connect", [self applicationPath]];
61 }
62
63 /* actions */
64 - (id <WOActionResults>) connectAction
65 {
66   WOResponse *response;
67   WORequest *request;
68   WOCookie *authCookie;
69   SOGoWebAuthenticator *auth;
70   NSString *cookieValue, *cookieString;
71
72   auth = [[WOApplication application]
73            authenticatorInContext: context];
74   request = [context request];
75   response = [self responseWith204];
76   cookieString = [NSString stringWithFormat: @"%@:%@",
77                            [request formValueForKey: @"userName"],
78                            [request formValueForKey: @"password"]];
79   cookieValue = [NSString stringWithFormat: @"basic %@",
80                           [cookieString stringByEncodingBase64]];
81   authCookie = [WOCookie cookieWithName: [auth cookieNameInContext: context]
82                          value: cookieValue];
83   [authCookie setPath: @"/"];
84   [response addCookie: authCookie];
85
86   return response;
87 }
88
89 - (id <WOActionResults>) defaultAction
90 {
91   id <WOActionResults> response;
92   NSString *login, *oldLocation;
93
94   login = [[context activeUser] login];
95   if (!login || [login isEqualToString: @"anonymous"])
96     response = self;
97   else
98     {
99       oldLocation = [[self clientObject] baseURLInContext: context];
100       response
101         = [self redirectToLocation: [NSString stringWithFormat: @"%@/%@",
102                                               oldLocation, login]];
103     }
104
105   return response;
106 }
107
108 - (BOOL) isPublicInContext: (WOContext *) localContext
109 {
110   return YES;
111 }
112
113 @end /* SOGoRootPage */