Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Maarch
MaarchCourrier
Commits
ee4612fe
Commit
ee4612fe
authored
Dec 08, 2017
by
Damien
Browse files
FEAT Basic auth for Rest + basic auth for curl calls
parent
fa311c43
Changes
3
Hide whitespace changes
Inline
Side-by-side
apps/maarch_entreprise/xml/curlCall.xml
View file @
ee4612fe
<?xml version="1.0" encoding="utf-8"?>
<ROOT>
<user>
super
</user>
<password>
maaarch
</password>
<call>
<id>
sendFile
</id>
<url></url>
<url>
http://127.0.0.1/maarch_trunk/rest/user/profile
</url>
<method>
POST
</method>
</call>
<call>
...
...
core/Models/CurlModel.php
View file @
ee4612fe
...
...
@@ -22,6 +22,7 @@ class CurlModel
ValidatorModel
::
notEmpty
(
$aArgs
,
[
'curlCallId'
]);
ValidatorModel
::
stringType
(
$aArgs
,
[
'curlCallId'
]);
ValidatorModel
::
arrayType
(
$aArgs
,
[
'bodyData'
]);
ValidatorModel
::
boolType
(
$aArgs
,
[
'noAuth'
]);
$curlConfig
=
CurlModel
::
getConfigByCallId
([
'curlCallId'
=>
$aArgs
[
'curlCallId'
]]);
if
(
empty
(
$curlConfig
))
{
...
...
@@ -36,6 +37,9 @@ class CurlModel
],
CURLOPT_RETURNTRANSFER
=>
true
,
];
if
(
empty
(
$aArgs
[
'noAuth'
]))
{
$opts
[
CURLOPT_HTTPHEADER
][]
=
'Authorization: Basic '
.
base64_encode
(
$curlConfig
[
'user'
]
.
':'
.
$curlConfig
[
'password'
]);
}
if
(
$curlConfig
[
'method'
]
==
'POST'
||
$curlConfig
[
'method'
]
==
'PUT'
)
{
if
(
!
empty
(
$curlConfig
[
'data'
]))
{
...
...
@@ -76,6 +80,9 @@ class CurlModel
$curlConfig
=
[];
if
(
file_exists
(
$path
))
{
$loadedXml
=
simplexml_load_file
(
$path
);
$curlConfig
[
'user'
]
=
(
string
)
$loadedXml
->
user
;
$curlConfig
[
'password'
]
=
(
string
)
$loadedXml
->
password
;
foreach
(
$loadedXml
->
call
as
$call
)
{
if
((
string
)
$call
->
id
==
$aArgs
[
'curlCallId'
])
{
$curlConfig
[
'url'
]
=
(
string
)
$call
->
url
;
...
...
rest/index.php
View file @
ee4612fe
...
...
@@ -70,13 +70,25 @@ if (empty($_SESSION['user'])) {
//login management
if
(
empty
(
$_SESSION
[
'user'
]))
{
require_once
(
'apps/maarch_entreprise/class/class_login.php'
);
$loginObj
=
new
login
();
$loginMethods
=
$loginObj
->
build_login_method
();
require_once
(
'core/services/Session.php'
);
$oSessionService
=
new
\
Core_Session_Service
();
$loginObj
->
execute_login_script
(
$loginMethods
,
true
);
if
(
!
empty
(
$_SERVER
[
'PHP_AUTH_USER'
])
&&
!
empty
(
$_SERVER
[
'PHP_AUTH_PW'
]))
{
$_SESSION
[
'error'
]
=
''
;
$security
=
new
security
();
$pass
=
$security
->
getPasswordHash
(
$_SERVER
[
'PHP_AUTH_PW'
]);
$res
=
$security
->
login
(
$_SERVER
[
'PHP_AUTH_USER'
],
$pass
);
$_SESSION
[
'user'
]
=
$res
[
'user'
];
if
(
!
empty
(
$res
[
'error'
]))
{
$_SESSION
[
'error'
]
=
$res
[
'error'
];
}
}
else
{
require_once
(
'apps/maarch_entreprise/class/class_login.php'
);
$loginObj
=
new
login
();
$loginMethods
=
$loginObj
->
build_login_method
();
require_once
(
'core/services/Session.php'
);
$oSessionService
=
new
\
Core_Session_Service
();
$loginObj
->
execute_login_script
(
$loginMethods
,
true
);
}
}
if
(
$_SESSION
[
'error'
])
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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