Skip to content

Commit ae27eae

Browse files
committedJun 12, 2012
Fixes #13445: Add mc_login() for login and to return user data.
1 parent f39ad8c commit ae27eae

File tree

4 files changed

+106
-1
lines changed

4 files changed

+106
-1
lines changed
 

‎api/soap/mantisconnect.php

+28
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@
9494
)
9595
);
9696

97+
### UserData
98+
$l_oServer->wsdl->addComplexType(
99+
'UserData',
100+
'complexType',
101+
'struct',
102+
'all',
103+
'',
104+
array(
105+
'account_data' => array( 'name' => 'account_data', 'type' => 'tns:AccountData', 'minOccurs' => '0'),
106+
'access_level' => array( 'name' => 'global_access_level', 'type' => 'xsd:integer', 'minOccurs' => '0'),
107+
'timezone' => array( 'name' => 'timezone', 'type' => 'xsd:string', 'minOccurs' => '0'),
108+
)
109+
);
110+
97111
### AccountDataArray
98112
$l_oServer->wsdl->addComplexType(
99113
'AccountDataArray',
@@ -665,6 +679,20 @@
665679
### PUBLIC METHODS (defined in mc_enum_api.php)
666680
###
667681

682+
### mc_login
683+
$l_oServer->register( 'mc_login',
684+
array(
685+
'username' => 'xsd:string',
686+
'password' => 'xsd:string'
687+
),
688+
array(
689+
'return' => 'tns:UserData'
690+
),
691+
$t_namespace,
692+
false, false, false,
693+
'Log the user in and get their information.'
694+
);
695+
668696
### mc_enum_status
669697
$l_oServer->register( 'mc_enum_status',
670698
array(

‎api/soap/mc_api.php

+31-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,37 @@ function mc_version() {
1616
return MANTIS_VERSION;
1717
}
1818

19-
# Checks if MantisBT installation is marked as offline by the administrator.
19+
/**
20+
* Attempts to login the user.
21+
* If logged in successfully, return user information.
22+
* If failed to login in, then throw a fault.
23+
*/
24+
function mc_login( $p_username, $p_password ) {
25+
$t_user_id = mci_check_login( $p_username, $p_password );
26+
if ( $t_user_id === false ) {
27+
return mci_soap_fault_login_failed();
28+
}
29+
30+
return mci_user_get( $p_username, $p_password, $t_user_id );
31+
}
32+
33+
/**
34+
* Given an id, this method returns the user.
35+
* When calling this method make sure that the caller has the right to retrieve
36+
* information about the target user.
37+
*/
38+
function mci_user_get( $p_username, $p_password, $p_user_id ) {
39+
$t_user_data = array();
40+
41+
// if user doesn't exist, then mci_account_get_array_by_id() will throw.
42+
$t_user_data['account_data'] = mci_account_get_array_by_id( $p_user_id );
43+
$t_user_data['access_level'] = access_get_global_level( $p_user_id );
44+
$t_user_data['timezone'] = user_pref_get_pref( $p_user_id, 'timezone' );
45+
46+
return $t_user_data;
47+
}
48+
49+
# access_ if MantisBT installation is marked as offline by the administrator.
2050
# true: offline, false: online
2151
function mci_is_mantis_offline() {
2252
$t_offline_file = dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'mantis_offline.php';

‎tests/soap/LoginTest.php

+46
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ class LoginTest extends SoapBase {
3131
private $dummyUser = 'no';
3232
private $dummyPassword = 'user';
3333

34+
public function testLoginFailed() {
35+
try {
36+
$this->client->mc_login( $this->dummyUser , $this->dummyPassword );
37+
$this->fail( "Should have failed." );
38+
} catch ( SoapFault $e) {
39+
$this->assertIsLoginFailure( $e );
40+
}
41+
}
42+
43+
public function testLoginSuccessfully() {
44+
$t_user_data = $this->client->mc_login( $this->userName, $this->password );
45+
46+
$this->assertEquals( $this->userName, $t_user_data->account_data->name, 'name' );
47+
$this->assertEquals( $this->userId, $t_user_data->account_data->id, 'id' );
48+
$this->assertEquals( $this->email, $t_user_data->account_data->email, 'email' );
49+
$this->assertEquals( false, empty( $t_user_data->timezone ), 'timezone' );
50+
$this->assertEquals( 90, (integer)$t_user_data->access_level, 'access_level' );
51+
}
52+
3453
public function testGetIssueGetLoginFailed() {
3554
try {
3655
$this->client->mc_issue_get( $this->dummyUser , $this->dummyPassword, 1 );
@@ -76,6 +95,33 @@ public function testFilterGetIssuesLoginFailed() {
7695
}
7796
}
7897

98+
public function testLoginWithNullPasswordIsRejected() {
99+
try {
100+
$this->client->mc_enum_status( $this->userName, null);
101+
$this->fail( "Should have failed." );
102+
} catch ( SoapFault $e) {
103+
$this->assertIsLoginFailure( $e );
104+
}
105+
}
106+
107+
public function testLoginWithEmptyPasswordIsRejected() {
108+
try {
109+
$this->client->mc_enum_status( $this->userName, '');
110+
$this->fail( "Should have failed." );
111+
} catch ( SoapFault $e) {
112+
$this->assertIsLoginFailure( $e );
113+
}
114+
}
115+
116+
public function testLoginWithIncorrectPasswordIsRejected() {
117+
try {
118+
$this->client->mc_enum_status( $this->userName, "This really should be incorrect");
119+
$this->fail( "Should have failed." );
120+
} catch ( SoapFault $e) {
121+
$this->assertIsLoginFailure( $e );
122+
}
123+
}
124+
79125
/**
80126
* @param $e SoapFault
81127
* @return void

‎tests/soap/SoapBase.php

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class SoapBase extends PHPUnit_Framework_TestCase {
3232
protected $client;
3333
protected $userName = 'administrator';
3434
protected $password = 'root';
35+
protected $email = 'root@localhost';
3536
protected $userId = '1';
3637

3738
protected $mantisPath;

0 commit comments

Comments
 (0)
Please sign in to comment.