Skip to content

Commit

Permalink
Fix for RRISD login problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan Seifert committed Feb 28, 2014
1 parent e903b78 commit 6327ddb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion QuickHAC/QuickHAC/QuickHAC-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>2203</string>
<string>2213</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIBackgroundModes</key>
Expand Down
15 changes: 10 additions & 5 deletions QuickHAC/QuickHAC/SQUDistrictManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,13 @@ - (void) performActualLoginRequestWithUser:(NSString *) username usingPassword:(
NSURL *url = loginRequest[@"request"][@"URL"];

// Called on success of the operation (200 OK)
void (^loginSuccess)(AFHTTPRequestOperation*operation, id responseObject) = ^(AFHTTPRequestOperation*operation, id responseObject) {
[_currentDistrict updateDistrictStateWithPostLoginData:responseObject];
void (^loginSuccess)(AFHTTPRequestOperation*operation, id responseObject) = ^(AFHTTPRequestOperation*operation, id responseObject) {
NSData *data = [self fixData:responseObject];

[_currentDistrict updateDistrictStateWithPostLoginData:data];

// The server accepted our request, now check if the request succeeded
if([_currentDistrict didLoginSucceedWithLoginData:responseObject]) {
if([_currentDistrict didLoginSucceedWithLoginData:data]) {
NSMutableDictionary *response = [NSMutableDictionary new];
response[@"username"] = username;
response[@"password"] = password;
Expand Down Expand Up @@ -261,7 +263,8 @@ - (void) performLoginRequestWithUser:(NSString *) username usingPassword:(NSStri
if(preLogin) {
// Called if the pre-login succeeds
void (^preLoginSuccess)(AFHTTPRequestOperation*operation, id responseObject) = ^(AFHTTPRequestOperation*operation, id responseObject) {
[_currentDistrict updateDistrictStateWithPreLoginData:(NSData *) responseObject];
NSData *data = [self fixData:responseObject];
[_currentDistrict updateDistrictStateWithPreLoginData:data];

// Perform the actual login, as the pre log-in request was success
[self performActualLoginRequestWithUser:username usingPassword:password andCallback:callback];
Expand Down Expand Up @@ -308,8 +311,9 @@ - (void) performDisambiguationRequestWithStudentID:(NSString *) sid andCallback:

// Called if the request succeeds
void (^disambiguateSuccess)(AFHTTPRequestOperation*operation, id responseObject) = ^(AFHTTPRequestOperation*operation, id responseObject) {
NSData *data = [self fixData:responseObject];

if([_currentDistrict didDisambiguationSucceedWithLoginData:responseObject]) {
if([_currentDistrict didDisambiguationSucceedWithLoginData:data]) {
callback(nil, responseObject);
} else {
callback([NSError errorWithDomain:@"SQUDistrictManagerErrorDomain" code:kSQUDistrictManagerErrorInvalidDisambiguation userInfo:@{@"localizedDescription" : NSLocalizedString(@"The disambiguation process failed.", nil)}], nil);
Expand Down Expand Up @@ -353,6 +357,7 @@ - (NSData *) fixData:(NSData *) in {
uint8_t *bytes = (uint8_t *) data.bytes;
uint32_t spaces = 0x20202020;

// loop through all bytes
for (NSUInteger i = 0; i < data.length; i++) {
if(bytes[i] == 0x00) {
[data replaceBytesInRange:NSMakeRange(i, 1) withBytes:&spaces length:1];
Expand Down
16 changes: 6 additions & 10 deletions QuickHAC/QuickHAC/SQUDistrictRRISD.m
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,14 @@ - (void) updateDistrictStateWithPreLoginData:(NSData *) data {

// Set up a parser
TFHpple *parser = [TFHpple hppleWithHTMLData:data];
TFHppleElement *form = [parser searchWithXPathQuery:@"//form[@name='aspnetForm']"][0];

// Find children of the form
NSArray *formChildren = [form childrenWithTagName:@"input"];
// Find required elements
TFHppleElement *viewState = [parser peekAtSearchWithXPathQuery:@"//*[@id=\"__VIEWSTATE\"]"];
TFHppleElement *eventValidation = [parser peekAtSearchWithXPathQuery:@"//*[@id=\"__EVENTVALIDATION\"]"];

for (TFHppleElement *input in formChildren) {
if([input[@"name"] isEqualToString:@"__VIEWSTATE"]) {
_loginASPNetInfo[@"__VIEWSTATE"] = input[@"value"];
} else if([input[@"name"] isEqualToString:@"__EVENTVALIDATION"]) {
_loginASPNetInfo[@"__EVENTVALIDATION"] = input[@"value"];
}
}
// Get their value
_loginASPNetInfo[@"__VIEWSTATE"] = viewState[@"value"];
_loginASPNetInfo[@"__EVENTVALIDATION"] = eventValidation[@"value"];
}

/*
Expand Down
2 changes: 1 addition & 1 deletion QuickHAC/QuickHAC/SQULoginViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ - (void) performAuthentication:(id) sender {

// Restore old student state
if(oldStudent) {
NSLog(@"Restoring student: %@", oldStudent);
// NSLog(@"Restoring student: %@", oldStudent);

[[SQUDistrictManager sharedInstance] selectDistrictWithID:oldStudent.district.integerValue];
[[SQUGradeManager sharedInstance] setStudent:oldStudent];
Expand Down

0 comments on commit 6327ddb

Please sign in to comment.