Commit 1426059d authored by Alex Moore's avatar Alex Moore

increased login button size, ran quick tests

parent 5e284abd
......@@ -17,7 +17,10 @@
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//Recognize tap outside of username/password fields so that keyboard will disappear
[self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self.view action:@selector(endEditing:)]];
//No need for back button - first page
self.navigationItem.hidesBackButton = YES;
}
......@@ -28,6 +31,7 @@
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//Check if user has "remember username/password" enabled and enter if so
[self checkAndSatisfyUserLoginPreferences];
}
......@@ -37,11 +41,13 @@
//Disable login button
[self.btnLogIn setEnabled:NO];
//Always reset RTI session when reaching this page
[self resetRTI];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
//Determine what to do next based on what page loads
[self evaluateNextRTIAction:webView];
}
......@@ -55,12 +61,14 @@
}
//Creates target for segue from section & scanning pages
- (IBAction)prepareForUnwindToLogin:(UIStoryboardSegue *)sender {
}
#pragma mark - Helper Functions
//Check if user has "remember username/password" enabled and enter if so
- (void)checkAndSatisfyUserLoginPreferences {
self.txtPassword.text = @"";
......@@ -84,6 +92,7 @@
}
}
//Reset RTI session by destroying + recreating UIWebView, eliminating cache + cookies
- (void)resetRTI {
//Remove delegate from webview
[self.webview setDelegate:nil];
......@@ -98,6 +107,7 @@
//Set current view as delegate of uiwebview
[self.webview setDelegate:self];
//Create URL request for RTI webpage
NSURLRequest *rti;
#ifdef TESTING
......@@ -122,23 +132,28 @@
[self.view addSubview:self.webview];
}
//Determine what to do next based on what page loads
- (void)evaluateNextRTIAction:(UIWebView *)webView {
//Get current URL
NSString *url = [[webView request] URL].absoluteString;
NSString *base_dest_url;
#ifdef TESTING
base_dest_url = @"http://162.223.19.75";
base_dest_url = @"http://162.223.19.75"; //External IP
#else
base_dest_url = @"http://192.168.1.131";
base_dest_url = @"http://192.168.1.131"; //Internal IP
#endif
//If initial load (before redirect)
if ([url isEqualToString:[base_dest_url stringByAppendingString:@"/rti/"]]) {
NSLog(@"0: %@", url);
}
//Else if login page
else if ([url isEqualToString:[base_dest_url stringByAppendingString:@"/rti/RTILogin.aspx"]]) {
NSLog(@"1: %@", url);
//Enable login button
[self.btnLogIn setEnabled:YES];
}
//Else if section page - means successful login
else if ([url isEqualToString:[base_dest_url stringByAppendingString:@"/rti/RTISetup.aspx?location=1"]]) {
NSLog(@"2: %@", url);
......@@ -182,31 +197,37 @@
#pragma mark - UI Buttons
//When "Log In" button is pressed
- (IBAction)btnLogInTouch:(id)sender {
//Load 1st half of Javascript to execute login
NSString *login1Path =
[[NSBundle mainBundle] pathForResource:@"Login1" ofType:@"js"];
NSString *login1 = [NSString stringWithContentsOfFile:login1Path
encoding:NSUTF8StringEncoding
error:nil];
//Create strings for entering username and password (via Javascript)
NSString *username = @"user.value = \"";
username = [username stringByAppendingString:[self.txtUsername.text stringByAppendingString:@"\";"]];
NSString *password = @"pword.value = \"";
password = [password stringByAppendingString:[self.txtPassword.text stringByAppendingString:@"\";"]];
//Load 2nd half of Javascript to execute login
NSString *login2Path =
[[NSBundle mainBundle] pathForResource:@"Login2" ofType:@"js"];
NSString *login2 = [NSString stringWithContentsOfFile:login2Path
encoding:NSUTF8StringEncoding
error:nil];
//Combine strings to form a single Javascript function
NSString *login = [login1 stringByAppendingString:[username stringByAppendingString:[password stringByAppendingString:login2]]];
//Execute Javascript function to login
[self.webview stringByEvaluatingJavaScriptFromString:login];
}
//When "Remember Username" button is changed
- (IBAction)rememberUsernameBtnChanged:(id)sender {
[[NSUserDefaults standardUserDefaults] setBool:self.rememberUsernameSwitch.isOn forKey:@"rememberUsername"];
if (!self.rememberUsernameSwitch.isOn) {
......@@ -216,6 +237,7 @@
[[NSUserDefaults standardUserDefaults] synchronize];
}
//When "Remember Password" button is changed
- (IBAction)rememberPasswordBtnChanged:(id)sender {
if (self.rememberUsernameSwitch.isOn) {
[[NSUserDefaults standardUserDefaults] setBool:self.rememberPasswordSwitch.isOn forKey:@"rememberPassword"];
......
This diff is collapsed.
......@@ -33,10 +33,14 @@
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
//Capture and load sections from page into UITableView
[self initializeSectionList];
}
//NOTE - for some reason running [super webViewDidFinishLoad(webView)] crashes everything.
// Never figured out exactly why...sorry to future developers (Bucknell ECE Senior Design 2015)
- (void)webViewDidFinishLoad:(UIWebView *)webView {
//Determine what to do next based on what page loads
[self evaluateNextRTIAction:webView];
}
......@@ -105,6 +109,8 @@
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
//When seguing to scanning, need to pass along which section was chosen (for displaying on scan page)
if ([segue.identifier isEqualToString:@"segueToScanning"]) {
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
Session *session = [[Session alloc] init];
......@@ -116,13 +122,14 @@
#pragma mark - Helper Functions
//Pulls sections from webpage to display in UITableView
- (void)initializeSectionList {
self.sections = [[NSMutableArray alloc] init];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.tableView reloadData];
// Get collections available - Testing GetAvailableCollections
//Load Javascript to get available collections from webpage
NSString *getAvailablePath =
[[NSBundle mainBundle] pathForResource:@"GetAvailableCollections"
ofType:@"js"];
......@@ -131,12 +138,16 @@
encoding:NSUTF8StringEncoding
error:nil];
//Execute Javascript to get available collections from webpage
// (returned as a string in JSON format for easy parsing)
NSString *availableSections =
[self.webview stringByEvaluatingJavaScriptFromString:getAvailable];
//Extracts sections from returned string
[self extractSectionInformation:availableSections];
}
- (void)extractSectionInformation:(NSString *)availableSections {
//Create error holder for JSON parsing
......@@ -150,11 +161,10 @@
//Check for errors (in JSON parsing)
if (error != nil) {
NSLog(@"ERROR: %@", error.localizedDescription);
NSLog(@"ERROR parsing JSON (sections): %@", error.localizedDescription);
}
//If no errors found, update section list
else {
NSLog(@"SUCCESS");
for (Section *section in sectionList) {
[self.sections addObject:section.text];
}
......@@ -162,7 +172,9 @@
}
}
//Determine what to do next based on what page loads
- (void)evaluateNextRTIAction:(UIWebView *)webView {
//Get current URL
NSString *url = [[webView request] URL].absoluteString;
NSString *base_dest_url;
#ifdef TESTING
......@@ -170,17 +182,24 @@
#else
base_dest_url = @"http://192.168.1.131";
#endif
//If return to initial page (so timed out)
// NOTE: Not sure this page ever times out, but just in case... - Bucknell ECE Senior Design 2015
if ([url isEqualToString:[base_dest_url stringByAppendingString:@"/rti/Default.aspx"]]) {
NSLog(@"Timed out!");
//In the event of timeout, return to login screen
[self performSegueWithIdentifier:@"segueSectionToLogin" sender:nil];
}
//Otherwise if current page loads...do nothing (should never really trigger)
else if ([url isEqualToString:[base_dest_url stringByAppendingString:@"/rti/RTISetup.aspx?location=1"]]) {
NSLog(@"1: %@", url);
}
//Otherwise if scan page loads - section was successfully chosen
else if ([url isEqualToString:[base_dest_url stringByAppendingString:@"/rti/RTIScan.aspx?location=1"]]) {
NSLog(@"2: %@", url);
//Segue to scan page in app
[self performSegueWithIdentifier:@"segueToScanning" sender:nil];
}
//Handle deeper errors (unrecognized URL)
else {
NSLog(@"3: %@", url);
/*
......@@ -196,9 +215,9 @@
}
}
//Once selection has been chosen in UITableView, add and move to scan page
- (void)setCollection:(NSIndexPath *)path {
//need to call AddCollection, then GetSelectedCollections
//AddCollection
//Load Javascript to add chosen section
NSString *addSelectedPath =
[[NSBundle mainBundle] pathForResource:@"AddCollection"
ofType:@"js"];
......@@ -209,52 +228,49 @@
[self.webview stringByEvaluatingJavaScriptFromString:[@"var selectedAdd = " stringByAppendingString:[NSString stringWithFormat:@"%d;", path.row]]];
//Add chosen section
NSString *add =
[self.webview
stringByEvaluatingJavaScriptFromString:addSelected];
[self.webview stringByEvaluatingJavaScriptFromString:addSelected];
//Check to make sure add worked
if ([add isEqual:nil]) {
NSLog(@"nil failed");
NSLog(@"ERROR - adding section failed!");
} else {
NSLog(@"NOT NILL UNFAILED");
//Load Javascript to get selected collections
NSString *selectedPath =
[[NSBundle mainBundle] pathForResource:@"GetSelectedCollections"
ofType:@"js"];
NSString *selectedFunc =
[NSString stringWithContentsOfFile:selectedPath
encoding:NSUTF8StringEncoding
error:nil];
//Add chosen section (equivalent to clicking >> button on RTI webpage)
[self.webview stringByEvaluatingJavaScriptFromString:selectedFunc];
//Load Javascript to save section and proceed to scan page
NSString *saveSetupPath =
[[NSBundle mainBundle] pathForResource:@"SaveSetup" ofType:@"js"];
NSString *saveSetup =
[NSString stringWithContentsOfFile:saveSetupPath
encoding:NSUTF8StringEncoding
error:nil];
//Save section and proceed to scan page
[self.webview stringByEvaluatingJavaScriptFromString:saveSetup];
}
//GetSelectedCollections
NSString *selectedPath =
[[NSBundle mainBundle] pathForResource:@"GetSelectedCollections"
ofType:@"js"];
NSString *selectedFunc =
[NSString stringWithContentsOfFile:selectedPath
encoding:NSUTF8StringEncoding
error:nil];
[self.webview stringByEvaluatingJavaScriptFromString:selectedFunc];
//UIAlertView *selectedAlert =
//[[UIAlertView alloc] initWithTitle:@"Collections Selected"
// message:selected
// delegate:self
// cancelButtonTitle:@"OK"
// otherButtonTitles:nil];
//[selectedAlert show];
NSString *saveSetupPath =
[[NSBundle mainBundle] pathForResource:@"SaveSetup" ofType:@"js"];
NSString *saveSetup =
[NSString stringWithContentsOfFile:saveSetupPath
encoding:NSUTF8StringEncoding
error:nil];
[self.webview stringByEvaluatingJavaScriptFromString:saveSetup];
}
#pragma mark - UI Buttons
//When "Select" button is pressed
- (IBAction)selectSelectionToScan:(id)sender {
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
//If a section was selected
if (path) {
[self setCollection:path];
}
//If no section was selected
else {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"No Collection Selected" message:@"Please select a collection to continue." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
......@@ -265,6 +281,7 @@
}
}
//When "Exit" button is pressed
- (IBAction)exitBtnPressed:(id)sender {
[self performSegueWithIdentifier:@"segueSectionToLogin" sender:nil];
}
......
......@@ -82,35 +82,6 @@
// NSLog(@"Scan");
// } else if ([page isEqual:@"3"]) { // Error/Action Page
// NSLog(@"Error");
// // Get the error - Testing GetError
// NSString *getErrorPath =
// [[NSBundle mainBundle] pathForResource:@"GetError" ofType:@"js"];
// NSString *getError = [NSString stringWithContentsOfFile:getErrorPath
// encoding:NSUTF8StringEncoding
// error:nil];
//
// NSString *error = [webView stringByEvaluatingJavaScriptFromString:getError];
//
// self.view.backgroundColor = [UIColor redColor];
// [UIView animateWithDuration:1.0 animations:^{
// self.view.backgroundColor = [UIColor whiteColor];
// }];
//
// // Continue - Testing GoToScan
// NSString *goToScanPath =
// [[NSBundle mainBundle] pathForResource:@"GoToScan" ofType:@"js"];
// NSString *goToScan = [NSString stringWithContentsOfFile:goToScanPath
// encoding:NSUTF8StringEncoding
// error:nil];
// [self.webview stringByEvaluatingJavaScriptFromString:goToScan];
//
// UIAlertView *errorAlert =
// [[UIAlertView alloc] initWithTitle:@"Error Encountered"
// message:error
// delegate:self
// cancelButtonTitle:@"OK"
// otherButtonTitles:nil];
// [errorAlert show];
// }
//}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment