2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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
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.
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
22 #include <NGObjWeb/SoComponent.h>
24 @interface SOGoRootPage : SoComponent
31 #include <SOGo/SOGoAuthenticator.h>
34 @implementation SOGoRootPage
36 static BOOL doNotRedirect = NO;
39 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
41 if ((doNotRedirect = [ud boolForKey:@"SOGoDoNotRedirectRootPage"]))
42 NSLog(@"SOGoRootPage: home-page redirect is disabled.");
46 [self->userName release];
52 - (void)setUserName:(NSString *)_value {
53 ASSIGNCOPY(self->userName, _value);
55 - (NSString *)userName {
56 return self->userName;
64 [self takeFormValuesForKeys:@"userName", nil];
66 if ([[self userName] length] == 0)
69 url = [@"/" stringByAppendingString:[[self userName] stringByEscapingURL]];
70 if (![url hasSuffix:@"/"])
71 url = [url stringByAppendingString:@"/"];
73 url = [[self context] urlWithRequestHandlerKey:@"so"
74 path:url queryString:nil];
75 return [self redirectToLocation:url];
78 - (id<WOActionResults>)defaultAction {
80 NSString *login, *rhk;
88 Note: ctx.activeUser is NOT set here. Don't know why, so we retrieve
89 the user from the authenticator.
92 auth = [[self clientObject] authenticatorInContext:[self context]];
93 user = [auth userInContext:[self context]];
96 if ([login isEqualToString:@"anonymous"]) {
97 /* use root page for unauthenticated users */
103 base = [self application];
104 rhk = [[[self context] request] requestHandlerKey];
105 if (([rhk length] == 0) || ([base requestHandlerForKey:rhk] == nil)) {
106 base = [base lookupName:@"so" inContext:[self context] acquire:NO];
108 if (![base isNotNull] || [base isKindOfClass:[NSException class]]) {
109 /* use root page if home could not be found */
110 [self errorWithFormat:@"Did not find 'so' request handler!"];
115 /* lookup home-page */
117 home = [base lookupName:login inContext:[self context] acquire:NO];
118 if (![home isNotNull] || [home isKindOfClass:[NSException class]]) {
119 /* use root page if home could not be found */
123 /* redirect to home-page */
125 r = [[self context] response];
126 [r setStatus:302 /* moved */];
127 [r setHeader:[home baseURLInContext:[self context]] forKey:@"location"];
131 /* response generation */
133 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
136 // TODO: we might also want to look into the HTTP basic-auth to redirect to
139 rhk = [[_ctx request] requestHandlerKey];
140 if ([rhk length]==0 || [[self application] requestHandlerForKey:rhk]==nil) {
141 /* a small hack to redirect to a valid URL */
144 url = [_ctx urlWithRequestHandlerKey:@"so" path:@"/" queryString:nil];
145 [_response setStatus:302 /* moved */];
146 [_response setHeader:url forKey:@"location"];
147 [self logWithFormat:@"URL: %@", url];
151 [super appendToResponse:_response inContext:_ctx];
154 @end /* SOGoRootPage */