Index: /trunk/htdocs2/Forms/LoginForm.php
===================================================================
--- /trunk/htdocs2/Forms/LoginForm.php	(revision 441)
+++ /trunk/htdocs2/Forms/LoginForm.php	(revision 442)
@@ -66,50 +66,79 @@
       $this->user_data->SetEmail( $this->GetPostString( 'email' ) );
       $this->user_data->SetAuthType( 'anonymous' );
+      $this->user_data->SetAssociatedProjects( Array() );
     }
     else if ( $this->GetPostString('authenticateType') == 'opal' )
     {
-        $opal_email = strtolower( $this->GetPostString( 'opalEmail' ) );
-        $opal_password = $this->GetPostString( 'opalPassword' );
-	$hash = md5( $opal_password );
-        
-        $opal_db_user = 'authenticator';
-        $opal_db_password = 'highintegrity';
-        $opal_db_dsn = 'serapis.atnf.csiro.au:1521/atoa.atnf.csiro.au';
-        
-        $connection = oci_connect( $opal_db_user, $opal_db_password, $opal_db_dsn );
-        
-        if( $connection === false )
-          throw new GZ_Exception( 'Unable to connect to opal database, service may be down!',
-                                  'LoginForm::Login' );
-
-	$sql = "SELECT hash FROM opalprod.password p, opalprod.atuser a WHERE a.id = p.userid AND lower(a.email)='".$opal_email."'";
-
-	echo 'sql command is : ' . $sql . ' <br> ';
-
-	$query = oci_parse( $connection, $sql );
-	if( $query === false )
-		throw new GZ_Exception( 'Unable to create password query', 'LoginForm::Login' );
-	
-	if( oci_execute( $query, OCI_DEFAULT ) === false )
-		throw new GZ_Exception( 'Opal login query failed!', 'LoginForm::Login' );
-	
-	$row = oci_fetch_array( $query, OCI_RETURN_NULLS );
-	if( ! $row )
-		echo 'failed to login to opal <br>';
-	else
-	{
-		echo 'from the db ' . $row['HASH'] . ' <br> ';
-		echo 'my hash is ' . $hash . ' <br> ';
-		echo 'got a row from opal to compare <br>';
-		if( $row['HASH'] != $hash )
-		{
-			echo 'logged in successfully <br>';
-		}
-		else
-		{
-			// get a list of all the projects this person is associated with
-
-		}
-	}
+      $opal_db = new OCIDB();
+      $opal_db->connect( OPAL_USER, OPAL_PASSWD, OPAL_DSN );
+      
+      $hash_query = new HashQuery();
+      $hash_query->SetBB( $opal_db );
+      $hash_query->SetEmail( $this->GetPostString( 'opalEmail' ) );
+      $hash_query->Execute();
+      $user_id = $hash_query->GetUserID();
+      $hash = $hash_query->GetHash();
+      if( $user_id == null )
+        $this->failure = true;
+      else
+      {
+        $this_hash = md5( $this->GetPostString( 'opalPassword' ) );
+        if( $this_hash != $hash )
+          $this->failure = true;
+        else
+        {
+          $this->user_data->SetEmail( $this->GetPostString( 'opalEmail' ) );
+          $this->user_data->SetAuthType( 'opal' );
+          
+          $projects_query = new ProjectsQuery();
+          $projects_query->SetUserID( $user_id );
+          $projects_query->Execute();
+          $this->user_data->SetAssociatedProjects( $projects_query->GetAssociatedProjects() );
+        }
+      }
+      
+//         $opal_email = strtolower( $this->GetPostString( 'opalEmail' ) );
+//         $opal_password = $this->GetPostString( 'opalPassword' );
+// 	$hash = md5( $opal_password );
+//         
+//         $opal_db_user = 'authenticator';
+//         $opal_db_password = 'highintegrity';
+//         $opal_db_dsn = 'serapis.atnf.csiro.au:1521/atoa.atnf.csiro.au';
+//         
+//         $connection = oci_connect( $opal_db_user, $opal_db_password, $opal_db_dsn );
+//         
+//         if( $connection === false )
+//           throw new GZ_Exception( 'Unable to connect to opal database, service may be down!',
+//                                   'LoginForm::Login' );
+// 
+// 	$sql = "SELECT hash FROM opalprod.password p, opalprod.atuser a WHERE a.id = p.userid AND lower(a.email)='".$opal_email."'";
+// 
+// 	echo 'sql command is : ' . $sql . ' <br> ';
+// 
+// 	$query = oci_parse( $connection, $sql );
+// 	if( $query === false )
+// 		throw new GZ_Exception( 'Unable to create password query', 'LoginForm::Login' );
+// 	
+// 	if( oci_execute( $query, OCI_DEFAULT ) === false )
+// 		throw new GZ_Exception( 'Opal login query failed!', 'LoginForm::Login' );
+// 	
+// 	$row = oci_fetch_array( $query, OCI_RETURN_NULLS );
+// 	if( ! $row )
+// 		echo 'failed to login to opal <br>';
+// 	else
+// 	{
+// 		echo 'from the db ' . $row['HASH'] . ' <br> ';
+// 		echo 'my hash is ' . $hash . ' <br> ';
+// 		echo 'got a row from opal to compare <br>';
+// 		if( $row['HASH'] != $hash )
+// 		{
+// 			echo 'logged in successfully <br>';
+// 		}
+// 		else
+// 		{
+// 			// get a list of all the projects this person is associated with
+// 
+// 		}
+// 	}
 		
 }
