]> err.no Git - scalable-opengroupware.org/blob - UI/MainUI/SOGoRootPage.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1170 d1b88da0-ebda-0310...
[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 #import <NGExtensions/NGBase64Coding.h>
28 #import <NGExtensions/NSNull+misc.h>
29 #import <NGExtensions/NSString+misc.h>
30 #import <NGExtensions/NSObject+Logs.h>
31
32 #import <SoObjects/SOGo/SOGoWebAuthenticator.h>
33 #import <SoObjects/SOGo/SOGoUser.h>
34
35 #import "SOGoRootPage.h"
36
37 @implementation SOGoRootPage
38
39 - (void) dealloc
40 {
41   [userName release];
42   [super dealloc];
43 }
44
45 /* accessors */
46
47 - (void) setUserName: (NSString *) _value
48 {
49   ASSIGNCOPY (userName, _value);
50 }
51
52 - (NSString *) userName
53 {
54   return userName;
55 }
56
57 - (NSString *) connectURL
58 {
59   return [NSString stringWithFormat: @"%@connect", [self applicationPath]];
60 }
61
62 /* actions */
63 - (id <WOActionResults>) connectAction
64 {
65   WOResponse *response;
66   WOCookie *authCookie;
67   SOGoWebAuthenticator *auth;
68   NSString *cookieValue, *cookieString;
69
70   auth = [[WOApplication application]
71            authenticatorInContext: context];
72   response = [context response];
73   cookieString = [NSString stringWithFormat: @"%@:%@",
74                            [self queryParameterForKey: @"userName"],
75                            [self queryParameterForKey: @"password"]];
76   cookieValue = [NSString stringWithFormat: @"basic%@",
77                           [cookieString stringByEncodingBase64]];
78   authCookie = [WOCookie cookieWithName: [auth cookieNameInContext: context]
79                          value: cookieValue];
80   [authCookie setPath: @"/"];
81   [response setStatus: 204];
82   [response addCookie: authCookie];
83
84   return response;
85 }
86
87 // - (id <WOActionResults>) defaultAction
88 // {
89 //   WOResponse *r;
90 //   NSString *login, *rhk;
91 //   SOGoWebAuthenticator *auth;
92 //   SOGoUser *user;
93 //   SOGoUserFolder *home;
94 //   WOApplication *base;
95
96 //   /* 
97 //      Note: ctx.activeUser is NOT set here. Don't know why, so we retrieve
98 //            the user from the authenticator.
99 //   */
100   
101 //   auth = [[self clientObject] authenticatorInContext: context];
102 //   user = [auth userInContext: context];
103 //   login = [user login];
104
105 //   if ([login isEqualToString:@"anonymous"]) {
106 //     /* use root page for unauthenticated users */
107 //     return self;
108 //   }
109
110 //   /* check base */
111
112 //   base = [self application];
113 //   rhk = [[context request] requestHandlerKey];
114 //   if (([rhk length] == 0) || ([base requestHandlerForKey:rhk] == nil)) {
115 //     base = [base lookupName: @"so" inContext: context acquire: NO];
116     
117 //     if (![base isNotNull] || [base isKindOfClass:[NSException class]]) {
118 //       /* use root page if home could not be found */
119 //       [self errorWithFormat:@"Did not find 'so' request handler!"];
120 //       return self;
121 //     }
122 //   }
123   
124 //   /* lookup home-page */
125
126 //   home = [base lookupName: login inContext: context acquire: NO];
127 //   if (![home isNotNull] || [home isKindOfClass:[NSException class]]) {
128 //     /* use root page if home could not be found */
129 //     return self;
130 //   }
131   
132 //   /* redirect to home-page */
133   
134 //   r = [context response];
135 //   [r setStatus: 302 /* moved */];
136 //   [r setHeader: [home baseURLInContext: context]
137 //      forKey: @"location"];
138
139 //   return r;
140 // }
141
142 /* response generation */
143
144 // - (void) appendToResponse: (WOResponse *) response
145 //              inContext: (WOContext *) ctx
146 // {
147 //   NSString *rhk;
148
149 //   // TODO: we might also want to look into the HTTP basic-auth to redirect to
150 //   //       the login URL!
151   
152 //   rhk = [[ctx request] requestHandlerKey];
153 //   if ([rhk length] == 0
154 //       || [[self application] requestHandlerForKey: rhk] == nil)
155 //     {
156 //       /* a small hack to redirect to a valid URL */
157 //       NSString *url;
158     
159 //       url = [ctx urlWithRequestHandlerKey: @"so" path: @"/" queryString: nil];
160 //       [response setStatus: 302 /* moved */];
161 //       [response setHeader: url forKey: @"location"];
162 //       [self logWithFormat: @"URL: %@", url];
163 //       return;
164 //     }
165
166 //   [response setHeader: @"text/html" forKey: @"content-type"];
167 //   [super appendToResponse: response inContext: ctx];
168 // }
169
170 - (BOOL) isPublicInContext: (WOContext *) localContext
171 {
172   return YES;
173 }
174
175 @end /* SOGoRootPage */