src/Controller/PagesController.php line 392

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use App\Document\User;
  6. use App\Document\Newsletter;
  7. use Symfony\Component\Mailer\MailerInterface;
  8. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  9. use Symfony\Component\Mime\Address;
  10. use App\Service\EuodiaApiConnector;
  11. use MongoDB\BSON\UTCDateTime;
  12. use MongoDB\BSON\Regex;
  13. /*
  14. * reste à faire :
  15. * - notification Taux
  16. * - rajouter un bouton pouir installer l'appli
  17. */
  18. class PagesController extends AbstractBaseController {
  19. /**
  20. * @Route("/accueil", name="client_accueil")
  21. */
  22. public function accueil(Request $request, EuodiaApiConnector $api) {
  23. if (!$user = $this->getMyUser($request)) {
  24. return $this->redirectToRoute('client_login');
  25. }
  26. $datas = $user->getDatas();
  27. $folders = $api->getApporteurFolder($user->getEmail());
  28. $nbContact = 0;
  29. $nbInstruction = 0;
  30. $nbEnvoye = 0;
  31. $nbAccorde = 0;
  32. $nbAcceptation = 0;
  33. $nbRealise = 0;
  34. $totalCommission = 0;
  35. foreach ($folders as $f) {
  36. if ($f['statut'] != "PROSPECT") {
  37. $nbContact++;
  38. }
  39. if ($f['statut'] == "INSTRUCTION") {
  40. $nbInstruction++;
  41. }
  42. elseif ($f['statut'] == "ENVOYE_BANQUE") {
  43. $nbEnvoye++;
  44. }
  45. elseif ($f['statut'] == "ACCORDE_BANQUE") {
  46. $nbAccorde++;
  47. }
  48. elseif ($f['statut'] == "ACCEPTATION_CLIENT") {
  49. $nbAcceptation++;
  50. }
  51. elseif ($f['statut'] == "CLOTURE") {
  52. $nbRealise++;
  53. if ($datas['commissionsVisibles']) {
  54. $totalCommission += $f['commission'];
  55. }
  56. }
  57. }
  58. $stats = [
  59. [
  60. "name" => "Nombre de contacts",
  61. "help" => "Dossier en cours (qui ne sont plus en prospect) sur le total de dossiers.",
  62. "class" => "nb",
  63. "value" => $nbContact . " / " . count($folders)
  64. ],
  65. [
  66. "name" => "Instruction",
  67. "help" => "Le dossier est en cours de constitution.",
  68. "class" => "instruction",
  69. "value" => $nbInstruction
  70. ],
  71. [
  72. "name" => "Envoyé à la banque",
  73. "help" => "Un dossier complet a été envoyé à un partenaire bancaire (ou +) pour analyse et négociation.",
  74. "class" => "envoye",
  75. "value" => $nbEnvoye
  76. ],
  77. [
  78. "name" => "Accordé par la banque",
  79. "help" => "Le dossier a fait l'objet d'une ou plusieurs propositions de financement (accords) par des partenaires bancaires.",
  80. "class" => "accord",
  81. "value" => $nbAccorde
  82. ],
  83. [
  84. "name" => "Acceptation client",
  85. "help" => "Le client a accepté l'offre négociée avec un partenaire bancaire. ",
  86. "class" => "acceptation",
  87. "value" => $nbAcceptation
  88. ]
  89. ];
  90. /* if ($datas['commissionsVisibles']) {
  91. $stats[] = [
  92. "name" => "Commissions - " . $nbRealise . " finalisé" . ($nbRealise > 1 ? "s" : ""),
  93. "class" => "commission",
  94. "value" => number_format($totalCommission, 0, ",", " ") . " €"
  95. ];
  96. }
  97. else { */
  98. $stats[] = [
  99. "name" => "Finalisé",
  100. "class" => "realise",
  101. "value" => $nbRealise
  102. ];
  103. //}
  104. return $this->render("pages/home.html.twig", [
  105. 'user' => $user,
  106. 'folders' => $folders,
  107. 'stats' => $stats,
  108. 'params' => $_GET,
  109. 'titre' => 'Accueil'
  110. ]);
  111. }
  112. /**
  113. * @Route("/profil", name="client_profil", methods={"POST"})
  114. */
  115. public function profil(Request $request, EuodiaApiConnector $api) {
  116. if (!$user = $this->getMyUser($request)) {
  117. return $this->redirectToRoute('client_login');
  118. }
  119. $updateProfil = "";
  120. $pwd = trim($request->get('memberPwd'));
  121. if ($pwd) {
  122. if (!preg_match('/^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z]).{8,}$/', $pwd)) {
  123. $error = "";
  124. if (strlen($pwd) < 8) {
  125. $error = 'Le mot de passe doit faire au moins 8 caractères.<br>';
  126. }
  127. if (!preg_match('/^(?=.*[a-z]).{0,}$/', $pwd)) {
  128. $error .= 'Le mot de passe doit contenir au moins une lettre minuscule.<br>';
  129. }
  130. if (!preg_match('/^(?=.*[A-Z]).{0,}$/', $pwd)) {
  131. $error .= 'Le mot de passe doit contenir au moins une lettre majuscule.<br>';
  132. }
  133. if (!preg_match('/^(?=.*[0-9]).{0,}$/', $pwd)) {
  134. $error .= 'Le mot de passe doit contenir au moins un chiffre.<br>';
  135. }
  136. if ($error) {
  137. $this->addFlash('error', $error);
  138. }
  139. }
  140. else {
  141. $pwd = hash('sha256', hash('sha256', $pwd . $user->getId()) . $user->getId());
  142. $user->setPwd($pwd);
  143. $this->dmPersistFlush($user);
  144. $updateProfil .= "Votre mot de passe a été modifié avec succès.<br>";
  145. }
  146. }
  147. $datas = $user->getDatas();
  148. $notification = $user->getNotification();
  149. $notif = trim($request->get('notification_newsletter'));
  150. if ($notif == '0' || $notif == '1') {
  151. $notification['newsletter'] = (int) $notif;
  152. $notif = trim($request->get('notification_taux'));
  153. if ($notif == '0' || $notif == '1') {
  154. $notification['taux'] = (int) $notif;
  155. }
  156. $notif = trim($request->get('notification_message'));
  157. if ($notif == '0' || $notif == '1' || $notif == '2' || $notif == '3') {
  158. $notification['message'] = (int) $notif;
  159. }
  160. $notif = trim($request->get('notification_dossier'));
  161. if ($notif == '0' || $notif == '1' || $notif == '2' || $notif == '3') {
  162. $notification['dossier'] = (int) $notif;
  163. }
  164. $user->setNotification($notification);
  165. $this->dmPersistFlush($user);
  166. $updateProfil .= "Vos préférences de notifications ont bien été enregistrées.<br>";
  167. }
  168. $notificationJson = trim($request->get('notificationJson'));
  169. if ($notificationJson) {
  170. if ($notificationJson == "disable") {
  171. $notification['navigatorAuth'] = [];
  172. }
  173. else {
  174. $notification['navigatorAuth'][]['json'] = $notificationJson;
  175. }
  176. $user->setNotification($notification);
  177. $this->dmPersistFlush($user);
  178. $updateProfil .= "Les notifications du navigateur ont bien été " . ($notificationJson == "disable" ? "désactivées" : "activées") . "<br>";
  179. }
  180. if ($updateProfil) {
  181. return $this->json([
  182. 'status' => 'success',
  183. 'message' => $updateProfil
  184. ]);
  185. }
  186. else {
  187. return $this->json([
  188. 'status' => 'error',
  189. 'error' => 'Rien à mettre à jour.'
  190. ]);
  191. }
  192. }
  193. /**
  194. * @Route("/taux", name="member_taux")
  195. */
  196. public function taux(Request $request, EuodiaApiConnector $api) {
  197. if (!$user = $this->getMyUser($request)) {
  198. return $this->redirectToRoute('client_login');
  199. }
  200. $rates = $api->getApporteurRate($user->getDatas()['id']);
  201. $ratesMinMax = [
  202. "T15" => 100,
  203. "T20" => 100,
  204. "T25" => 100
  205. ];
  206. if (isset($rates["regionalRates"])) {
  207. usort($rates["regionalRates"], function ($a, $b) {
  208. return strcmp($a["year"] . "-" . $a['month'], $b["year"] . "-" . $b['month']);
  209. });
  210. $rates["regionalRates"] = array_reverse($rates["regionalRates"]);
  211. foreach ($rates["regionalRates"][0]['rates'] as $r) {
  212. if ($r['rateFifteenYears'] > 0 && $r['rateFifteenYears'] < $ratesMinMax['T15']) {
  213. $ratesMinMax['T15'] = $r['rateFifteenYears'];
  214. }
  215. if ($r['rateTwentyYears'] > 0 && $r['rateTwentyYears'] < $ratesMinMax['T20']) {
  216. $ratesMinMax['T20'] = $r['rateTwentyYears'];
  217. }
  218. if ($r['rateTwentyFiveYears'] > 0 && $r['rateTwentyFiveYears'] < $ratesMinMax['T25']) {
  219. $ratesMinMax['T25'] = $r['rateTwentyFiveYears'];
  220. }
  221. }
  222. }
  223. else {
  224. $rates["regionalRates"] = [];
  225. }
  226. return $this->render("pages/taux.html.twig", [
  227. 'user' => $user,
  228. 'rates' => $rates,
  229. 'ratesMinMax' => $ratesMinMax,
  230. 'titre' => 'Taux immobiliers'
  231. ]);
  232. }
  233. /**
  234. * @Route("/newsletters", name="member_newsletters")
  235. */
  236. public function newsletters(Request $request) {
  237. if (!$user = $this->getMyUser($request)) {
  238. return $this->redirectToRoute('client_login');
  239. }
  240. // search on assurance-vie
  241. $campaigns = $this->dm
  242. ->createQueryBuilder(Newsletter::class)
  243. ->sort('connectionAt', -1)
  244. ->limit(24)
  245. ->getQuery()->execute();
  246. return $this->render("pages/newsletters.html.twig", [
  247. 'user' => $user,
  248. 'titre' => 'Newsletters',
  249. 'campaigns' => $campaigns
  250. ]);
  251. }
  252. /**
  253. * @Route("/statistiques", name="member_statistiques")
  254. */
  255. public function statistiques(Request $request, EuodiaApiConnector $api) {
  256. if (!$user = $this->getMyUser($request)) {
  257. return $this->redirectToRoute('client_login');
  258. }
  259. $datas = $user->getDatas();
  260. if (!isset($datas['statisticsVisibles']) || !$datas['statisticsVisibles']) {
  261. return $this->redirectToRoute('client_login');
  262. }
  263. $filter = [
  264. "a" => $request->get('a'),
  265. "d" => $request->get('d'),
  266. "f" => $request->get('f')
  267. ];
  268. if (!$filter['d']) {
  269. $d = mktime(0, 0, 0, 1, 1, date('Y'));
  270. $filter['d'] = date('Y-m-d', $d);
  271. }
  272. else {
  273. $d = strtotime($filter['d']);
  274. }
  275. if (!$filter['f']) {
  276. $f = mktime(23, 59, 59, 12, 31, date('Y'));
  277. $filter['f'] = date('Y-m-d', $f);
  278. }
  279. else {
  280. $f = strtotime($filter['f']) + 86399;
  281. }
  282. $apporteurs = $api->getListApporteur($user->getEmail());
  283. if (!$filter['a']) {
  284. foreach ($apporteurs as $a => $v) {
  285. $filter['a'][] = $a;
  286. }
  287. }
  288. $ids = [];
  289. if ($filter['a'] && is_array($filter['a'])) {
  290. foreach ($filter['a'] as $a) {
  291. if (!in_array($a, $ids)) {
  292. $ids[] = $a;
  293. }
  294. }
  295. }
  296. return $this->render("pages/statistiques.html.twig", [
  297. 'user' => $user,
  298. 'titre' => 'Statistiques',
  299. 'filter' => $filter,
  300. 'apporteur' => $apporteurs,
  301. 'stats' => $api->getStatistiques(implode(",", $ids), date('c', $d), date('c', $f)),
  302. 'statsOld' => $api->getStatistiques(implode(",", $ids), date('c', $d - 31536000), date('c', $f - 31536000)),
  303. ]);
  304. }
  305. /**
  306. * @Route("/_ajax/search/", name="_ajax_search")
  307. */
  308. public function search(Request $request) {
  309. $response = [];
  310. return $this->json($response);
  311. }
  312. /**
  313. * @Route("/", name="client_login", methods={"GET","POST"})
  314. */
  315. public function login(Request $request) {
  316. if ($this->getMyUser($request)) {
  317. return $this->redirectToRoute('client_accueil');
  318. }
  319. $error = false;
  320. $email = trim($request->get('email'));
  321. $pwd = trim($request->get('password'));
  322. if ($email && $pwd) {
  323. $user = $this->dmGetRepo(User::class)->findOneBy(['email' => new Regex($email, 'i'), 'status' => true, 'datas.espacePartenaire' => true]);
  324. if ($user && $user->getPwd() == hash('sha256', hash('sha256', $pwd . $user->getId()) . $user->getId())) {
  325. $request->getSession()->set('user', $user);
  326. return $this->redirectToRoute('client_accueil');
  327. }
  328. else {
  329. $error = "Email et/ou mot de passe incorrect.";
  330. }
  331. }
  332. return $this->render('pages/login.html.twig', ['error' => $error, 'titre' => 'Connexion']);
  333. }
  334. /**
  335. * @Route("/logout", name="client_logout")
  336. */
  337. public function logout(Request $request) {
  338. $request->getSession()->remove('user');
  339. return $this->redirectToRoute('client_login');
  340. }
  341. /**
  342. * @Route("/forgotten-password", name="client_forgotten_password")
  343. */
  344. public function forgottenPassword(Request $request, MailerInterface $mail) {
  345. if ($this->getMyUser($request)) {
  346. return $this->redirectToRoute('client_accueil');
  347. }
  348. $error = false;
  349. $email = trim($request->get('email'));
  350. if ($email) {
  351. $user = $this->dmGetRepo(User::class)->findOneBy(['email' => new Regex($email, 'i'), 'status' => true, 'datas.espacePartenaire' => true]);
  352. if ($user) {
  353. $datas = $user->getDatas();
  354. $key = hash('sha256', $user->getId() . "|cv7a,_H)" . $user->getPwd() . "-7aU;f|" . date('Y-m-d'));
  355. $user->setForgottenPwd([
  356. "key" => $key,
  357. "date" => new UTCDateTime()
  358. ]);
  359. $this->dmPersistFlush($user);
  360. $lien = $this->generateUrl('client_forgotten_password_change', [], false) . "?id=" . $user->getId() . "&key=" . $key;
  361. $email = (new TemplatedEmail())
  362. ->from(new Address('noreply@artemiscourtage.com', 'Artemis Courtage'))
  363. ->to(new Address($_ENV['APP_ENV'] == "prod" ? $user->getEmail() : "n.theneaud@kiwilab.fr"))
  364. ->bcc(new Address("artemis@kiwilab.fr"))
  365. ->subject('Artemis Courtage - Mot de passe oublié')
  366. ->htmlTemplate('email/forgotten-password.html.twig')
  367. ->context(['datas' => $datas, 'lien' => $lien]);
  368. $mail->send($email);
  369. }
  370. $error = "Si vous disposez d'un compte vous allez recevoir un email pour réinitialiser votre mot de passe.";
  371. }
  372. return $this->render('pages/forgotten-password.html.twig', ['error' => $error, 'titre' => 'Mot de passe oublié']);
  373. }
  374. /**
  375. * @Route("/update-user-albr", name="client_user_update_albr", methods={"POST"})
  376. */
  377. public function updateUserAlbr(Request $request) {
  378. if ($this->getMyUser($request)) {
  379. return $this->redirectToRoute('client_accueil');
  380. }
  381. $email = trim($request->get('email'));
  382. $key = trim($request->get('key'));
  383. if ($email && $key && $key == 'cN.QB:T46791zdg}4]P£!O-LG') {
  384. $user = $this->dmGetRepo(User::class)->findOneBy(['email' => new Regex($email, 'i')]);
  385. if (!$user) {
  386. $user = new User();
  387. $user->setNotification([
  388. 'newsletter' => 1,
  389. 'taux' => 1,
  390. 'message' => 1,
  391. 'dossier' => 1
  392. ]);
  393. }
  394. $p = json_decode($request->getContent(), true);
  395. $pClean = $p;
  396. unset($pClean['email'], $pClean['pictureFile'], $pClean['isDisabled']);
  397. $user
  398. ->setDatas($pClean)
  399. ->setEmail($p['email'])
  400. ->setStatus(!$p['isDisabled']);
  401. $this->dmPersistFlush($user);
  402. return $this->json(['ok' => true]);
  403. }
  404. else {
  405. return $this->json(['error' => 'url et/ou paramètres inccorects'], 400);
  406. }
  407. }
  408. /**
  409. * @Route("/invitation-password-simple", name="client_invitation_password_simple")
  410. */
  411. public function invitationPasswordSimple(Request $request, MailerInterface $mail, EuodiaApiConnector $api) {
  412. if ($this->getMyUser($request)) {
  413. return $this->redirectToRoute('client_accueil');
  414. }
  415. $email = trim($request->get('email'));
  416. $emailCourtier = trim($request->get('emailCourtier'));
  417. $key = trim($request->get('key'));
  418. if ($email && $emailCourtier && $key && $key == 'cN.QB:T46791zdg}4]P£!O-LG') {
  419. $user = $this->dmGetRepo(User::class)->findOneBy(['email' => new Regex($email, 'i'), 'status' => true, 'datas.espacePartenaire' => true]);
  420. if ($user) {
  421. $key = hash('sha256', $user->getId() . "|cv7a,_H)" . $user->getPwd() . "-7aU;f|" . date('Y-m-d'));
  422. $user->setForgottenPwd([
  423. "key" => $key,
  424. "date" => new UTCDateTime()
  425. ]);
  426. $this->dmPersistFlush($user);
  427. $from = new Address($emailCourtier, 'Artemis Courtage');
  428. $email = (new TemplatedEmail())
  429. ->from($from)
  430. ->to(new Address($_ENV['APP_ENV'] == "prod" ? $user->getEmail() : "n.theneaud@kiwilab.fr"))
  431. ->bcc($from)
  432. ->addBcc(new Address("artemis@kiwilab.fr"))
  433. ->subject('Artemis Courtage - Invitation de connexion')
  434. ->htmlTemplate('email/invitation.html.twig')
  435. ->context([
  436. 'user' => $user,
  437. 'lien' => $this->generateUrl('client_forgotten_password_change', [], false) . "?id=" . $user->getId() . "&key=" . $key
  438. ]);
  439. $mail->send($email);
  440. return $this->json(['ok' => true]);
  441. }
  442. else {
  443. return $this->json(['error' => 'email not found'], 400);
  444. }
  445. }
  446. else {
  447. return $this->json(['error' => 'url et/ou paramètres inccorects'], 400);
  448. }
  449. }
  450. /**
  451. * @Route("/autologin-albr", name="client_autologin_albr")
  452. */
  453. public function autoLoginAlbr(Request $request, EuodiaApiConnector $api) {
  454. $email = trim($request->get('email'));
  455. $key = trim($request->get('key'));
  456. if ($email && $key && $key == 'cN.QB:T46791zdg}4]P£!O-LG') {
  457. $user = $this->dmGetRepo(User::class)->findOneBy(['email' => new Regex($email, 'i'), 'status' => true, 'datas.espacePartenaire' => true]);
  458. if ($user) {
  459. return $this->json(['autologin' => $this->generateUrl('client_autologin_client', [], false) . "?id=" . $user->getId() . "&key=" . hash('sha256', $user->getId() . "|cv7a,_H)" . $user->getPwd() . "-7aU;f|" . date('Y-m-d') . "T" . floor(date('H') * 60 * 60 + date('i') * 60 + date('s') / 60))]);
  460. }
  461. else {
  462. return $this->json(['error' => 'email not found'], 400);
  463. }
  464. }
  465. else {
  466. return $this->json(['error' => 'url et/ou paramètres inccorects'], 400);
  467. }
  468. }
  469. /**
  470. * @Route("/autologin-client", name="client_autologin_client")
  471. */
  472. public function autoLoginClient(Request $request) {
  473. $id = trim($request->get('id'));
  474. $key = trim($request->get('key'));
  475. if ($id && $key) {
  476. $user = $this->dmGetRepo(User::class)->findOneBy(['id' => $id, 'status' => true, 'datas.espacePartenaire' => true]);
  477. if ($user && $key == hash('sha256', $user->getId() . "|cv7a,_H)" . $user->getPwd() . "-7aU;f|" . date('Y-m-d') . "T" . floor(date('H') * 60 * 60 + date('i') * 60 + date('s') / 60))) {
  478. $request->getSession()->set('user', $user);
  479. return $this->redirectToRoute('client_accueil');
  480. }
  481. else {
  482. $this->addFlash('error', "Erreur : Lien expiré.");
  483. return $this->redirectToRoute('client_accueil');
  484. }
  485. }
  486. else {
  487. $this->addFlash('error', "Erreur : Lien incomplet.");
  488. return $this->redirectToRoute('client_accueil');
  489. }
  490. }
  491. /**
  492. * @Route("/forgotten-password-change", name="client_forgotten_password_change")
  493. */
  494. public function forgottenPasswordChange(Request $request) {
  495. $id = $request->get('id');
  496. $key = $request->get('key');
  497. if ($id && $key) {
  498. $user = $this->dmGetRepo(User::class)->findOneBy(['id' => $id, 'status' => true, 'datas.espacePartenaire' => true]);
  499. if ($user && isset($user->getForgottenPwd()['key']) && $key == $user->getForgottenPwd()['key'] && $user->getForgottenPwd()['date']->toDateTime()->getTimestamp() >= time() - 7 * 24 * 60 * 60) {
  500. $error = false;
  501. $pwd1 = trim($request->get('pwd1'));
  502. $pwd2 = trim($request->get('pwd2'));
  503. if ($pwd1 && $pwd2) {
  504. if ($pwd1 != $pwd2) {
  505. $error = "Les mots de passe ne sont pas identiques.";
  506. }
  507. elseif (!preg_match('/^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z]).{8,}$/', $pwd1)) {
  508. if (strlen($pwd1) < 8) {
  509. $error = 'Le mot de passe doit faire au moins 8 caractères.<br>';
  510. }
  511. if (!preg_match('/^(?=.*[a-z]).{0,}$/', $pwd1)) {
  512. $error .= 'Le mot de passe doit contenir au moins une lettre minuscule.<br>';
  513. }
  514. if (!preg_match('/^(?=.*[A-Z]).{0,}$/', $pwd1)) {
  515. $error .= 'Le mot de passe doit contenir au moins une lettre majuscule.<br>';
  516. }
  517. if (!preg_match('/^(?=.*[0-9]).{0,}$/', $pwd1)) {
  518. $error .= 'Le mot de passe doit contenir au moins un chiffre.<br>';
  519. }
  520. }
  521. else {
  522. $pwd = hash('sha256', hash('sha256', $pwd1 . $user->getId()) . $user->getId());
  523. $user->setPwd($pwd);
  524. $this->dmPersistFlush($user);
  525. $this->addFlash('success', "Votre mot de passe a été modifié avec succès.");
  526. return $this->redirectToRoute('client_accueil');
  527. }
  528. }
  529. return $this->render('pages/forgotten-password-change.html.twig', ['error' => $error, 'titre' => 'Connexion']);
  530. }
  531. else {
  532. $this->addFlash('error', "Erreur : Lien de changement de mot de passe expiré.");
  533. return $this->redirectToRoute('client_forgotten_password');
  534. }
  535. }
  536. else {
  537. $this->addFlash('error', "Erreur : Paramètre(s) manquant(s).");
  538. return $this->redirectToRoute('client_accueil');
  539. }
  540. }
  541. /**
  542. * @Route("/send-contact", name="client_send_contact", methods={"POST"})
  543. */
  544. public function sendContact(Request $request, EuodiaApiConnector $api, MailerInterface $mail) {
  545. if (!$user = $this->getMyUser($request)) {
  546. return $this->redirectToRoute('client_login');
  547. }
  548. $infos = $request->request->all();
  549. $valid = array_reduce(['civilite', 'nom', 'prenom', 'email', 'tel', 'premier', 'type', 'projet', 'destination'], function ($acc, $item) use ($infos) {
  550. return $acc &= !empty($infos[$item]);
  551. }, true);
  552. if (!$valid) {
  553. return $this->json([
  554. 'status' => 'error',
  555. 'error' => 'Données manquantes ! Merci de bien remplir correctement les champs !'
  556. ]);
  557. }
  558. else {
  559. $datas = $user->getDatas();
  560. $d = [
  561. "webSourceName" => "espaceaffaire",
  562. "baseTypeDDP" => (int) $infos['type'],
  563. "clientNbClient" => 1,
  564. "prjType" => (int) $infos['projet'],
  565. "prjDestine" => (int) $infos['destination'],
  566. "prjIs1erAchat" => ($infos['premier'] == "oui" ? true : false),
  567. "baseIdAgent" => $datas['memberId'], //ID DU MEMBRE
  568. "baseIdParrain" => $datas['idCifacil'], //ID CIFACIL ATTENTION BIEN CIFACIL DE L'APPORTEUR
  569. "emailApporteur" => $user->getEmail(),
  570. "civilite" => (int) $infos['civilite'],
  571. "nom" => $infos['nom'],
  572. "prenom" => $infos['prenom'],
  573. "email" => $infos['email'],
  574. "telMobile" => $infos['tel']
  575. ];
  576. if ($infos['dpe']) {
  577. $d["prjTypePE"] = (int) $infos['dpe'];
  578. }
  579. $r = $api->sendLead($d);
  580. /* echo '<pre>';
  581. print_r($api->sendLead($d));
  582. echo json_encode($d);
  583. exit; */
  584. $email = (new TemplatedEmail())
  585. ->from(new Address('noreply@artemiscourtage.com', 'Artemis Courtage'))
  586. ->to(new Address($_ENV['APP_ENV'] == "prod" ? $r['emailCourtier'] : "n.theneaud@kiwilab.fr"))
  587. ->bcc(new Address("artemis@kiwilab.fr"))
  588. ->subject('Artemis Courtage - Envoi d\'un contact')
  589. ->htmlTemplate('email/send-contact.html.twig')
  590. ->context([
  591. 'user' => $user,
  592. 'datas' => $infos
  593. ]);
  594. $mail->send($email);
  595. return $this->json([
  596. 'status' => 'success',
  597. 'debug' => $r
  598. ]);
  599. }
  600. }
  601. /**
  602. * @Route("/message", name="client_message")
  603. */
  604. public function message(Request $request, EuodiaApiConnector $api) {
  605. if (!$user = $this->getMyUser($request)) {
  606. return $this->redirectToRoute('client_login');
  607. }
  608. $id = $request->query->get('id');
  609. if ($id) {
  610. return $this->json($api->getMessage($user->getEmail(), $id));
  611. }
  612. return $this->json([]);
  613. }
  614. /**
  615. * @Route("/message-send", name="client_message_send", methods={"POST"})
  616. */
  617. public function messageSend(Request $request, EuodiaApiConnector $api) {
  618. if (!$user = $this->getMyUser($request)) {
  619. return $this->redirectToRoute('client_login');
  620. }
  621. $id = $request->get('id');
  622. $content = $request->get('content');
  623. if ($id && $content) {
  624. return $this->json($api->setMessage($user->getEmail(), $id, $content));
  625. }
  626. return $this->json(["error" => "Erreur : Paramètre(s) manquant(s)."]);
  627. }
  628. /**
  629. * @Route("/notification", name="client_notification")
  630. */
  631. public function notification(Request $request, EuodiaApiConnector $api) {
  632. if (!$user = $this->getMyUser($request)) {
  633. return $this->redirectToRoute('client_login');
  634. }
  635. $notifs = $api->getNotification($user->getEmail());
  636. foreach ($user->getNotificationOtherList() as $t => $n) {
  637. if ($n['type'] == "TAUX" || $n['type'] == "NEWSLETTER") {
  638. $notifs[] = [
  639. "id" => $t,
  640. "type" => $n['type'],
  641. "content" => $n['content'],
  642. "creationDate" => $n['creationDate']->toDateTime()->format(DATE_ISO8601),
  643. "seenDate" => $n['seenDate'] ? $n['seenDate']->toDateTime()->format(DATE_ISO8601) : null
  644. ];
  645. }
  646. }
  647. usort($notifs, function ($a, $b) {
  648. if (strtotime($a['creationDate']) == strtotime($b['creationDate'])) {
  649. return 0;
  650. }
  651. return strtotime($a['creationDate']) > strtotime($b['creationDate']) ? -1 : 1;
  652. });
  653. return $this->json($notifs);
  654. }
  655. /**
  656. * @Route("/notification-lu", name="client_notification_lu", methods={"POST"})
  657. */
  658. public function notificationLu(Request $request, EuodiaApiConnector $api) {
  659. if (!$user = $this->getMyUser($request)) {
  660. return $this->redirectToRoute('client_login');
  661. }
  662. $dossiers = [];
  663. $messages = [];
  664. $id = $request->get('id');
  665. if (!is_array($id)) {
  666. $id = [$id];
  667. }
  668. foreach ($id as $v) {
  669. $v = explode('-', $v);
  670. if (count($v) != 2) {
  671. return $this->json([
  672. 'status' => 'error'
  673. ]);
  674. }
  675. if ($v[0] == "NEWSLETTER") {
  676. $notifs = $user->getNotificationOtherList();
  677. $notifs[$v[1]]['seenDate'] = ($request->get('lu') ? new UTCDateTime() : null);
  678. $user->setNotificationOtherList($notifs);
  679. $this->dmPersistFlush($user);
  680. }
  681. else {
  682. $dossiers[] = $v[0];
  683. $messages[] = $v[1];
  684. }
  685. }
  686. if (count($dossiers) > 0) {
  687. $api->setMessageSeen($user->getEmail(), $dossiers, $messages, $request->get('lu'));
  688. }
  689. return $this->json([
  690. 'status' => 'success'
  691. ]);
  692. }
  693. /**
  694. * @Route("/manifest.webmanifest", name="manifest")
  695. */
  696. public function manifest() {
  697. return $this->json([
  698. "name" => "Espace Affaires - Artemis Courtage",
  699. "short_name" => "Espace Affaires",
  700. "description" => "Espace Affaires de la société Artemis Courtage",
  701. "icons" => [
  702. [
  703. "src" => "/sw/icon.svg",
  704. "sizes" => "144x144",
  705. "type" => "image/svg+xml",
  706. "purpose" => "any"
  707. ]],
  708. "start_url" => "/accueil",
  709. "display" => "standalone",
  710. "background_color" => "#1F1D25",
  711. "theme_color" => "#000000",
  712. "screenshots" => [
  713. [
  714. "src" => "/sw/screenshot1.png",
  715. "sizes" => "1280x720",
  716. "type" => "image/png",
  717. "form_factor" => "wide",
  718. "label" => "List of folders"
  719. ],
  720. [
  721. "src" => "/sw/screenshot2.png",
  722. "sizes" => "391x869",
  723. "type" => "image/png",
  724. "form_factor" => "narrow",
  725. "label" => "List of folders"
  726. ]
  727. ]
  728. ]);
  729. }
  730. protected function getMyUser($request) {
  731. $user = $request->getSession()->get('user');
  732. $u = false;
  733. if ($user) {
  734. $u = $this->dmGetRepo(User::class)->findOneBy(['id' => $user->getId(), 'status' => true, 'datas.espacePartenaire' => true]);
  735. if (!$u->getStatus()) {
  736. $u = false;
  737. }
  738. else {
  739. $u->setConnectionAt(time());
  740. $this->dmPersistFlush($u);
  741. }
  742. }
  743. return $u;
  744. }
  745. }