-// $Id$
+/*
+ Copyright (C) 2004-2005 SKYRIX Software AG
+
+ This file is part of OpenGroupware.org.
+
+ OGo is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with OGo; see the file COPYING. If not, write to the
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*/
#include <NGObjWeb/SoComponent.h>
@end
+#include <SOGo/SOGoAuthenticator.h>
#include "common.h"
@implementation SOGoRootPage
-- (id)initWithContext:(id)_ctx {
- if ((self = [super initWithContext:_ctx])) {
- }
- return self;
+static BOOL doNotRedirect = NO;
+
++ (void)initialize {
+ NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
+
+ if ((doNotRedirect = [ud boolForKey:@"SOGoDoNotRedirectRootPage"]))
+ NSLog(@"SOGoRootPage: home-page redirect is disabled.");
}
- (void)dealloc {
return [self redirectToLocation:url];
}
+- (id)defaultAction {
+ WOResponse *r;
+ NSString *login, *rhk;
+ id auth, user;
+ id home, base;
+
+ if (doNotRedirect)
+ return self;
+
+ /*
+ Note: ctx.activeUser is NOT set here. Don't know why, so we retrieve
+ the user from the authenticator.
+ */
+
+ auth = [[self clientObject] authenticatorInContext:[self context]];
+ user = [auth userInContext:[self context]];
+ login = [user login];
+
+ if ([login isEqualToString:@"anonymous"]) {
+ /* use root page for unauthenticated users */
+ return self;
+ }
+
+ /* check base */
+
+ base = [self application];
+ rhk = [[[self context] request] requestHandlerKey];
+ if (([rhk length] == 0) || ([base requestHandlerForKey:rhk] == nil)) {
+ base = [base lookupName:@"so" inContext:[self context] acquire:NO];
+
+ if (![base isNotNull] || [base isKindOfClass:[NSException class]]) {
+ /* use root page if home could not be found */
+ [self errorWithFormat:@"Did not find 'so' request handler!"];
+ return self;
+ }
+ }
+
+ /* lookup home-page */
+
+ home = [base lookupName:login inContext:[self context] acquire:NO];
+ if (![home isNotNull] || [home isKindOfClass:[NSException class]]) {
+ /* use root page if home could not be found */
+ return self;
+ }
+
+ /* redirect to home-page */
+
+ r = [[self context] response];
+ [r setStatus:302 /* moved */];
+ [r setHeader:[home baseURLInContext:[self context]] forKey:@"location"];
+ return r;
+}
+
/* response generation */
- (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {