Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
afi
opacce
Commits
6b7b532d
Commit
6b7b532d
authored
Apr 24, 2018
by
Ghislain Loas
Browse files
dev #59224 feature
parent
d3de24a6
Pipeline
#3984
failed with stage
in 34 minutes and 6 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
203 additions
and
5 deletions
+203
-5
VERSIONS_WIP/59224
VERSIONS_WIP/59224
+2
-0
application/modules/opac/controllers/AbonneController.php
application/modules/opac/controllers/AbonneController.php
+13
-0
library/Class/WebService/SIGB/AbstractRESTService.php
library/Class/WebService/SIGB/AbstractRESTService.php
+9
-0
library/Class/WebService/SIGB/Koha/RestfulService.php
library/Class/WebService/SIGB/Koha/RestfulService.php
+30
-0
library/Class/WebService/SIGB/Koha/Service.php
library/Class/WebService/SIGB/Koha/Service.php
+12
-0
library/Class/WebService/SimpleWebClient.php
library/Class/WebService/SimpleWebClient.php
+15
-3
tests/application/modules/opac/controllers/AbonneControllerChangePasswordTest.php
...s/opac/controllers/AbonneControllerChangePasswordTest.php
+92
-0
tests/library/Class/WebService/SIGB/KohaRestfulTest.php
tests/library/Class/WebService/SIGB/KohaRestfulTest.php
+30
-2
No files found.
VERSIONS_WIP/59224
0 → 100644
View file @
6b7b532d
- ticket #59224 : Compte lecteur : les adhérents peuvent modifier leur mot de passe Koha depuis Bokeh.
\ No newline at end of file
application/modules/opac/controllers/AbonneController.php
View file @
6b7b532d
...
@@ -578,9 +578,12 @@ class AbonneController extends ZendAfi_Controller_Action {
...
@@ -578,9 +578,12 @@ class AbonneController extends ZendAfi_Controller_Action {
if
(
!
$this
->
getRequest
()
->
isPost
())
if
(
!
$this
->
getRequest
()
->
isPost
())
return
;
return
;
if
(
!
$form
->
isValid
(
$_POST
))
if
(
!
$form
->
isValid
(
$_POST
))
return
;
return
;
$subscriptions
=
$this
->
_request
->
getParam
(
'subscriptions'
,
[]);
$subscriptions
=
$this
->
_request
->
getParam
(
'subscriptions'
,
[]);
$newsletters
=
$subscriptions
?
$newsletters
=
$subscriptions
?
Class_Newsletter
::
findAllBy
([
'id'
=>
$subscriptions
])
:
Class_Newsletter
::
findAllBy
([
'id'
=>
$subscriptions
])
:
[];
[];
...
@@ -602,7 +605,10 @@ class AbonneController extends ZendAfi_Controller_Action {
...
@@ -602,7 +605,10 @@ class AbonneController extends ZendAfi_Controller_Action {
->
setPassword
(
$password
)
->
setPassword
(
$password
)
->
setNewsletters
(
$newsletters
);
->
setNewsletters
(
$newsletters
);
$this
->
_updatePasswordInILS
();
if
(
$this
->
_user
->
save
())
{
if
(
$this
->
_user
->
save
())
{
$this
->
_helper
->
notify
(
$this
->
_
(
'Vos modifications ont bien été enregistrées'
));
$this
->
_redirect
(
'/abonne/fiche'
);
$this
->
_redirect
(
'/abonne/fiche'
);
}
}
...
@@ -613,7 +619,14 @@ class AbonneController extends ZendAfi_Controller_Action {
...
@@ -613,7 +619,14 @@ class AbonneController extends ZendAfi_Controller_Action {
$form
->
addError
(
$e
->
getMessage
());
$form
->
addError
(
$e
->
getMessage
());
$form
->
addDecorator
(
'Errors'
);
$form
->
addDecorator
(
'Errors'
);
}
}
}
protected
function
_updatePasswordInILS
()
{
if
(
!
$comm
=
$this
->
_user
->
getSIGBComm
())
return
;
$comm
->
changePasswordOfBy
(
$this
->
_user
,
$this
->
_user
->
getPassword
());
}
}
...
...
library/Class/WebService/SIGB/AbstractRESTService.php
View file @
6b7b532d
...
@@ -110,6 +110,15 @@ abstract class Class_WebService_SIGB_AbstractRESTService extends Class_WebServic
...
@@ -110,6 +110,15 @@ abstract class Class_WebService_SIGB_AbstractRESTService extends Class_WebServic
}
}
public
function
httpPut
(
$options
,
$datas
)
{
$closure
=
function
(
$client
,
$url
)
use
(
$datas
)
{
return
$client
->
putData
(
$url
,
$datas
);
};
return
$this
->
_withClientDo
(
$options
,
$closure
);
}
/**
/**
* @param $options array url query part
* @param $options array url query part
* @param $closure
* @param $closure
...
...
library/Class/WebService/SIGB/Koha/RestfulService.php
View file @
6b7b532d
...
@@ -141,6 +141,30 @@ class Class_WebService_SIGB_Koha_RestfulService
...
@@ -141,6 +141,30 @@ class Class_WebService_SIGB_Koha_RestfulService
}
}
public
function
changePasswordOfBy
(
$user
,
$new_password
)
{
if
(
!
$user
)
return
;
if
(
!
$new_password
)
return
;
$response
=
$this
->
restfulPut
(
'auth/change_password'
,
[
'user_name'
=>
$user
->
getLogin
(),
'new_password'
=>
$new_password
]);
if
(
null
===
(
$json
=
json_decode
(
$response
,
true
)))
throw
new
Class_WebService_Exception
(
$this
->
_
(
'Échec de la connexion au webservice, le SIGB a répondu "%s"'
,
trim
(
$response
)));
$json
=
reset
(
$json
);
if
(
!
array_key_exists
(
'success'
,
$json
))
throw
new
Class_WebService_Exception
(
$this
->
_
(
'Échec du changement de mot de passe le SIGB à répondu "%s"'
,
trim
(
$response
)));
return
$this
->
_success
();
}
public
function
buildQueryURL
(
$options
)
{
public
function
buildQueryURL
(
$options
)
{
if
(
empty
(
$options
))
if
(
empty
(
$options
))
return
sprintf
(
'%s/%s'
,
return
sprintf
(
'%s/%s'
,
...
@@ -169,6 +193,12 @@ class Class_WebService_SIGB_Koha_RestfulService
...
@@ -169,6 +193,12 @@ class Class_WebService_SIGB_Koha_RestfulService
}
}
public
function
restfulPut
(
$action
,
$datas
,
$params
=
[])
{
$this
->
_current_action
=
$action
;
return
$this
->
httpPut
(
$params
,
$datas
);
}
/**
/**
* Handled by ILSDI
* Handled by ILSDI
*/
*/
...
...
library/Class/WebService/SIGB/Koha/Service.php
View file @
6b7b532d
...
@@ -224,6 +224,11 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR
...
@@ -224,6 +224,11 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR
}
}
public
function
providesChangePasswordService
()
{
return
$this
->
restful
;
}
public
function
suggestionsOf
(
$user
)
{
public
function
suggestionsOf
(
$user
)
{
if
(
!
$this
->
providesSuggestions
())
if
(
!
$this
->
providesSuggestions
())
return
parent
::
suggestionsOf
(
$user
);
return
parent
::
suggestionsOf
(
$user
);
...
@@ -254,6 +259,13 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR
...
@@ -254,6 +259,13 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR
}
}
public
function
changePasswordOfBy
(
$user
,
$new_password
)
{
return
$this
->
providesChangePasswordService
()
?
$this
->
getRestfulService
()
->
changePasswordOfBy
(
$user
,
$new_password
)
:
null
;
}
public
function
getRestfulService
()
{
public
function
getRestfulService
()
{
return
Class_WebService_SIGB_Koha_RestfulService
::
newFromIlsdi
(
$this
);
return
Class_WebService_SIGB_Koha_RestfulService
::
newFromIlsdi
(
$this
);
}
}
...
...
library/Class/WebService/SimpleWebClient.php
View file @
6b7b532d
...
@@ -41,8 +41,7 @@ class Class_WebService_SimpleWebClient {
...
@@ -41,8 +41,7 @@ class Class_WebService_SimpleWebClient {
$httpClient
->
setMethod
(
Zend_Http_Client
::
GET
);
$httpClient
->
setMethod
(
Zend_Http_Client
::
GET
);
$httpClient
->
setUri
(
$url
);
$httpClient
->
setUri
(
$url
);
$response
=
$httpClient
->
request
();
return
$httpClient
->
request
()
->
getBody
();
return
$response
->
getBody
();
}
}
...
@@ -59,12 +58,25 @@ class Class_WebService_SimpleWebClient {
...
@@ -59,12 +58,25 @@ class Class_WebService_SimpleWebClient {
}
}
public
function
putData
(
$url
,
$params
,
$options
)
{
$httpClient
=
$this
->
getHttpClient
();
$httpClient
->
resetParameters
();
$httpClient
->
setUri
(
$url
);
$httpClient
->
setMethod
(
Zend_Http_Client
::
PUT
);
$httpClient
->
setEncType
(
Zend_Http_Client
::
ENC_URLENCODED
);
foreach
(
$params
as
$key
=>
$value
)
$httpClient
->
setParameterPost
(
$key
,
$value
);
return
$httpClient
->
request
()
->
getBody
();
}
public
function
postRawData
(
$url
,
$datas
,
$encoding
,
$options
=
[])
{
public
function
postRawData
(
$url
,
$datas
,
$encoding
,
$options
=
[])
{
$httpClient
=
$this
->
getHttpClient
();
$httpClient
=
$this
->
getHttpClient
();
$httpClient
->
resetParameters
();
$httpClient
->
resetParameters
();
$httpClient
->
setUri
(
$url
);
$httpClient
->
setUri
(
$url
);
$httpClient
->
setMethod
(
Zend_Http_Client
::
POST
);
$httpClient
->
setMethod
(
Zend_Http_Client
::
POST
);
$httpClient
->
setRawData
(
$datas
,
$encoding
);
if
(
isset
(
$options
[
'headers'
]))
if
(
isset
(
$options
[
'headers'
]))
$httpClient
->
setHeaders
(
$options
[
'headers'
]);
$httpClient
->
setHeaders
(
$options
[
'headers'
]);
...
...
tests/application/modules/opac/controllers/AbonneControllerChangePasswordTest.php
0 → 100644
View file @
6b7b532d
<?php
/**
* Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class
AbonneControllerChangePasswordOnKohaTestCase
extends
AbstractControllerTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
$sigb_plage
=
$this
->
fixture
(
'Class_IntBib'
,
[
'id'
=>
3
,
'comm_params'
=>
[
'url_serveur'
=>
'http://plage.com/cgi-bin/koha/ilsdi.pl'
,
'restful'
=>
'1'
],
'comm_sigb'
=>
Class_IntBib
::
COM_KOHA
]);
$this
->
fixture
(
'Class_Bib'
,
[
'id'
=>
11
,
'libelle'
=>
'Bib de la plage'
,
'int_bib'
=>
$sigb_plage
]);
$koha_user
=
$this
->
fixture
(
'Class_Users'
,
[
'id'
=>
5
,
'login'
=>
'ml34'
,
'password'
=>
'achanger'
,
'id_site'
=>
11
,
'int_bib'
=>
$sigb_plage
,
'idabon'
=>
'123456'
,
'role_level'
=>
ZendAfi_Acl_AdminControllerRoles
::
ABONNE_SIGB
]);
$mock_web_client
=
$this
->
mock
()
->
whenCalled
(
'open_url'
)
->
with
(
'http://plage.com/cgi-bin/koha/ilsdi.pl?service=AuthenticatePatron&username=ml34&password=achanger'
)
->
answers
(
true
)
->
whenCalled
(
'putData'
)
->
with
(
'http://plage.com/cgi-bin/koha/rest.pl/auth/change_password'
,
[
'user_name'
=>
'ml34'
,
'new_password'
=>
'ce1bnm2p'
])
->
answers
(
json_encode
([[
'success'
=>
[
'password'
=>
'$2a$08$o0BrhvBevJBbWcYJElH3IevoytrdwnkZUQLwNcxQt3GhAjtht3RoK'
]]]))
->
beStrict
();
$sigb_comm
=
Class_IntBib
::
find
(
3
)
->
getSIGBComm
();
$sigb_comm
->
setWebClient
(
$mock_web_client
);
ZendAfi_Auth
::
getInstance
()
->
logUser
(
$koha_user
);
$logger
=
$this
->
mock
()
->
whenCalled
(
'log'
)
->
answers
(
true
)
->
whenCalled
(
'logError'
)
->
willDo
(
function
(
$url
,
$message
)
{
var_dump
(
$url
.
' :: '
.
$message
);
exit
;
});
Class_WebService_SIGB_AbstractService
::
setLogger
(
$logger
);
$this
->
postDispatch
(
'/abonne/edit'
,
[
'password'
=>
'ce1bnm2p'
,
'confirm_password'
=>
'ce1bnm2p'
]);
}
public
function
tearDown
()
{
Class_WebService_SIGB_AbstractService
::
setLogger
(
null
);
Class_IntBib
::
find
(
3
)
->
getSIGBComm
()
->
setWebClient
(
null
);
parent
::
tearDown
();
}
/** @test */
public
function
userPasswordShouldHaveBeenUpdatedToCe1bnm2p
()
{
Class_Users
::
clearCache
();
$this
->
assertEquals
(
'ce1bnm2p'
,
Class_Users
::
getIdentity
()
->
getPassword
());
}
}
\ No newline at end of file
tests/library/Class/WebService/SIGB/KohaRestfulTest.php
View file @
6b7b532d
...
@@ -40,8 +40,8 @@ abstract class KohaRestfulTestCase extends ModelTestCase {
...
@@ -40,8 +40,8 @@ abstract class KohaRestfulTestCase extends ModelTestCase {
->
whenCalled
(
'logError'
)
->
whenCalled
(
'logError'
)
->
willDo
(
function
(
$url
,
$message
)
{
->
willDo
(
function
(
$url
,
$message
)
{
throw
new
RuntimeException
(
$url
.
' :: '
.
$message
);
throw
new
RuntimeException
(
$url
.
' :: '
.
$message
);
});
});
Class_WebService_SIGB_AbstractService
::
setLogger
(
$logger
);
Class_WebService_SIGB_AbstractService
::
setLogger
(
$logger
);
$params
=
[
'url_serveur'
=>
static
::
BASE_URL
.
'ilsdi.pl'
,
$params
=
[
'url_serveur'
=>
static
::
BASE_URL
.
'ilsdi.pl'
,
...
@@ -429,4 +429,32 @@ class KohaRestGetUserHistoryTest extends KohaRestfulTestCase {
...
@@ -429,4 +429,32 @@ class KohaRestGetUserHistoryTest extends KohaRestfulTestCase {
$this
->
assertEquals
(
'22/07/2015'
,
$this
->
loans_history
->
getLoans
()[
1
]
->
getDateRetour
());
$this
->
assertEquals
(
'22/07/2015'
,
$this
->
loans_history
->
getLoans
()[
1
]
->
getDateRetour
());
}
}
}
class
KohaRestfulChangePasswordTest
extends
KohaRestfulTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
$user
=
$this
->
fixture
(
'Class_Users'
,
[
'id'
=>
34
,
'login'
=>
'harlock'
,
'password'
=>
'arcadia'
,
'idabon'
=>
'AO989IE'
]);
$this
->
mock_web_client
->
whenCalled
(
'putData'
)
->
with
(
'http://cat-aficg55.biblibre.com/cgi-bin/koha/rest.pl/auth/change_password'
,
[
'user_name'
=>
'harlock'
,
'new_password'
=>
'ce1snm2p'
])
->
answers
(
json_encode
([[
'success'
=>
[
'password'
=>
'$2a$08$o0BrhvBevJBbWcYJElH3IevoytrdwnkZUQLwNcxQt3GhAjtht3RoK'
]]]))
->
beStrict
();
$this
->
response
=
$this
->
service
->
changePasswordOfBy
(
$user
,
'ce1snm2p'
);
}
/** @test */
public
function
responseShouldReturnSuccess
()
{
$this
->
assertEquals
([
'statut'
=>
true
,
'erreur'
=>
''
],
$this
->
response
);
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment