Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.14 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AppBundle\Controller;
  4.  
  5. use AppBundle\AppBundle;
  6. use AppBundle\Entity\Task;
  7. use AppBundle\Entity\accounts;
  8. use AppBundle\Entity\rights;
  9. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\Form\Extension\Core\Type\TextType;
  13. use Symfony\Component\Form\Extension\Core\Type\DateType;
  14. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  15. use Symfony\Component\Security\Core\Security;
  16. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  17.  
  18.  
  19. class BelwayController extends Controller
  20. {
  21. /**
  22. * @Route("/", name="homepage")
  23. */
  24. public function homeAction(Request $request)
  25. {
  26. return $this->render('default/baseLayout.html.twig');
  27. }
  28. /**
  29. * @Route("/accounts", name="accounts")
  30. */
  31. public function accountAction(Request $request)
  32. {
  33. $account = new accounts();
  34.  
  35. $form = $this->createForm('AppBundle\Form\RegForm', $account);
  36. $form->handleRequest($request);
  37.  
  38. if ($form->isSubmitted() && $form->isValid()) {
  39.  
  40.  
  41. $em = $this->getDoctrine()->getManager();
  42.  
  43. $p_username = $form['username']->getData();
  44. $p_password = $form['password']->getData();
  45. $p_name = $form['name']->getData();
  46. $p_country = $form['country']->getData();
  47.  
  48. $factory = $this->get('security.encoder_factory');
  49. $encoder = $factory->getEncoder($this);
  50.  
  51. $account->setUsername($p_username);
  52. $account->setPassword($encoder->encodePassword($account->getPassword(),$account->getSalt()));
  53. $account->setName($p_name);
  54. $account->setCountry($p_country);
  55.  
  56. $em->persist($account);
  57.  
  58. $em->flush();
  59.  
  60. }
  61.  
  62.  
  63. return $this->render('accounts/accounts.html.twig', array(
  64. 'account' => $account,
  65. 'form' => $form->createView(),
  66. ));
  67. }
  68. /**
  69. * @Route("/login", name="login")
  70. */
  71. public function loginAction(Request $request)
  72. {
  73. $session = $request->getSession();
  74.  
  75. if ($request->attributes->has(Security::AUTHENTICATION_ERROR)) {
  76. $error = $request->attributes->get(Security::AUTHENTICATION_ERROR);
  77. } else {
  78. $error = $session->get(Security::AUTHENTICATION_ERROR);
  79. $session->remove(Security::AUTHENTICATION_ERROR);
  80. }
  81.  
  82. return $this->render('accounts/login.html.twig',
  83. array(
  84. 'last_username' => $session->get(Security::LAST_USERNAME),
  85. 'error' => $error,
  86. )
  87. );
  88. }
  89. /**
  90. * @Route("/logout", name="logout")
  91. */
  92. public function logoutAction() {
  93.  
  94.  
  95. }
  96.  
  97. /**
  98. * @Route("/users", name="users")
  99. */
  100. public function showAllAction() {
  101.  
  102. $users = $this->getDoctrine()
  103. ->getRepository(accounts::class)
  104. ->findAll();
  105.  
  106. return $this->render('users/users.html.twig', array('viewUsers' => $users));
  107.  
  108. }
  109.  
  110. /**
  111. * @Route("/account_show/{id}", name="account_show")
  112. */
  113. public function showOneAction($id) {
  114.  
  115. $users = $this->getDoctrine()
  116. ->getRepository(accounts::class)
  117. ->find($id);
  118.  
  119. return $this->render('users/show.html.twig', array('viewUser' => $users));
  120.  
  121. }
  122.  
  123. /**
  124. * @Route("/account_edit/{id}", name="account_edit")
  125. */
  126. public function editOneAction(Request $request , $id) {
  127.  
  128. $users = $this->getDoctrine()
  129. ->getRepository(accounts::class)
  130. ->find($id);
  131.  
  132. $em = $this->getDoctrine()->getManager();
  133. $account = $em->getRepository(accounts::class)->find($id);
  134. $form = $this->createForm('AppBundle\Form\EditForm', $account);
  135. $form->handleRequest($request);
  136.  
  137. if ($form->isSubmitted() && $form->isValid()) {
  138.  
  139. $em = $this->getDoctrine()->getManager();
  140. $account = $em->getRepository(accounts::class)->find($id);
  141.  
  142. $p_username = $form['username']->getData();
  143. $p_password = $form['password']->getData();
  144. $p_name = $form['name']->getData();
  145. $p_country = $form['country']->getData();
  146. $p_factory = $form['factory']->getData();
  147.  
  148. $factory = $this->get('security.encoder_factory');
  149. $encoder = $factory->getEncoder($this);
  150.  
  151. $account->setUsername($p_username);
  152. $account->setPassword($encoder->encodePassword($account->getPassword(),$account->getSalt()));
  153. $account->setName($p_name);
  154. $account->setCountry($p_country);
  155. $account->setFactory($p_factory);
  156.  
  157. $em->persist($account);
  158.  
  159. $em->flush();
  160.  
  161. }
  162.  
  163.  
  164. return $this->render('users/edit.html.twig', array(
  165. 'viewUser' => $users,
  166. 'form' => $form->createView(),
  167. ));
  168.  
  169.  
  170.  
  171. }
  172.  
  173. /**
  174. * @Route("/account_deact/{id}", name="account_deact")
  175. */
  176. public function editDeactivated(Request $request , $id) {
  177.  
  178. $em = $this->getDoctrine()->getManager();
  179. $account = $em->getRepository(accounts::class)->find($id);
  180.  
  181. if ($account->getActivated() == 1){$account->setActivated(0);};
  182.  
  183. $em->persist($account);
  184. $em->flush();
  185.  
  186. $users = $this->getDoctrine()
  187. ->getRepository(accounts::class)
  188. ->findAll();
  189.  
  190. return $this->render('users/users.html.twig', array('viewUsers' => $users));
  191.  
  192.  
  193.  
  194. }
  195.  
  196. /**
  197. * @Route("/account_act/{id}", name="account_act")
  198. */
  199. public function editActivated(Request $request , $id) {
  200.  
  201. $em = $this->getDoctrine()->getManager();
  202. $account = $em->getRepository(accounts::class)->find($id);
  203.  
  204. if ($account->getActivated() == 0){$account->setActivated(1);};
  205.  
  206. $em->persist($account);
  207. $em->flush();
  208.  
  209. $users = $this->getDoctrine()
  210. ->getRepository(accounts::class)
  211. ->findAll();
  212.  
  213. return $this->render('users/users.html.twig', array('viewUsers' => $users));
  214.  
  215.  
  216.  
  217. }
  218.  
  219. /**
  220. * @Route("/rightnew", name="rightnew")
  221. */
  222. public function rightAction(Request $request)
  223. {
  224. $rights = new rights();
  225.  
  226. $form = $this->createForm('AppBundle\Form\RightsRegForm', $rights);
  227. $form->handleRequest($request);
  228.  
  229. if ($form->isSubmitted() && $form->isValid()) {
  230.  
  231.  
  232. $em = $this->getDoctrine()->getManager();
  233.  
  234. $p_rightname = $form['rightname']->getData();
  235. $p_short = $form['short']->getData();
  236. $p_description = $form['description']->getData();
  237.  
  238.  
  239. $rights->setRightname($p_rightname);
  240. $rights->setShort($p_short);
  241. $rights->setDescription($p_description);
  242.  
  243. $em->persist($rights);
  244.  
  245. $em->flush();
  246.  
  247. }
  248. return $this->render('rightnew/rightnew.html.twig', array(
  249. 'rights' => $rights,
  250. 'form' => $form->createView(),
  251. ));
  252. }
  253.  
  254. /**
  255. * @Route("/rights", name="rights")
  256. */
  257. public function showAllRigtsAction() {
  258.  
  259. $rights = $this->getDoctrine()
  260. ->getRepository(rights::class)
  261. ->findAll();
  262.  
  263. return $this->render('rights/rights.html.twig', array('viewRights' => $rights));
  264.  
  265. }
  266.  
  267. /**
  268. * @Route("/right_edit/{id}", name="right_edit")
  269. */
  270. public function editOneRightAction(Request $request , $id) {
  271.  
  272. $rightss = $this->getDoctrine()
  273. ->getRepository(rights::class)
  274. ->find($id);
  275.  
  276. $em = $this->getDoctrine()->getManager();
  277. $rights = $em->getRepository(rights::class)->find($id);
  278. $form = $this->createForm('AppBundle\Form\RightEditForm', $rights);
  279. $form->handleRequest($request);
  280.  
  281. if ($form->isSubmitted() && $form->isValid()) {
  282.  
  283. $em = $this->getDoctrine()->getManager();
  284. $rights = $em->getRepository(rights::class)->find($id);
  285.  
  286. $em = $this->getDoctrine()->getManager();
  287.  
  288. $p_rightname = $form['rightname']->getData();
  289. $p_short = $form['short']->getData();
  290. $p_description = $form['description']->getData();
  291.  
  292.  
  293. $rights->setRightname($p_rightname);
  294. $rights->setShort($p_short);
  295. $rights->setDescription($p_description);
  296.  
  297. $em->persist($rights);
  298.  
  299. $em->flush();
  300.  
  301. }
  302.  
  303.  
  304. return $this->render('rights/edit.html.twig', array(
  305. 'viewRights' => $rightss,
  306. 'form' => $form->createView(),
  307. ));
  308.  
  309.  
  310.  
  311. }
  312.  
  313.  
  314. /**
  315. * @Route("/right_show/{id}", name="right_show")
  316. */
  317. public function showOneRightAction(Request $request , $id) {
  318.  
  319. $rightss = $this->getDoctrine()
  320. ->getRepository(rights::class)
  321. ->find($id);
  322.  
  323.  
  324.  
  325. return $this->render('rights/show.html.twig', array(
  326. 'viewRight' => $rightss,
  327. ));
  328.  
  329.  
  330.  
  331. }
  332.  
  333.  
  334.  
  335.  
  336. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement