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

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

@ -24,9 +24,10 @@ class UserController extends AbstractController
return $this->render($this->render.'list.html.twig',[
$this->data."s" => $datas,
"useheader" => true,
"usesidebar" => true,
]);
"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',
));
}
}