|
From: Geisschaes <gei...@us...> - 2005-03-27 12:24:14
|
Update of /cvsroot/macattrick/macattrick In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26265 Modified Files: HattrickOrg.h HattrickOrg.m LoginController.m Log Message: if login failes, a message is displayed Index: LoginController.m =================================================================== RCS file: /cvsroot/macattrick/macattrick/LoginController.m,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** LoginController.m 27 Feb 2005 15:14:44 -0000 1.13 --- LoginController.m 27 Mar 2005 12:23:33 -0000 1.14 *************** *** 62,71 **** [[HattrickOrg uniqueInstance] setServerName:serverName]; [[HattrickOrg uniqueInstance] setLoginName:loginName password:password ]; ! [[HattrickOrg uniqueInstance] loginAndDownload]; ! if ([[NSUserDefaults standardUserDefaults] boolForKey:@"savePasswordInKeychain"] && loginName && password) { ! [self savePasswordInKeychain]; ! } ! [self loadTeam]; ! [self close]; } --- 62,84 ---- [[HattrickOrg uniqueInstance] setServerName:serverName]; [[HattrickOrg uniqueInstance] setLoginName:loginName password:password ]; ! int errorCode = [[HattrickOrg uniqueInstance] loginAndDownload]; ! if(!errorCode) { // no error occured ! if ([[NSUserDefaults standardUserDefaults] boolForKey:@"savePasswordInKeychain"] && loginName && password) { ! [self savePasswordInKeychain]; ! } ! [self loadTeam]; ! [self close]; ! } ! else { ! NSString *title = NSLocalizedString(@"Login failed", @"Login failed"); ! if(errorCode == -3) { // wrong password or loginname ! NSString *wrongLogin = NSLocalizedString(@"Login to hattrick.org failed. \nWrong login or security code.", @"Login to hattrick.org failed. \nWrong login or security code."); ! NSRunAlertPanel(title,wrongLogin,@"Ok",nil,nil); ! } ! if(errorCode == -2 || errorCode == -1) { // connecting to server failed ! NSString *wrongLogin = NSLocalizedString(@"Connecting to hattrick.org failed. \nPlease check the server name and try again.", @"Connecting to hattrick.org failed. \nPlease check the server name and try again."); ! NSRunAlertPanel(title,wrongLogin,@"Ok",nil,nil); ! } ! } } Index: HattrickOrg.m =================================================================== RCS file: /cvsroot/macattrick/macattrick/HattrickOrg.m,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** HattrickOrg.m 14 Mar 2005 19:30:51 -0000 1.20 --- HattrickOrg.m 27 Mar 2005 12:23:33 -0000 1.21 *************** *** 32,36 **** @interface HattrickOrg (Private) ! -(void) download: (NSString*) urlString toFile: (NSString*) file; -(NSURLRequest*) buildRequest: (NSString*) urlString ; @end --- 32,36 ---- @interface HattrickOrg (Private) ! -(int) download: (NSString*) urlString toFile: (NSString*) file; -(NSURLRequest*) buildRequest: (NSString*) urlString ; @end *************** *** 67,71 **** - - (NSString *)loginName { return loginName; } --- 67,70 ---- *************** *** 79,169 **** } ! - (void) loginAndDownload { ! [self login]; ! [self downloadPlayers]; ! [self downloadWorldDetails]; ! [self downloadArenaDetails]; ! [self downloadClub]; ! [self downloadEconomy]; ! [self downloadLeagueDetails]; ! [self downloadTeamDetails]; ! [self downloadTraining]; ! [self logout]; } ! - (void) login { ! NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; ! NSString *urlString = [NSString stringWithFormat:@"http://%s/Common/default.asp?outputType=XML&actionType=login&loginType=CHPP&Loginname=%s&readonlypassword=%s", [serverName cString], [loginName cString], [password cString]]; ! NSError *error; ! NSURLResponse *response; ! NSData *data = [NSURLConnection sendSynchronousRequest:[self buildRequest:urlString]returningResponse:&response error:&error]; ! [[NSFileManager defaultManager] removeFileAtPath:[Properties loginFile] handler:nil]; ! [data writeToFile:[Properties loginFile] atomically:YES]; ! [pool release]; } ! - (void) logout { ! NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; ! NSString *urlString = [NSString stringWithFormat:@"http://%s/Common/default.asp?outputType=XML&actionType=logout", ! [serverName cString]]; ! NSError *error; ! NSURLResponse *response; ! NSData *data = [NSURLConnection sendSynchronousRequest:[self buildRequest:urlString]returningResponse:&response error:&error]; ! [[NSFileManager defaultManager] removeFileAtPath:[Properties logoutFile] handler:nil]; ! [data writeToFile:[Properties logoutFile] atomically:YES]; ! [pool release]; } ! -(void) downloadPlayers { ! NSString *urlString = [[NSString alloc] initWithFormat:@"http://%s/Common/players.asp?outputType=XML&actionType=view", ! [serverName cString]]; ! [self download:urlString toFile:[Properties playersFile]]; [urlString release]; } ! -(void) downloadEconomy { ! NSString *urlString = [[NSString alloc] initWithFormat:@"http://%s/Common/economy.asp?outputType=XML&actionType=view", ! [serverName cString]]; ! [self download:urlString toFile: [Properties economyFile]]; [urlString release]; } ! -(void) downloadTeamDetails { ! NSString *urlString = [[NSString alloc] initWithFormat:@"http://%s/Common/teamDetails.asp?outputType=XML&actionType=view", ! [serverName cString]]; ! [self download:urlString toFile: [Properties teamDetailsFile]]; [urlString release]; } ! -(void) downloadLeagueDetails { ! NSString *urlString = [[NSString alloc] initWithFormat:@"http://%s/Common/leagueDetails.asp?outputType=XML&actionType=view", ! [serverName cString]]; ! [self download:urlString toFile: [Properties leagueDetailsFile]]; [urlString release]; } ! -(void) downloadClub { ! NSString *urlString = [[NSString alloc] initWithFormat:@"http://%s/Common/club.asp?outputType=XML&actionType=view", ! [serverName cString]]; ! [self download:urlString toFile: [Properties clubFile]]; [urlString release]; } ! -(void) downloadArenaDetails { ! NSString *urlString = [[NSString alloc] initWithFormat:@"http://%s/Common/arenaDetails.asp?outputType=XML&actionType=view", ! [serverName cString]]; ! [self download:urlString toFile: [Properties arenaDetailsFile]]; [urlString release]; } ! -(void) downloadTraining { ! NSString *urlString = [[NSString alloc] initWithFormat:@"http://%s/Common/training.asp?outputType=XML&actionType=view", ! [serverName cString]]; ! [self download:urlString toFile: [Properties trainingFile]]; [urlString release]; } ! -(void) downloadWorldDetails { ! NSString *urlString = [[NSString alloc] initWithFormat:@"http://%s/Common/worldDetails.asp?outputType=XML&actionType=leagues", ! [serverName cString]]; ! [self download:urlString toFile: [Properties worldDetailsFile]]; [urlString release]; } --- 78,186 ---- } + - (NSString *) loginName { return loginName; } + - (void) setLoginName: (NSString *) newLoginName { + [newLoginName retain]; + [loginName release]; + loginName = newLoginName; + } ! ! - (NSString *) password { return password; } ! - (void) setPassword: (NSString *) newPassword { ! [newPassword retain]; ! [password release]; ! password = newPassword; } ! ! ! - (int) loginAndDownload { ! int errorCode = 0; ! errorCode = [self login]; if(errorCode) {return errorCode;} ! errorCode = [self downloadPlayers]; if(errorCode) {return errorCode;} ! errorCode = [self downloadWorldDetails]; if(errorCode) {return errorCode;} ! errorCode = [self downloadArenaDetails]; if(errorCode) {return errorCode;} ! errorCode = [self downloadClub]; if(errorCode) {return errorCode;} ! errorCode = [self downloadEconomy]; if(errorCode) {return errorCode;} ! errorCode = [self downloadLeagueDetails]; if(errorCode) {return errorCode;} ! errorCode = [self downloadTeamDetails]; if(errorCode) {return errorCode;} ! errorCode = [self downloadTraining]; if(errorCode) {return errorCode;} ! errorCode = [self logout]; ! return errorCode; ! } ! ! - (int) login { ! NSString *urlString = [[NSString alloc] initWithFormat:@"http://%s/Common/default.asp?outputType=XML&actionType=login&loginType=CHPP&Loginname=%s&readonlypassword=%s", [serverName cString], [loginName cString], [password cString]]; ! int error = [self download:urlString toFile:[Properties loginFile]]; ! [urlString release]; ! if(error == 0) { // download successful check if login did not failed ! NSString *successful = @"<ActionSuccessful>True</ActionSuccessful>"; ! NSString *loginFile = [[NSString alloc] initWithContentsOfFile:[Properties loginFile]]; ! NSRange range = [loginFile rangeOfString:successful]; ! if(! range.length ) { //string not found ! error = -3; ! } ! [loginFile release]; ! } ! return error; } ! - (int) logout { ! NSString *urlString = [[NSString alloc] initWithFormat:@"http://%s/Common/default.asp?outputType=XML&actionType=logout", [serverName cString]]; ! int error = [self download:urlString toFile:[Properties logoutFile]]; ! [urlString release]; ! return error; } ! -(int) downloadPlayers { ! NSString *urlString = [[NSString alloc] initWithFormat:@"http://%s/Common/players.asp?outputType=XML&actionType=view", [serverName cString]]; ! int error = [self download:urlString toFile:[Properties playersFile]]; [urlString release]; + return error; } ! -(int) downloadEconomy { ! NSString *urlString = [[NSString alloc] initWithFormat:@"http://%s/Common/economy.asp?outputType=XML&actionType=view", [serverName cString]]; ! int error = [self download:urlString toFile: [Properties economyFile]]; [urlString release]; + return error; } ! -(int) downloadTeamDetails { ! NSString *urlString = [[NSString alloc] initWithFormat:@"http://%s/Common/teamDetails.asp?outputType=XML&actionType=view", [serverName cString]]; ! int error = [self download:urlString toFile: [Properties teamDetailsFile]]; [urlString release]; + return error; } ! -(int) downloadLeagueDetails { ! NSString *urlString = [[NSString alloc] initWithFormat:@"http://%s/Common/leagueDetails.asp?outputType=XML&actionType=view", [serverName cString]]; ! int error = [self download:urlString toFile: [Properties leagueDetailsFile]]; [urlString release]; + return error; } ! -(int) downloadClub { ! NSString *urlString = [[NSString alloc] initWithFormat:@"http://%s/Common/club.asp?outputType=XML&actionType=view", [serverName cString]]; ! int error = [self download:urlString toFile: [Properties clubFile]]; [urlString release]; + return error; } ! -(int) downloadArenaDetails { ! NSString *urlString = [[NSString alloc] initWithFormat:@"http://%s/Common/arenaDetails.asp?outputType=XML&actionType=view", [serverName cString]]; ! int error = [self download:urlString toFile: [Properties arenaDetailsFile]]; [urlString release]; + return error; } ! -(int) downloadTraining { ! NSString *urlString = [[NSString alloc] initWithFormat:@"http://%s/Common/training.asp?outputType=XML&actionType=view", [serverName cString]]; ! int error = [self download:urlString toFile: [Properties trainingFile]]; [urlString release]; + return error; } ! -(int) downloadWorldDetails { ! NSString *urlString = [[NSString alloc] initWithFormat:@"http://%s/Common/worldDetails.asp?outputType=XML&actionType=leagues", [serverName cString]]; ! int error = [self download:urlString toFile: [Properties worldDetailsFile]]; [urlString release]; + return error; } *************** *** 179,190 **** // private methods ! -(void) download: (NSString*) urlString toFile: (NSString*) file { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSError *error; NSURLResponse *response; NSData *data = [NSURLConnection sendSynchronousRequest:[self buildRequest:urlString]returningResponse:&response error:&error]; ! [[NSFileManager defaultManager] removeFileAtPath:file handler:nil]; ! [data writeToFile:file atomically:YES]; [pool release]; } --- 196,217 ---- // private methods ! -(int) download: (NSString*) urlString toFile: (NSString*) file { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + int errorCode = 0; NSError *error; NSURLResponse *response; NSData *data = [NSURLConnection sendSynchronousRequest:[self buildRequest:urlString]returningResponse:&response error:&error]; ! if([error code]) { // error on sending request ! errorCode = -1; ! } ! else if(data == nil || [data length]<10){ // data not correctly fetched ! errorCode = -2; ! } ! else { ! [[NSFileManager defaultManager] removeFileAtPath:file handler:nil]; ! [data writeToFile:file atomically:YES]; ! } [pool release]; + return errorCode; } Index: HattrickOrg.h =================================================================== RCS file: /cvsroot/macattrick/macattrick/HattrickOrg.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** HattrickOrg.h 3 Oct 2004 19:26:55 -0000 1.12 --- HattrickOrg.h 27 Mar 2005 12:23:32 -0000 1.13 *************** *** 48,51 **** --- 48,58 ---- + (HattrickOrg*) uniqueInstance; + - (NSString *) loginName; + - (void) setLoginName: (NSString *) newLoginName; + - (NSString *) password; + - (void) setPassword: (NSString *) newPassword; + + + - (NSString *)serverName; /*! @method setServerName: *************** *** 64,68 **** @abstract login to the hattrick.org page to enable fetching data */ ! - (void) login; /*! --- 71,75 ---- @abstract login to the hattrick.org page to enable fetching data */ ! - (int) login; /*! *************** *** 70,74 **** @abstract logout of the hattrick.org page to disable fetching data */ ! - (void) logout; /*! --- 77,81 ---- @abstract logout of the hattrick.org page to disable fetching data */ ! - (int) logout; /*! *************** *** 77,81 **** @discussion first login is executed. then all download methods are called. at the end, logout is performed */ ! - (void) loginAndDownload; /*! --- 84,88 ---- @discussion first login is executed. then all download methods are called. at the end, logout is performed */ ! - (int) loginAndDownload; /*! *************** *** 85,89 **** outputType=XML&actionType=view */ ! -(void) downloadPlayers; /*! --- 92,96 ---- outputType=XML&actionType=view */ ! -(int) downloadPlayers; /*! *************** *** 93,97 **** outputType=XML&actionType=view */ ! -(void) downloadEconomy; --- 100,104 ---- outputType=XML&actionType=view */ ! -(int) downloadEconomy; *************** *** 102,106 **** outputType=XML&actionType=view */ ! -(void) downloadTeamDetails; /*! --- 109,113 ---- outputType=XML&actionType=view */ ! -(int) downloadTeamDetails; /*! *************** *** 110,114 **** outputType=XML&actionType=view */ ! -(void) downloadLeagueDetails; /*! --- 117,121 ---- outputType=XML&actionType=view */ ! -(int) downloadLeagueDetails; /*! *************** *** 118,122 **** outputType=XML&actionType=view */ ! -(void) downloadClub; /*! --- 125,129 ---- outputType=XML&actionType=view */ ! -(int) downloadClub; /*! *************** *** 126,130 **** outputType=XML&actionType=view */ ! -(void) downloadArenaDetails; /*! --- 133,137 ---- outputType=XML&actionType=view */ ! -(int) downloadArenaDetails; /*! *************** *** 134,138 **** outputType=XML&actionType=view */ ! -(void) downloadTraining; /*! --- 141,145 ---- outputType=XML&actionType=view */ ! -(int) downloadTraining; /*! *************** *** 142,146 **** outputType=XML&actionType=leagues */ ! -(void) downloadWorldDetails; @end --- 149,153 ---- outputType=XML&actionType=leagues */ ! -(int) downloadWorldDetails; @end |