diff --git a/api/soap/mantisconnect.php b/api/soap/mantisconnect.php index 819dced..adea6a7 100644 --- a/api/soap/mantisconnect.php +++ b/api/soap/mantisconnect.php @@ -94,6 +94,20 @@ $l_oServer->wsdl->addComplexType( ) ); +### UserData +$l_oServer->wsdl->addComplexType( + 'UserData', + 'complexType', + 'struct', + 'all', + '', + array( + 'account_data' => array( 'name' => 'account_data', 'type' => 'tns:AccountData', 'minOccurs' => '0'), + 'access_level' => array( 'name' => 'global_access_level', 'type' => 'xsd:integer', 'minOccurs' => '0'), + 'timezone' => array( 'name' => 'timezone', 'type' => 'xsd:string', 'minOccurs' => '0'), + ) +); + ### AccountDataArray $l_oServer->wsdl->addComplexType( 'AccountDataArray', @@ -664,6 +678,20 @@ $l_oServer->register( 'mc_version', ### PUBLIC METHODS (defined in mc_enum_api.php) ### +### mc_login +$l_oServer->register( 'mc_login', + array( + 'username' => 'xsd:string', + 'password' => 'xsd:string' + ), + array( + 'return' => 'tns:UserData' + ), + $t_namespace, + false, false, false, + 'Log the user in and get their information.' +); + ### mc_enum_status $l_oServer->register( 'mc_enum_status', array( diff --git a/api/soap/mc_api.php b/api/soap/mc_api.php index 6777811..9ec61a7 100644 --- a/api/soap/mc_api.php +++ b/api/soap/mc_api.php @@ -16,7 +16,37 @@ function mc_version() { return MANTIS_VERSION; } -# Checks if MantisBT installation is marked as offline by the administrator. +/** + * Attempts to login the user. + * If logged in successfully, return user information. + * If failed to login in, then throw a fault. + */ +function mc_login( $p_username, $p_password ) { + $t_user_id = mci_check_login( $p_username, $p_password ); + if ( $t_user_id === false ) { + return mci_soap_fault_login_failed(); + } + + return mci_user_get( $p_username, $p_password, $t_user_id ); +} + +/** + * Given an id, this method returns the user. + * When calling this method make sure that the caller has the right to retrieve + * information about the target user. + */ +function mci_user_get( $p_username, $p_password, $p_user_id ) { + $t_user_data = array(); + + // if user doesn't exist, then mci_account_get_array_by_id() will throw. + $t_user_data['account_data'] = mci_account_get_array_by_id( $p_user_id ); + $t_user_data['access_level'] = access_get_global_level( $p_user_id ); + $t_user_data['timezone'] = user_pref_get_pref( $p_user_id, 'timezone' ); + + return $t_user_data; +} + +# access_ if MantisBT installation is marked as offline by the administrator. # true: offline, false: online function mci_is_mantis_offline() { $t_offline_file = dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'mantis_offline.php'; diff --git a/tests/soap/LoginTest.php b/tests/soap/LoginTest.php index d8b17b0..f2fed26 100644 --- a/tests/soap/LoginTest.php +++ b/tests/soap/LoginTest.php @@ -31,6 +31,25 @@ class LoginTest extends SoapBase { private $dummyUser = 'no'; private $dummyPassword = 'user'; + public function testLoginFailed() { + try { + $this->client->mc_login( $this->dummyUser , $this->dummyPassword ); + $this->fail( "Should have failed." ); + } catch ( SoapFault $e) { + $this->assertIsLoginFailure( $e ); + } + } + + public function testLoginSuccessfully() { + $t_user_data = $this->client->mc_login( $this->userName, $this->password ); + + $this->assertEquals( $this->userName, $t_user_data->account_data->name, 'name' ); + $this->assertEquals( $this->userId, $t_user_data->account_data->id, 'id' ); + $this->assertEquals( $this->email, $t_user_data->account_data->email, 'email' ); + $this->assertEquals( false, empty( $t_user_data->timezone ), 'timezone' ); + $this->assertEquals( 90, (integer)$t_user_data->access_level, 'access_level' ); + } + public function testGetIssueGetLoginFailed() { try { $this->client->mc_issue_get( $this->dummyUser , $this->dummyPassword, 1 ); @@ -77,29 +96,29 @@ class LoginTest extends SoapBase { } public function testLoginWithNullPasswordIsRejected() { - try { - $this->client->mc_enum_status( $this->userName, null); - $this->fail( "Should have failed." ); - } catch ( SoapFault $e) { - $this->assertIsLoginFailure( $e ); + try { + $this->client->mc_enum_status( $this->userName, null); + $this->fail( "Should have failed." ); + } catch ( SoapFault $e) { + $this->assertIsLoginFailure( $e ); } } public function testLoginWithEmptyPasswordIsRejected() { - try { - $this->client->mc_enum_status( $this->userName, ''); - $this->fail( "Should have failed." ); - } catch ( SoapFault $e) { - $this->assertIsLoginFailure( $e ); + try { + $this->client->mc_enum_status( $this->userName, ''); + $this->fail( "Should have failed." ); + } catch ( SoapFault $e) { + $this->assertIsLoginFailure( $e ); } } public function testLoginWithIncorrectPasswordIsRejected() { - try { - $this->client->mc_enum_status( $this->userName, "This really should be incorrect"); - $this->fail( "Should have failed." ); - } catch ( SoapFault $e) { - $this->assertIsLoginFailure( $e ); + try { + $this->client->mc_enum_status( $this->userName, "This really should be incorrect"); + $this->fail( "Should have failed." ); + } catch ( SoapFault $e) { + $this->assertIsLoginFailure( $e ); } } diff --git a/tests/soap/SoapBase.php b/tests/soap/SoapBase.php index 39365fb..dea42d4 100644 --- a/tests/soap/SoapBase.php +++ b/tests/soap/SoapBase.php @@ -32,6 +32,7 @@ class SoapBase extends PHPUnit_Framework_TestCase { protected $client; protected $userName = 'administrator'; protected $password = 'root'; + protected $email = 'root@localhost'; protected $userId = '1'; protected $mantisPath;