From ab2bd7c4e341f937ba4b44077afb0a7c3615ce71 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 6 Sep 2007 22:21:16 +0000 Subject: [PATCH] Monotone-Parent: 84bc6f895c1a0b4e4455df229813dc1774f0be43 Monotone-Revision: 058f5a310b6bec2478c767650e3d9f8b2a304022 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-09-06T22:21:16 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 8 ++ UI/MainUI/SOGoRootPage.m | 179 +++++++++++++++++++++++---------------- 2 files changed, 112 insertions(+), 75 deletions(-) diff --git a/ChangeLog b/ChangeLog index f585510f5..0e01f6c97 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2007-09-06 Wolfgang Sourdeau + * UI/MainUI/SOGoRootPage.m ([-defaultAction]): commented out. + ([-appendToResponse:responseinContext:ctx]): commented out. + ([SOGoRootPage -connectURL]): new accessor that returns the full + url the the "connect" method. + ([-connectAction]): rewrote method to return a properly formatted + auth. cookie based on the username and password passed as + parameter. + * UI/MainUI/SOGoUserHomePage.m ([SOGoUserHomePage -logoffAction]): set the value of the cookie to "discard" and set its expiration date to yesterday. diff --git a/UI/MainUI/SOGoRootPage.m b/UI/MainUI/SOGoRootPage.m index f99b4e9e9..c88e9af4f 100644 --- a/UI/MainUI/SOGoRootPage.m +++ b/UI/MainUI/SOGoRootPage.m @@ -24,6 +24,7 @@ #import #import #import +#import #import #import #import @@ -53,90 +54,118 @@ return userName; } -/* actions */ - -- (id ) defaultAction +- (NSString *) connectURL { - WOResponse *r; - NSString *login, *rhk; - SOGoWebAuthenticator *auth; - SOGoUser *user; - SOGoUserFolder *home; - WOApplication *base; - - /* - Note: ctx.activeUser is NOT set here. Don't know why, so we retrieve - the user from the authenticator. - */ - - auth = [[self clientObject] authenticatorInContext: context]; - user = [auth userInContext: context]; - login = [user login]; - - if ([login isEqualToString:@"anonymous"]) { - /* use root page for unauthenticated users */ - return self; - } - - /* check base */ - - base = [self application]; - rhk = [[context request] requestHandlerKey]; - if (([rhk length] == 0) || ([base requestHandlerForKey:rhk] == nil)) { - base = [base lookupName: @"so" inContext: 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: 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 = [context response]; - [r setStatus: 302 /* moved */]; - [r setHeader: [home baseURLInContext: context] - forKey: @"location"]; - - return r; + return [NSString stringWithFormat: @"%@connect", [self applicationPath]]; } +/* actions */ +- (id ) connectAction +{ + WOResponse *response; + WOCookie *authCookie; + SOGoWebAuthenticator *auth; + NSString *cookieValue, *cookieString; + + auth = [[WOApplication application] + authenticatorInContext: context]; + response = [context response]; + cookieString = [NSString stringWithFormat: @"%@:%@", + [self queryParameterForKey: @"userName"], + [self queryParameterForKey: @"password"]]; + cookieValue = [NSString stringWithFormat: @"basic%@", + [cookieString stringByEncodingBase64]]; + authCookie = [WOCookie cookieWithName: [auth cookieNameInContext: context] + value: cookieValue]; + [authCookie setPath: @"/"]; + [response setStatus: 204]; + [response addCookie: authCookie]; + + return response; +} + +// - (id ) defaultAction +// { +// WOResponse *r; +// NSString *login, *rhk; +// SOGoWebAuthenticator *auth; +// SOGoUser *user; +// SOGoUserFolder *home; +// WOApplication *base; + +// /* +// Note: ctx.activeUser is NOT set here. Don't know why, so we retrieve +// the user from the authenticator. +// */ + +// auth = [[self clientObject] authenticatorInContext: context]; +// user = [auth userInContext: context]; +// login = [user login]; + +// if ([login isEqualToString:@"anonymous"]) { +// /* use root page for unauthenticated users */ +// return self; +// } + +// /* check base */ + +// base = [self application]; +// rhk = [[context request] requestHandlerKey]; +// if (([rhk length] == 0) || ([base requestHandlerForKey:rhk] == nil)) { +// base = [base lookupName: @"so" inContext: 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: 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 = [context response]; +// [r setStatus: 302 /* moved */]; +// [r setHeader: [home baseURLInContext: context] +// forKey: @"location"]; + +// return r; +// } + /* response generation */ -- (void) appendToResponse: (WOResponse *) response - inContext: (WOContext *) ctx -{ - NSString *rhk; +// - (void) appendToResponse: (WOResponse *) response +// inContext: (WOContext *) ctx +// { +// NSString *rhk; - // TODO: we might also want to look into the HTTP basic-auth to redirect to - // the login URL! +// // TODO: we might also want to look into the HTTP basic-auth to redirect to +// // the login URL! - rhk = [[ctx request] requestHandlerKey]; - if ([rhk length] == 0 - || [[self application] requestHandlerForKey: rhk] == nil) - { - /* a small hack to redirect to a valid URL */ - NSString *url; +// rhk = [[ctx request] requestHandlerKey]; +// if ([rhk length] == 0 +// || [[self application] requestHandlerForKey: rhk] == nil) +// { +// /* a small hack to redirect to a valid URL */ +// NSString *url; - url = [ctx urlWithRequestHandlerKey: @"so" path: @"/" queryString: nil]; - [response setStatus: 302 /* moved */]; - [response setHeader: url forKey: @"location"]; - [self logWithFormat: @"URL: %@", url]; - return; - } +// url = [ctx urlWithRequestHandlerKey: @"so" path: @"/" queryString: nil]; +// [response setStatus: 302 /* moved */]; +// [response setHeader: url forKey: @"location"]; +// [self logWithFormat: @"URL: %@", url]; +// return; +// } - [response setHeader: @"text/html" forKey: @"content-type"]; - [super appendToResponse: response inContext: ctx]; -} +// [response setHeader: @"text/html" forKey: @"content-type"]; +// [super appendToResponse: response inContext: ctx]; +// } - (BOOL) isPublicInContext: (WOContext *) localContext {