2 Copyright (C) 2000-2004 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
23 #include "iCalPortalPage.h"
24 #include <NGObjWeb/WODirectAction.h>
26 @interface iCalPortalRegistrationPage : iCalPortalPage
38 NSString *wantIcalNews;
39 NSString *wantSkyrixNews;
49 - (void)markLoginWrong;
50 - (void)markLoginUsed;
52 - (void)markFirstNameWrong;
53 - (void)markLastNameWrong;
54 - (void)markEmailWrong;
58 @interface iCalPortalRegistrationAction : WODirectAction
63 @interface NSString(EmailAddress)
64 - (BOOL)isValidEmailAddress;
67 @implementation iCalPortalRegistrationPage
70 if ((self = [super init])) {
72 self->loginAvailable = YES;
74 self->firstNameOK = YES;
75 self->lastNameOK = YES;
82 [self->login release];
83 [self->firstName release];
84 [self->lastName release];
85 [self->email release];
86 [self->address release];
88 [self->state release];
90 [self->country release];
91 [self->phone release];
92 [self->wantIcalNews release];
93 [self->wantSkyrixNews release];
99 - (void)setLogin:(NSString *)_value {
100 ASSIGN(self->login, _value);
102 - (NSString *)login {
106 - (void)setFirstName:(NSString *)_value {
107 ASSIGN(self->firstName, _value);
109 - (NSString *)firstName {
110 return self->firstName;
113 - (void)setLastName:(NSString *)_value {
114 ASSIGN(self->lastName, _value);
116 - (NSString *)lastName {
117 return self->lastName;
120 - (void)setEmail:(NSString *)_value {
121 ASSIGN(self->email, _value);
123 - (NSString *)email {
127 - (void)setAddress:(NSString *)_value {
128 ASSIGN(self->address, _value);
130 - (NSString *)address {
131 return self->address;
134 - (void)setCity:(NSString *)_value {
135 ASSIGN(self->city, _value);
141 - (void)setState:(NSString *)_value {
142 ASSIGN(self->state, _value);
144 - (NSString *)state {
148 - (void)setZip:(NSString *)_value {
149 ASSIGN(self->zip, _value);
155 - (void)setCountry:(NSString *)_value {
156 ASSIGN(self->country, _value);
158 - (NSString *)country {
159 return self->country;
162 - (void)setPhone:(NSString *)_value {
163 ASSIGN(self->phone, _value);
165 - (NSString *)phone {
169 - (void)setWantIcalNews:(NSString *)_value {
170 ASSIGN(self->wantIcalNews, _value);
172 - (NSString *)wantIcalNews {
173 return self->wantIcalNews;
176 - (void)setWantSkyrixNews:(NSString *)_value {
177 ASSIGN(self->wantSkyrixNews, _value);
179 - (NSString *)wantSkyrixNews {
180 return self->wantSkyrixNews;
183 - (void)markLoginWrong {
187 return !self->loginOK;
189 - (void)markLoginUsed {
190 self->loginAvailable = NO;
193 return !self->loginAvailable;
195 - (void)markPwdWrong {
201 - (void)markFirstNameWrong {
202 self->firstNameOK = NO;
204 - (BOOL)firstNameWrong {
205 return !self->firstNameOK;
207 - (void)markLastNameWrong {
208 self->lastNameOK = NO;
210 - (BOOL)lastNameWrong {
211 return !self->lastNameOK;
213 - (void)markEmailWrong {
217 return !self->emailOK;
227 - (BOOL)isSessionProtectedPage {
235 @end /* iCalPortalRegistrationPage */
237 #include "iCalPortalUser.h"
238 #include "iCalPortalDatabase.h"
240 @implementation iCalPortalRegistrationAction
242 - (NSMutableDictionary *)collectFormValues {
243 static NSString *keys[] = {
244 /* do not add passwords here !! */
259 NSMutableDictionary *md;
264 md = [NSMutableDictionary dictionaryWithCapacity:16];
267 for (i = 0; (key = keys[i]) != nil; i++) {
270 val = [rq formValueForKey:key];
272 [md setObject:val forKey:key];
279 iCalPortalRegistrationPage *page;
280 iCalPortalDatabase *db;
281 NSMutableDictionary *values;
284 BOOL loginAvailable = YES;
286 BOOL firstNameOK = YES;
287 BOOL lastNameOK = YES;
290 if ((db = [(id)[WOApplication application] database]) == nil)
293 values = [self collectFormValues];
297 tmp = [values objectForKey:@"login"];
298 if ((loginOK = [db isLoginNameValid:tmp]))
299 loginAvailable = [db isLoginNameUsed:tmp] ? NO : YES;
301 /* validate password */
303 tmp = [[self request] formValueForKey:@"pwd1"];
304 if ((pwdOK = [db isPasswordValid:tmp])) {
307 if ((tmp2 = [[self request] formValueForKey:@"pwd2"])) {
308 if (![tmp2 isEqualToString:tmp])
317 tmp = [values objectForKey:@"firstName"];
318 if ([tmp length] < 3) firstNameOK = NO;
319 tmp = [values objectForKey:@"lastName"];
320 if ([tmp length] < 3) lastNameOK = NO;
324 emailOK = [[values objectForKey:@"email"] isValidEmailAddress];
328 if (loginOK&&loginAvailable&&pwdOK&&firstNameOK&&lastNameOK&&emailOK) {
329 iCalPortalUser *user = nil;
330 NSString *pwd = nil, *login = nil;
332 pwd = [[self request] formValueForKey:@"pwd1"];
334 login = [values objectForKey:@"login"];
336 if ([db createUser:login info:values password:pwd]) {
337 [self logWithFormat:@"did create account: %@ ...", login];
339 user = [db userWithName:[values objectForKey:@"login"] password:pwd];
341 [self logWithFormat:@"login of created account failed ?! (user=%@)",
345 [[self session] setObject:user forKey:@"user"];
346 return [[self pageWithName:@"iCalPortalHomePage"] performPage];
350 [self logWithFormat:@"failed to create account: %@ ...", user];
354 page = [self pageWithName:@"iCalPortalRegistrationPage"];
356 [page takeValuesFromDictionary:values];
358 if (!loginOK) [page markLoginWrong];
359 if (!loginAvailable) [page markLoginUsed];
360 if (!pwdOK) [page markPwdWrong];
361 if (!firstNameOK) [page markFirstNameWrong];
362 if (!lastNameOK) [page markLastNameWrong];
363 if (!emailOK) [page markEmailWrong];
365 return [page performPage];
368 - (id)saveProfileAction {
369 if ([[[self request] formValueForKey:@"action"] isEqualToString:@"save"])
370 return [self saveProfile];
372 return [self indexPage];
375 @end /* iCalPortalRegistrationAction */
377 @implementation NSString(EmailAddress)
379 - (BOOL)isValidEmailAddress {
382 if ([self length] < 3)
386 static NSString *forbiddenOnes[] = {
389 @"steve.jobs@apple.com",
392 @"bill.gates@microsoft",
399 for (i = 0; (tmp = forbiddenOnes[i]) != nil; i++) {
400 if ([self rangeOfString:tmp].length > 0) {
401 [self logWithFormat:@"someone tried '%@' ...", tmp];
408 r = [tmp rangeOfString:@"@"];
411 else if (r.location < 2)
414 tmp = [tmp substringFromIndex:(r.location + r.length)];
415 r = [tmp rangeOfString:@"."];
418 else if (r.location == 0)
421 tmp = [tmp substringFromIndex:(r.location + r.length)];
422 emailOK = [tmp length] > 1;
429 @end /* NSString(EmailAddress) */