]> err.no Git - scalable-opengroupware.org/blob - UI/MainUI/SOGoRootPage.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1173 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 = [self responseWith204];
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 addCookie: authCookie];
82
83   return response;
84 }
85
86 - (id <WOActionResults>) defaultAction
87 {
88   id <WOActionResults> response;
89   NSString *login, *oldLocation;
90
91   login = [[context activeUser] login];
92   if ([login isEqualToString: @"anonymous"])
93     response = self;
94   else
95     {
96       oldLocation = [[self clientObject] baseURLInContext: context];
97       response
98         = [self redirectToLocation: [NSString stringWithFormat: @"%@/%@",
99                                               oldLocation, login]];
100     }
101
102   return response;
103 }
104
105 - (BOOL) isPublicInContext: (WOContext *) localContext
106 {
107   return YES;
108 }
109
110 @end /* SOGoRootPage */