Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Σταύρος Παπαδάκης
gredu_labs
Commits
af6ef85a
Commit
af6ef85a
authored
Feb 10, 2016
by
Vassilis Kanellopoulos
Browse files
sync module
parent
4e4dd6e7
Changes
5
Hide whitespace changes
Inline
Side-by-side
config/app.config.php
View file @
af6ef85a
...
...
@@ -17,6 +17,7 @@ return [
'module/sch_sso/bootstrap.php'
,
'module/sch_mm/bootstrap.php'
,
'module/sch_inventory/bootstrap.php'
,
'module/sch_sync/bootstrap.php'
,
'module/schools/bootstrap.php'
,
'module/application/bootstrap.php'
,
],
...
...
module/sch_mm/src/FetchUnit.php
View file @
af6ef85a
...
...
@@ -29,12 +29,12 @@ class FetchUnit
$this
->
httpClient
=
$httpClient
;
}
public
function
__invoke
(
$
mmId
)
public
function
__invoke
(
$
registryNo
)
{
$config
=
$this
->
httpClient
->
getConfig
();
$baseUri
=
$config
[
'base_uri'
];
$auth
=
$config
[
'auth'
];
$url
=
$baseUri
->
withQueryValue
(
$baseUri
,
'registry_no'
,
$
mmId
);
$url
=
$baseUri
->
withQueryValue
(
$baseUri
,
'registry_no'
,
$
registryNo
);
$response
=
$this
->
httpClient
->
request
(
'GET'
,
$url
,
[
'auth'
=>
$auth
]);
$responseData
=
json_decode
(
$response
->
getBody
()
->
getContents
(),
true
);
...
...
module/sch_sso/bootstrap.php
View file @
af6ef85a
...
...
@@ -124,7 +124,7 @@ return function (Slim\App $app) {
$listener
=
$container
[
SchSSO\Listener\User
::
class
];
return
$listener
(
$stop
,
$identity
);
},
10
00
);
},
10
);
$app
->
get
(
'/user/login/sso'
,
SchSSO\Action\Login
::
class
)
->
setName
(
'user.login.sso'
);
$app
->
get
(
'/user/logout/sso'
,
SchSSO\Action\Logout
::
class
)
->
setName
(
'user.logout.sso'
);
...
...
module/sch_sync/bootstrap.php
0 → 100644
View file @
af6ef85a
<?php
/**
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
return
function
(
Slim
\
App
$app
)
{
$container
=
$app
->
getContainer
();
$container
[
'autoloader'
]
->
addPsr4
(
'SchSync\\'
,
__DIR__
.
'/src'
);
$container
[
SchSync\Listener\CreateSchool
::
class
]
=
function
(
$c
)
{
return
new
SchSync\Listener\CreateSchool
(
$c
[
'ldap'
],
$c
[
SchMM\FetchUnit
::
class
]);
};
$events
=
$container
[
'events'
];
$events
(
'on'
,
'authenticate.success'
,
function
(
$stop
,
$identity
)
use
(
$container
)
{
$listener
=
$container
[
SchSync\Listener\CreateSchool
::
class
];
$listener
(
$stop
,
$identity
);
},
20
);
};
module/sch_sync/src/Listener/CreateSchool.php
0 → 100644
View file @
af6ef85a
<?php
/**
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace
SchSync\Listener
;
use
GrEduLabs\Authentication\Identity
;
use
RedBeanPHP\R
;
use
Zend\Ldap\Dn
;
use
Zend\Ldap\Filter
;
use
Zend\Ldap\Ldap
;
class
CreateSchool
{
/**
* @var Ldap
*/
private
$ldap
;
/**
* @var callable
*/
private
$fetchUnit
;
public
function
__construct
(
Ldap
$ldap
,
callable
$fetchUnitFromMM
)
{
$this
->
ldap
=
$ldap
;
$this
->
fetchUnit
=
$fetchUnitFromMM
;
}
public
function
__invoke
(
callable
$stop
,
Identity
$identity
)
{
$registryNo
=
$this
->
findUnitRegitryNo
(
$identity
);
if
(
null
===
$registryNo
)
{
$stop
();
}
$registryNo
=
(
$registryNo
===
'1111111'
)
?
'0601010'
:
$registryNo
;
$unit
=
call_user_func
(
$this
->
fetchUnit
,
$registryNo
);
if
(
null
===
$unit
)
{
$stop
();
}
$school
=
R
::
findOne
(
'school'
,
'registryNo = ?'
,
[
$registryNo
]);
try
{
if
(
!
$school
)
{
$school
=
R
::
dispense
(
'school'
);
$school
->
name
=
$unit
[
'name'
];
$school
->
streetAddress
=
$unit
[
'street_address'
];
$school
->
postalCode
=
$unit
[
'postal_code'
];
$school
->
phoneNumber
=
$unit
[
'phone_number'
];
$school
->
faxNumber
=
$unit
[
'fax_number'
];
$school
->
email
=
$unit
[
'email'
];
$school
->
municipality
=
$unit
[
'municipality'
];
$school
->
schooltype_id
=
$unit
[
'unit_type_id'
];
$school
->
prefecture_id
=
$unit
[
'prefecture_id'
];
$school
->
educationlevel_id
=
$unit
[
'education_level_id'
];
$school
->
eduadmin_id
=
$unit
[
'edu_admin_id'
];
$school
->
created
=
time
();
$school
->
creator
=
$identity
->
mail
;
R
::
store
(
$school
);
}
}
catch
(
\
Exception
$e
)
{
// todo handle exceptions
die
(
'ERROR'
);
}
}
private
function
findUnitRegitryNo
(
Identity
$identity
)
{
$filter
=
Filter
::
equals
(
'mail'
,
$identity
->
mail
);
$baseDn
=
Dn
::
factory
(
$this
->
ldap
->
getBaseDn
())
->
prepend
([
'ou'
=>
'people'
]);
$result
=
$this
->
ldap
->
search
(
$filter
,
$baseDn
,
Ldap
::
SEARCH_SCOPE_ONE
,
[
'l'
]);
if
(
1
!==
$result
->
count
())
{
return
;
}
$result
=
$result
->
current
();
$unitDn
=
$result
[
'l'
][
0
];
$unit
=
$this
->
ldap
->
getNode
(
$unitDn
);
return
$unit
->
getAttribute
(
'gsnunitcode'
,
0
);
}
}
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