Skip to content

Commit 6ef42ca

Browse files
committed
Change Password section functionality and unit test done
1 parent bf3cb3c commit 6ef42ca

File tree

8 files changed

+214
-63
lines changed

8 files changed

+214
-63
lines changed

WebService/Model/GCashModel.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use Model\TransactionModel as Transaction;
1717
use Model\WebServiceModel as WebService;
18+
use Model\UserModel as User;
1819

1920
/**
2021
* Bridge to call TB DBAL
@@ -133,9 +134,16 @@ public function checkRefNoTransactionExists($refNo)
133134
*/
134135
public function getUnAuthorizedData()
135136
{
136-
$this->return ='5';
137+
if ($this->parameters['operation']=='changePassword') {
138+
$this->return ='1';
139+
} else {
140+
$this->return ='5';
141+
}
137142
}
138143

144+
145+
146+
139147
/**
140148
* sets return variable to GCASH formated string according to $type
141149
*
@@ -160,6 +168,28 @@ public function formatReturnData($type)
160168

161169
}
162170

171+
/**
172+
* [changePassword description]
173+
*
174+
* @return [type] [description]
175+
*/
176+
public function changePassword()
177+
{
178+
if ($this->parameters['newPassword'] !=' ') {
179+
$user = new User();
180+
$status=$user->changePassword($this->parameters['username'], $this->parameters['newPassword']);
181+
if ($status == true) {
182+
$this ->return ='0';
183+
} else {
184+
$this->return = 'error in changing password';
185+
}
186+
187+
}
188+
189+
}
190+
191+
192+
163193
/**
164194
* set return data
165195
*

WebService/Model/MLhuillierModel.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
use Model\TransactionModel as Transaction;
1717
use Model\WebServiceModel as WebService;
18+
use Model\UserModel as User;
19+
1820

1921
/**
2022
* Bridge to call TB DBAL
@@ -133,7 +135,11 @@ public function checkRefNoTransactionExists($refNo)
133135
*/
134136
public function getUnAuthorizedData()
135137
{
136-
$this->return = $this->parameters['sessionID'] .'|5';
138+
if ($this->parameters['operation']=='changePassword') {
139+
$this->return =$this->parameters['sessionID'] .'|1';
140+
} else {
141+
$this->return =$this->parameters['sessionID'] .'|5';
142+
}
137143
}
138144

139145
/**
@@ -160,6 +166,26 @@ public function formatReturnData($type)
160166

161167
}
162168

169+
/**
170+
* [changePassword description]
171+
*
172+
* @return [type] [description]
173+
*/
174+
public function changePassword()
175+
{
176+
if ($this->parameters['newPassword'] !=' ') {
177+
$user = new User();
178+
$status=$user->changePassword($this->parameters['username'], $this->parameters['newPassword']);
179+
if ($status == true) {
180+
$this ->return =$this->parameters['sessionID'].'|0';
181+
} else {
182+
$this->return = 'error in changing password';
183+
}
184+
185+
}
186+
187+
}
188+
163189
/**
164190
* set return data
165191
*

WebService/Model/ModelFactory.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,25 @@ class ModelFactory
4242
* @param Main $obj Object of Main class sub-calsses
4343
*/
4444
public function __construct(WebService $obj)
45-
{
46-
45+
{
4746
$user = new User();
4847
if ($user->authenticateUser($obj->parameters['username'], $obj->parameters['password'])) {
4948
$obj->execute();
5049
$this->_returnData = $obj->getReturn();
51-
} else {
52-
$obj->getUnAuthorizedData();
50+
} else {
51+
$obj->getUnAuthorizedData();
5352
$this->_returnData = $obj->getReturn();
54-
5553
}
5654

5755
}
5856

59-
public function returnData() {
60-
return $this->_returnData;
57+
/**
58+
* Returns set data for testing in String format
59+
*
60+
* @return void
61+
*/
62+
public function returnData()
63+
{
64+
return $this->_returnData;
6165
}
6266
}

WebService/Model/UserModel.php

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,41 +29,58 @@
2929
*/
3030
class UserModel extends Main
3131
{
32-
private $_transactionObj;
32+
private $_hashObj;
33+
/**
34+
* for connection
35+
*/
36+
function __construct()
37+
{
38+
parent::__construct();
39+
$this->_hashObj = new Password();
40+
}
41+
3342

3443
/**
3544
* [authenticateUser description]
3645
*
3746
* @param varchar $username username
3847
* @param varchar $password clear password
3948
*
40-
* @return void
49+
* @return void
50+
*
51+
* @todo
52+
* This logic was iimplememted in after user checking user is active or not before,
53+
* We need to findout its significance and implement, if necessary.
54+
* Logic ---
55+
* // $userAgent = $user->getAgent();
56+
* // $userProcessor = $userAgent->getParentAgent() ? : $userAgent;
57+
* // if( !$userAgent->isActive() or !$userProcessor->isActive() )
58+
* // return false;
59+
* Logic End ----
4160
**/
4261
public function authenticateUser($username, $password)
4362
{
4463

45-
$this->_transactionObj=new Transaction();
46-
$this->hashObj = new Password();
47-
$user = $this->_transactionObj->connection->fetchAssoc('SELECT * FROM f1_users WHERE username = ?', array($username));
64+
// $this=new Transaction();
65+
66+
$user = $this->connection->fetchAssoc('SELECT * FROM f1_users WHERE username = ?', array($username));
4867

4968
if ( $user ) {
5069

5170
if ($user['deleted'] !=0 || $user['active']==0) {
5271
return false;
5372
}
54-
// $userAgent = $user->getAgent();
55-
// $userProcessor = $userAgent->getParentAgent() ? : $userAgent;
56-
57-
// if( !$userAgent->isActive() or !$userProcessor->isActive() )
58-
// return false;
73+
5974

6075
if ($hash = $user['password_hash']) {
61-
if ( ! $this->hashObj->password_verify($password, $hash)) {
76+
if ( ! $this->_hashObj->password_verify($password, $hash)) {
6277
return false;
6378
}
6479
} else if ($user['password'] == md5($password)) {
65-
$hashValue=$this->hashObj->password_hash($password, PASSWORD_BCRYPT);
66-
$this->_transactionObj->connection->update('f1_users', array('password_hash' => $hashValue ,'password'=>' '), array('username' => $username));
80+
$hashValue=$this->_hashObj->password_hash($password, PASSWORD_BCRYPT);
81+
$this->connection->update(
82+
'f1_users', array('password_hash' => $hashValue ,'password'=>' '), array('username' => $username)
83+
);
6784
} else return false;
6885

6986
return true;
@@ -89,4 +106,27 @@ public function isAuthorized($user, $pass)
89106
}
90107

91108
}
92-
}
109+
110+
/**
111+
* [changePassword description]
112+
*
113+
* @param [type] $username [description]
114+
* @param [type] $newPassword [description]
115+
*
116+
* @return bool
117+
*/
118+
public function changePassword($username,$newPassword)
119+
{
120+
$hashValue=$this->_hashObj->password_hash($newPassword, PASSWORD_BCRYPT);
121+
$this->connection->update('f1_users', array('password_hash' => $hashValue ,'password'=>' '), array('username' => $username));
122+
$result=$this->authenticateUser($username, $newPassword);
123+
124+
if ( $result == false) {
125+
return false;
126+
} else {
127+
return true;
128+
}
129+
130+
131+
}
132+
}

WebService/Test/GCashModelTest.php

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
require_once './autoload.php';
1616

17-
use Model\GCashModel as gcash;
17+
use Model\GCashModel as GCash;
1818
/**
1919
* First Global Data
2020
*
@@ -28,6 +28,12 @@
2828

2929
class GCashModelTest extends \PHPUnit_Framework_TestCase
3030
{
31+
/**
32+
* [$_model description]
33+
*
34+
* @var [type]
35+
*
36+
*/
3137
private $_model;
3238

3339
/**
@@ -41,7 +47,7 @@ public function testGetRemittanceWithPaidRefNo()
4147

4248
$postParam = array('refNo' => '502000098',);
4349

44-
$this->_model = new gcash($postParam);
50+
$this->_model = new GCash($postParam);
4551
$expected='502000098|1|200.00|Bhjkgfj|Teest||null|null|null|Ertertwe|' ;
4652

4753
$this->_model->showRemittanceDetail();
@@ -59,7 +65,7 @@ public function testGetRemittanceWithApprovedRefNo()
5965
{
6066
$postParam = array('refNo' => '502000008');
6167

62-
$this->_model = new gcash($postParam);
68+
$this->_model = new GCash($postParam);
6369
$expected='502000008|0|20.00|Ali|Nadia||null|null|null|687 Main|';
6470

6571
$this->_model->showRemittanceDetail();
@@ -77,7 +83,7 @@ public function testGetRemittanceWithOtherRefNo()
7783
{
7884
$postParam = array('refNo' => '502000039',);
7985

80-
$this->_model = new gcash($postParam);
86+
$this->_model = new GCash($postParam);
8187
$expected = '3';
8288

8389
$this->_model->showRemittanceDetail();
@@ -96,7 +102,7 @@ public function testTagAsCompleteWithPaidRefNo()
96102

97103
$postParam = array('refNo' => '502000098',);
98104

99-
$this->_model = new gcash($postParam);
105+
$this->_model = new GCash($postParam);
100106
$expected='2' ;
101107

102108
$this->_model->tagAsCompleted();
@@ -115,7 +121,7 @@ public function ptestTagAsCompleteWithApprovedRefNo()
115121
{
116122
$postParam = array('refNo' => '502000011','traceNo'=>'T77');
117123

118-
$this->_model = new gcash($postParam);
124+
$this->_model = new GCash($postParam);
119125
$expected='';
120126

121127
$this->_model->tagAsCompleted();
@@ -133,7 +139,7 @@ public function testTagAsCompleteWithOtherRefNo()
133139
{
134140
$postParam = array('refNo' => '502000039','traceNo'=>'T77');
135141

136-
$this->_model = new gcash($postParam);
142+
$this->_model = new GCash($postParam);
137143
$expected = '3';
138144

139145
$this->_model->tagAsCompleted();
@@ -153,7 +159,7 @@ public function testInquireTagAsCompletedWithPaidRefNo()
153159

154160
$postParam = array('refNo' => '502000098','traceNo'=>'T77');
155161

156-
$this->_model = new gcash($postParam);
162+
$this->_model = new GCash($postParam);
157163
$expected='T77|502000098|0|200.00|Bhjkgfj|Teest||null|null|null|Ertertwe|' ;
158164

159165
$this->_model->inquireTagAsCompleted();
@@ -172,7 +178,7 @@ public function testInquireTagAsCompletedWithApprovedRefNo()
172178
{
173179
$postParam = array('refNo' => '502000011','traceNo'=>'T77');
174180

175-
$this->_model = new gcash($postParam);
181+
$this->_model = new GCash($postParam);
176182
$expected='1';
177183

178184
$this->_model->inquireTagAsCompleted();
@@ -190,7 +196,7 @@ public function testTransactionExistsWithCorrectRefNo()
190196
{
191197
$postParam = array('refNo' => '');
192198

193-
$this->model = new gcash($postParam);
199+
$this->model = new GCash($postParam);
194200

195201
$expected=true;
196202
$result = $this->model->checkRefNoTransactionExists('502000098');
@@ -206,16 +212,26 @@ public function testTransactionExistsWithoutCorrectRefNo()
206212
{
207213
$postParam = array('refNo' => '');
208214

209-
$this->model = new gcash($postParam);
215+
$this->model = new GCash($postParam);
210216

211217
$expected=false;
212218
$result = $this->model->checkRefNoTransactionExists('manisfasfh');
213219
$this->assertEquals($expected, $result);
214220
}
215221

216-
217-
218-
222+
/**
223+
* [testChangePassword description]
224+
*
225+
* @return [type] [description]
226+
*/
227+
public function testChangePassword()
228+
{
229+
$postParam = array('refNo' => '','username'=>'AWARFA','newPassword'=>'123456');
230+
$this->_model = new GCash($postParam);
231+
$this->_model->changePassword();
232+
$result = $this->_model->getReturn();
233+
$this->assertEquals('0', $result);
234+
}
219235
}
220236

221237
?>

0 commit comments

Comments
 (0)