diff --git a/Unit_testing/check_minimum_requirement.php b/Unit_testing/check_minimum_requirement.php index 11defd1..6a4a114 100644 --- a/Unit_testing/check_minimum_requirement.php +++ b/Unit_testing/check_minimum_requirement.php @@ -30,7 +30,7 @@ # Skipped: A test was skipped. It may or may not be a problem. - Error: There was an error on the server—please contact Nigel. + Error: There was an error on the server—please contact Nigel. @@ -43,21 +43,11 @@ Missing username, please return to the login page and try again.

'; - $continue = false; -} -if ( empty( $_POST['password'] ) ) -{ - echo '

Missing password, please return to the login page and try again.

'; - $continue = false; -} - -if ( $continue ) -{ + if ( empty( $_POST['username'] ) ) throw new Exception( 'No username entered. Please return to the login page and try again.' ); + if ( empty( $_POST['password'] ) ) throw new Exception( 'No password entered. Please return to the login page and try again.' ); + // Define things that need to be globally accessible as constants. define( 'ORACLE_USERNAME', $_POST['username'] ); define( 'ORACLE_PASSWORD', $_POST['password'] ); @@ -67,11 +57,40 @@ define( 'OUTPUT_VERBOSITY', 2 ); define( 'RUN_MODE', 'student' ); + require_once 'test_config.php'; + + // Test that the database connection works. + $testPDO = new PDO( "oci:dbname=" . ORACLE_SERVICE_ID, ORACLE_USERNAME, ORACLE_PASSWORD ); + unset( $testPDO ); + require_once 'test.php'; } -else +catch ( PDOException $e ) { - echo '

Redirecting you back to the login page…

'; + echo '

Error: '; + switch ( $e->getCode() ) + { + case 1017: + echo 'Oracle username and/or password are incorrect, cannot connect to schema. Please check your login details and try again.'; + break; + default: + echo 'Failed to connect to Oracle, error was:
'; + echo $e->getMessage(); + echo ''; + break; + } + echo "

\n"; + redirect(); +} +catch ( Exception $e ) +{ + echo '

Error: ', $e->getMessage(), "

\n"; + redirect(); +} + +function redirect() +{ + echo '

Redirecting you back to the login page in a few seconds…

'; header( "refresh:7;url=student_login.html" ); } ?>