This commit is contained in:
afornerot 2024-11-01 17:00:36 +01:00
parent edea0d279c
commit 475b5c8412
12 changed files with 205 additions and 46 deletions

15
.env
View File

@ -5,6 +5,7 @@
APP_ENV=dev
APP_SECRET=changeme
INITPWDADMIN=changeme
PROTOCOLE=http
# Webpack
APP_PUBLIC_PATH=/ninefolio/build
@ -17,6 +18,20 @@ APP_ALIAS=ninefolio
APP_NAME="NINEFOLIO"
APP_CRON=1
# NINEGATE
NINEGATE_ACTIVATE=0
NINEGATE_URL=
NINEGATE_SECRET=
NINEGATE_MASTERIDENTITY=
# CAS
CAS_HOST=
CAS_PORT=
CAS_PATH=
CAS_USERNAME=username
CAS_MAIL=email
CAS_LASTNAME=lastname
CAS_FIRSTNAME=firstname
# BDD
DATABASE_NAME=ninefolio

View File

@ -8,7 +8,7 @@
"doctrine/annotations": "^1.8",
"friendsofsymfony/ckeditor-bundle": "^2.2",
"friendsofsymfony/rest-bundle": "^3.0",
"jasig/phpcas": "^1.3",
"jasig/phpcas": "^1.6",
"knplabs/knp-snappy-bundle": "^1.7",
"mashape/unirest-php": "^3.0",
"nategood/httpful": "^0.3.2",

35
composer.lock generated
View File

@ -1598,24 +1598,28 @@
},
{
"name": "jasig/phpcas",
"version": "1.3.8",
"version": "1.6.1",
"source": {
"type": "git",
"url": "https://github.com/apereo/phpCAS.git",
"reference": "40c0769ce05a30c8172b36ceab11124375c8366e"
"reference": "c129708154852656aabb13d8606cd5b12dbbabac"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/apereo/phpCAS/zipball/40c0769ce05a30c8172b36ceab11124375c8366e",
"reference": "40c0769ce05a30c8172b36ceab11124375c8366e",
"url": "https://api.github.com/repos/apereo/phpCAS/zipball/c129708154852656aabb13d8606cd5b12dbbabac",
"reference": "c129708154852656aabb13d8606cd5b12dbbabac",
"shasum": ""
},
"require": {
"ext-curl": "*",
"php": ">=5.4.0"
"ext-dom": "*",
"php": ">=7.1.0",
"psr/log": "^1.0 || ^2.0 || ^3.0"
},
"require-dev": {
"phpunit/phpunit": "~3.7.10"
"monolog/monolog": "^1.0.0 || ^2.0.0",
"phpstan/phpstan": "^1.5",
"phpunit/phpunit": ">=7.5"
},
"type": "library",
"extra": {
@ -1624,6 +1628,9 @@
}
},
"autoload": {
"files": [
"source/CAS.php"
],
"classmap": [
"source/"
]
@ -1635,11 +1642,16 @@
"authors": [
{
"name": "Joachim Fritschi",
"homepage": "https://wiki.jasig.org/display/~fritschi"
"email": "jfritschi@freenet.de",
"homepage": "https://github.com/jfritschi"
},
{
"name": "Adam Franco",
"homepage": "https://wiki.jasig.org/display/~adamfranco"
"homepage": "https://github.com/adamfranco"
},
{
"name": "Henry Pan",
"homepage": "https://github.com/phy25"
}
],
"description": "Provides a simple API for authenticating users against a CAS server",
@ -1649,7 +1661,12 @@
"cas",
"jasig"
],
"time": "2019-08-18T20:01:55+00:00"
"support": {
"issues": "https://github.com/apereo/phpCAS/issues",
"source": "https://github.com/apereo/phpCAS/tree/1.6.1"
},
"abandoned": "apereo/phpcas",
"time": "2023-02-19T19:52:35+00:00"
},
{
"name": "knplabs/knp-snappy",

View File

@ -7,6 +7,7 @@ parameters:
appEnv: '%env(resolve:APP_ENV)%'
appSecret: '%env(resolve:APP_SECRET)%'
appInitpwdadmin: '%env(resolve:INITPWDADMIN)%'
protocole: '%env(resolve:PROTOCOLE)%'
appWeburl: '%env(resolve:APP_WEBURL)%'
appAuth: '%env(resolve:APP_AUTH)%'
@ -14,6 +15,19 @@ parameters:
appName: '%env(resolve:APP_NAME)%'
appCron: '%env(resolve:APP_CRON)%'
appNinegateactivate: '%env(resolve:NINEGATE_ACTIVATE)%'
appNinegateurl: '%env(resolve:NINEGATE_URL)%'
appNinegatesecret: '%env(resolve:NINEGATE_SECRET)%'
appNinegatemasteridentity: '%env(resolve:NINEGATE_MASTERIDENTITY)%'
casHost: '%env(resolve:CAS_HOST)%'
casPort: '%env(resolve:CAS_PORT)%'
casPath: '%env(resolve:CAS_PATH)%'
casUsername: '%env(resolve:CAS_USERNAME)%'
casMail: '%env(resolve:CAS_MAIL)%'
casLastname: '%env(resolve:CAS_LASTNAME)%'
casFirstname: '%env(resolve:CAS_FIRSTNAME)%'
databaseName: '%env(resolve:DATABASE_NAME)%'
databaseUser: '%env(resolve:DATABASE_USER)%'
databasePassword: '%env(resolve:DATABASE_PASSWORD)%'

View File

@ -373,7 +373,7 @@ th.dt-center, td.dt-center { text-align: center; }
.grid-item-size-8 { width: 80%; margin-bottom: 0%;float:left;}
.grid-item-size-9 { width: 90%; margin-bottom: 0%;float:left;}
.grid-item-full { width: 100%; margin-bottom: 0%; font-size:20px;float:left; }
.grid-item-full h1 {margin: 0; border:none; padding: 20px 0px 0px 10px; }
.grid-item-full h1 {margin: 0; border:none; padding: 20px 0px 0px 0px; }
.gutter-sizer { width: 0%;float:left; }
.member{display:flex; flex-direction: column; align-items: center; background-color: var(--colorbgbodydarkdarker); border-radius:10px; padding:10px;}
.member img{border-radius:100%;width:60px; height: 60px;}

View File

@ -13,6 +13,20 @@ class HomeController extends AbstractController
{
$em = $this->getDoctrine()->getManager();
if($this->getUser()) {
// Entete
$headers = ['Accept' => 'application/json', 'key' => $this->getParameter("appNinegatesecret")];
$query = [];
$url=$this->getParameter("appNinegateurl");
// Paramétrage unirest
\Unirest\Request::verifyPeer(false);
\Unirest\Request::verifyHost(false);
\Unirest\Request::timeout(5);
//dd($url.'/rest/user/'.$this->getUser()->getUsername());
$response = \Unirest\Request::get($url.'/rest/user/'.$this->getUser()->getUsername(),$headers,["only"=>"user,groups"]);
}
$users = $em->getRepository("App:User")->findBy([],["pseudo"=>"ASC"]);
$illustrations = $em->getRepository("App:Illustration")->findBy([],["submittime"=>"DESC"]);
$links = $em->getRepository("App:Link")->findBy(["user"=>null]);

View File

@ -44,9 +44,10 @@ class SecurityController extends AbstractController
$redirect = $this->get('session')->get("_security.main.target_path");
// Init Client CAS
$alias=$this->getParameter('appAlias');
\phpCAS::setDebug('/var/www/html/'.$alias.'/var/log/cas.log');
\phpCAS::client(CAS_VERSION_2_0, $this->getParameter('casHost'), intval($this->getParameter('casPort')), is_null($this->getParameter('casPath')) ? '' : $this->getParameter('casPath'), false);
$url=$this->getHost($request);
$url=str_replace("http://",$this->getParameter("protocole")."://",$url);
$url=str_replace("https://",$this->getParameter("protocole")."://",$url);
\phpCAS::client(CAS_VERSION_2_0, $this->getParameter('casHost'), intval($this->getParameter('casPort')), is_null($this->getParameter('casPath')) ? '' : $this->getParameter('casPath'), $url, false);
\phpCAS::setNoCasServerValidation();
@ -64,8 +65,8 @@ class SecurityController extends AbstractController
if(isset($attributes[$this->getParameter('casUsername')]))
$username = $attributes[$this->getParameter('casUsername')];
if(isset($attributes[$this->getParameter('casEmail')]))
$email = $attributes[$this->getParameter('casEmail')];
if(isset($attributes[$this->getParameter('casMail')]))
$email = $attributes[$this->getParameter('casMail')];
if(isset($attributes[$this->getParameter('casLastname')]))
$lastname = $attributes[$this->getParameter('casLastname')];
@ -100,6 +101,8 @@ class SecurityController extends AbstractController
$em->flush();
}
$this->updateNinegate($user);
// Sauvegarde des attributes en session
$this->get('session')->set('attributes', $attributes);
@ -120,44 +123,80 @@ class SecurityController extends AbstractController
return $this->redirect($this->generateUrl('app_home'));
}
public function logout() {
public function logout(Request $request) {
$auth_mode=$this->getParameter("appAuth");
switch($auth_mode) {
case "MYSQL":
return $this->logoutMYSQL();
return $this->logoutMYSQL($request);
break;
case "CAS":
return $this->logoutCAS();
return $this->logoutCAS($request);
break;
}
}
public function logoutMYSQL() {
public function logoutMYSQL(Request $request) {
$this->get('security.token_storage')->setToken(null);
$this->get('session')->invalidate();
return $this->redirect($this->generateUrl("app_home"));
}
public function logoutcas() {
$this->get('security.token_storage')->setToken(null);
$this->get('session')->invalidate();
public function logoutcas(Request $request) {
// Init Client CAS
$alias=$this->getParameter('appAlias');
\phpCAS::setDebug('/var/www/html/'.$alias.'/var/log/cas.log');
\phpCAS::client(CAS_VERSION_2_0, $this->getParameter('casHost'), intval($this->getParameter('casPort')), is_null($this->getParameter('casPath')) ? '' : $this->getParameter('casPath'), false);
$url=$this->getHost($request);
$url=str_replace("http://",$this->getParameter("protocole")."://",$url);
$url=str_replace("https://",$this->getParameter("protocole")."://",$url);
\phpCAS::client(CAS_VERSION_2_0, $this->getParameter('casHost'), intval($this->getParameter('casPort')), is_null($this->getParameter('casPath')) ? '' : $this->getParameter('casPath'), $url, false);
\phpCAS::setNoCasServerValidation();
// Logout
$url=$this->generateUrl('app_home', array(), UrlGeneratorInterface::ABSOLUTE_URL);
\phpCAS::logout(array("service"=>$url));
$url = $this->generateUrl('app_home', [], UrlGeneratorInterface::ABSOLUTE_URL);
$url=str_replace("http://",$this->getParameter("protocole")."://",$url);
$url=str_replace("https://",$this->getParameter("protocole")."://",$url);
\phpCAS::logout(['service' => $url]);
$this->tokenstorage->setToken(null);
$request->getSession()->invalidate();
return true;
}
private function updateNinegate($user) {
if($this->getParameter("appNinegateactivate") && $this->getParameter("appNinegatemasteridentity")=="SQL") {
// Entete
$headers = ['Accept' => 'application/json', 'key' => $this->getParameter("appNinegatesecret")];
$query = [];
$url=$this->getParameter("appNinegateurl");
// Paramétrage unirest
\Unirest\Request::verifyPeer(false);
\Unirest\Request::verifyHost(false);
\Unirest\Request::timeout(5);
try {
$response = \Unirest\Request::get($url.'/rest/user/'.$user->getUsername(),$headers,["only"=>"user"]);
$em = $this->getDoctrine()->getManager();
if(property_exists($response->body->user,'lastname')) $user->setLastname($response->body->user->lastname);
if(property_exists($response->body->user,'firstname')) $user->setFirstname($response->body->user->firstname);
if(property_exists($response->body->user,'usualname')) $user->setPseudo($response->body->user->usualname);
if(property_exists($response->body->user,'email')) $user->setEmail($response->body->user->email);
$em->flush();
}
catch (\Exception $e) {
}
}
}
private function getHost($request) {
$host = $request->getHost();
$protocol = $request->getScheme();
$port = $request->getPort();
return $protocol."://".$host.($port!=80&&$port!=443?":".$port:"");
}
}

View File

@ -26,7 +26,8 @@ class UserController extends AbstractController
$this->data."s" => $datas,
"useheader" => true,
"usesidebar" => true,
]);
'appNinegateactivate' => $this->getParameter("appNinegateactivate"),
'appNinegateurl' => $this->getParameter("appNinegateurl"), ]);
}
public function submit(Request $request)
@ -36,6 +37,9 @@ class UserController extends AbstractController
$data = new Entity();
$data->setAvatar("noavatar.png");
if($this->getParameter("appNinegateactivate")) return $this->redirectToRoute($this->route);
// Création du formulaire
$form = $this->createForm(Form::class,$data,array("mode"=>"submit"));
@ -61,7 +65,9 @@ class UserController extends AbstractController
'usesidebar' => true,
$this->data => $data,
'mode' => 'submit',
'form' => $form->createView()
'form' => $form->createView(),
'appNinegateactivate' => $this->getParameter("appNinegateactivate"),
'appNinegateurl' => $this->getParameter("appNinegateurl"),
]);
}
@ -72,8 +78,11 @@ class UserController extends AbstractController
$data=$em->getRepository($this->entity)->find($id);
$oldpassword=$data->getPassword();
// Récupération Nineage
$data=$this->updateNinegate($data);
// Création du formulaire
$form = $this->createForm(Form::class,$data,array("mode"=>"update","appAuth"=>$this->getParameter("appAuth")));
$form = $this->createForm(Form::class,$data,array("mode"=>"update","appNinegateactivate"=>$this->getParameter("appNinegateactivate")));
// Récupération des data du formulaire
$form->handleRequest($request);
@ -103,7 +112,9 @@ class UserController extends AbstractController
'usesidebar' => true,
$this->data => $data,
'mode' => 'update',
'form' => $form->createView()
'form' => $form->createView(),
'appNinegateactivate' => $this->getParameter("appNinegateactivate"),
'appNinegateurl' => $this->getParameter("appNinegateurl"),
]);
}
@ -135,8 +146,11 @@ class UserController extends AbstractController
$data=$this->getUser();
$oldpassword=$data->getPassword();
// Récupération Nineage
$data=$this->updateNinegate($data);
// Création du formulaire
$form = $this->createForm(Form::class,$data,array("mode"=>"profil","appAuth"=>$this->getParameter("appAuth")));
$form = $this->createForm(Form::class,$data,array("mode"=>"profil","appNinegateactivate"=>$this->getParameter("appNinegateactivate")));
// Récupération des data du formulaire
$form->handleRequest($request);
@ -166,7 +180,9 @@ class UserController extends AbstractController
'usesidebar' => false,
$this->data => $data,
'mode' => 'profil',
'form' => $form->createView()
'form' => $form->createView(),
'appNinegateactivate' => $this->getParameter("appNinegateactivate"),
'appNinegateurl' => $this->getParameter("appNinegateurl"),
]);
}
@ -239,4 +255,29 @@ class UserController extends AbstractController
}
}
}
private function updateNinegate($user) {
if($this->getParameter("appNinegateactivate") && $this->getParameter("appNinegatemasteridentity")=="SQL") {
// Entete
$headers = ['Accept' => 'application/json', 'key' => $this->getParameter("appNinegatesecret")];
$query = [];
$url=$this->getParameter("appNinegateurl");
\Unirest\Request::verifyPeer(false);
\Unirest\Request::verifyHost(false);
\Unirest\Request::timeout(5);
try {
$response = \Unirest\Request::get($url.'/rest/user/'.$user->getUsername(),$headers,["only"=>"user"]);
$em = $this->getDoctrine()->getManager();
if(property_exists($response->body->user,'lastname')) $user->setLastname($response->body->user->lastname);
if(property_exists($response->body->user,'firstname')) $user->setFirstname($response->body->user->firstname);
if(property_exists($response->body->user,'usualname')) $user->setPseudo($response->body->user->usualname);
if(property_exists($response->body->user,'email')) $user->setEmail($response->body->user->email);
$em->flush();
}
catch (\Exception $e) {
}
}
return $user;
}
}

View File

@ -395,8 +395,8 @@ class User implements UserInterface, \Serializable
public function setPseudo(?string $pseudo): self
{
$this->pseudo = $pseudo;
$pseudo=strtolower($pseudo);
$this->pseudo = $pseudo?$pseudo:$this->username;
$pseudo=strtolower($this->pseudo);
if($pseudo=="admin"||$pseudo=="user"||$pseudo=="feed"||$pseudo=="_uploader") $pseudo.="home";
$this->slug = $pseudo;
return $this;

View File

@ -45,6 +45,7 @@ class UserType extends AbstractType
$builder->add('pseudo',
TextType::class, [
"label" =>"Pseudo",
"disabled" => $options["appNinegateactivate"],
]
);
@ -86,6 +87,7 @@ class UserType extends AbstractType
$builder->add('lastname',
TextType::class, [
"label" =>"Nom",
"disabled" => $options["appNinegateactivate"],
]
);
@ -93,12 +95,14 @@ class UserType extends AbstractType
TextType::class, [
"label" =>"Prénom",
"required" => false,
"disabled" => $options["appNinegateactivate"],
]
);
$builder->add('email',
EmailType::class, [
"label" =>"Email",
"disabled" => $options["appNinegateactivate"],
]
);
@ -106,6 +110,7 @@ class UserType extends AbstractType
RepeatedType::class, [
"type" => PasswordType::class,
"required" => ($options["mode"]=="submit"?true:false),
"disabled" => $options["appNinegateactivate"],
"options" => array("always_empty" => true),
"first_options" => array("label" => "Mot de Passe","attr" => array("class" => "form-control", "style" => "margin-bottom:15px", "autocomplete" => "new-password")),
"second_options" => array('label' => 'Confirmer Mot de Passe',"attr" => array("class" => "form-control", "style" => "margin-bottom:15px"))
@ -118,7 +123,7 @@ class UserType extends AbstractType
$resolver->setDefaults(array(
'data_class' => 'App\Entity\User',
'mode' => 'string',
'appAuth' => 'string',
'appNinegateactivate' => 'boolean',
));
}
}

View File

@ -15,7 +15,7 @@
{{ form_widget(form.submit) }}
{% if mode=="profil" %}
<a class="btn btn-secondary" href={{ path('app_home_user',{userpseudo:user.pseudo}) }}>Annuler</a>
<a class="btn btn-secondary" href={{ path('app_home_user',{userpseudo:user.slug}) }}>Annuler</a>
{% else %}
<a class="btn btn-secondary" href={{ path('app_user') }}>Annuler</a>
{% endif %}
@ -75,6 +75,16 @@
{{ form_row(form.firstname) }}
{{ form_row(form.pseudo) }}
{{ form_row(form.email) }}
{% if mode!="submit" %}
{% if appNinegateactivate %}
{% if mode=="profil" %}
<a class="btn btn-info" style="width:100%" href="{{appNinegateurl}}/user?redirect={{app.request.uri}}">Modfier</a>
{% else %}
<a class="btn btn-info" style="width:100%" href="{{appNinegateurl}}/config/user/update/{{user.username}}?redirect={{app.request.uri}}">Modifier</a>
{% endif %}
{%endif%}
{%endif%}
</div>
</div>

View File

@ -5,7 +5,11 @@
UTILISATEURS
</h1>
{% if appNinegateactivate %}
<p><a class="btn btn-success" href={{ appNinegateurl }}/config/user/submit?redirect={{app.request.uri}}>Ajouter</a></p>
{% else %}
<p><a class="btn btn-success" href={{ path('app_user_submit') }}>Ajouter</a></p>
{% endif %}
<div class="card">
<div class="card-header">