~ubuntu-branches/ubuntu/edgy/sope/edgy

« back to all changes in this revision

Viewing changes to sope-appserver/samples/iCalPortal/Pages/iCalPortalWelcomePage.m

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Ley
  • Date: 2005-08-19 16:53:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050819165331-hs683wz1osm708pw
Tags: upstream-4.4rc.2
ImportĀ upstreamĀ versionĀ 4.4rc.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2000-2005 SKYRIX Software AG
 
3
 
 
4
  This file is part of SOPE.
 
5
 
 
6
  SOPE 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
  SOPE 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 SOPE; 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
#include <NGObjWeb/WOComponent.h>
 
23
#include <NGObjWeb/WODirectAction.h>
 
24
 
 
25
@interface iCalPortalWelcomePage : WOComponent
 
26
{
 
27
}
 
28
 
 
29
@end
 
30
 
 
31
@interface iCalPortalWelcomeAction : WODirectAction
 
32
@end
 
33
 
 
34
#include "iCalPortalUser.h"
 
35
#include "iCalPortalDatabase.h"
 
36
#include "common.h"
 
37
 
 
38
@implementation iCalPortalWelcomePage
 
39
 
 
40
- (void)dealloc {
 
41
  [super dealloc];
 
42
}
 
43
 
 
44
/* accessors */
 
45
 
 
46
/* actions */
 
47
 
 
48
- (BOOL)isSessionProtectedPage {
 
49
  return NO;
 
50
}
 
51
 
 
52
- (id)run {
 
53
  return self;
 
54
}
 
55
- (id)performPage {
 
56
  return [self run];
 
57
}
 
58
 
 
59
@end /* iCalPortalWelcomePage */
 
60
 
 
61
@implementation iCalPortalWelcomeAction
 
62
 
 
63
- (BOOL)redirectOnLogin {
 
64
  return NO;
 
65
}
 
66
 
 
67
- (id)loginAction {
 
68
  NSString           *login, *pwd;
 
69
  iCalPortalDatabase *db;
 
70
  iCalPortalUser     *user;
 
71
  
 
72
  db = [(id)[WOApplication application] database];
 
73
  
 
74
  login = [[self request] formValueForKey:@"user"];
 
75
  pwd   = [[self request] formValueForKey:@"pwd"];
 
76
  
 
77
  if (![db isLoginNameValid:login]) {
 
78
    [self logWithFormat:@"tried an invalid login: '%@'", login];
 
79
    return [self indexPage];
 
80
  }
 
81
  
 
82
  if ((user = [db userWithName:login password:pwd]) == nil) {
 
83
    [self logWithFormat:@"login failed: '%@'", login];
 
84
    return [self indexPage];
 
85
  }
 
86
  
 
87
  [self logWithFormat:@"user %@ is logged in.", login];
 
88
  [[self session] setObject:user forKey:@"user"];
 
89
  
 
90
  /* check language */
 
91
  {
 
92
    NSString *lang;
 
93
    
 
94
    if ((lang = [[self request] formValueForKey:@"language"])) {
 
95
      NSMutableArray *langs;
 
96
 
 
97
      if ([lang isEqualToString:@"en"])
 
98
        lang = @"English";
 
99
      else if ([lang isEqualToString:@"de"])
 
100
        lang = @"German";
 
101
      
 
102
      langs = [NSMutableArray arrayWithCapacity:16];
 
103
      [langs addObject:lang];
 
104
      [langs addObject:[[self session] languages]];
 
105
      [[self session] setLanguages:langs];
 
106
    }
 
107
  }
 
108
  
 
109
  /* deliver login result */
 
110
  
 
111
  if ([self redirectOnLogin]) {
 
112
    /* make a redirect on login (better for deployment) ... */
 
113
    WOResponse   *r;
 
114
    NSString     *homeURL;
 
115
    NSDictionary *qd;
 
116
 
 
117
    qd = [NSDictionary dictionaryWithObject:[[self session] sessionID]
 
118
                       forKey:WORequestValueSessionID];
 
119
    
 
120
    homeURL = [[[WOApplication application] context] 
 
121
                               directActionURLForActionNamed:@"home"
 
122
                               queryDictionary:qd];
 
123
    
 
124
    r = [WOResponse responseWithRequest:[self request]];
 
125
    [r setStatus:302];
 
126
    [r setHeader:homeURL forKey:@"location"];
 
127
    return r;
 
128
  }
 
129
  else {
 
130
    /* better for development */
 
131
    return [[self pageWithName:@"iCalPortalHomePage"] performPage];
 
132
  }
 
133
}
 
134
 
 
135
@end /* iCalPortalWelcomeAction */