Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace AppBundle\Controller;
- use AppBundle\AppBundle;
- use AppBundle\Entity\Task;
- use AppBundle\Entity\accounts;
- use AppBundle\Entity\rights;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\Form\Extension\Core\Type\TextType;
- use Symfony\Component\Form\Extension\Core\Type\DateType;
- use Symfony\Component\Form\Extension\Core\Type\SubmitType;
- use Symfony\Component\Security\Core\Security;
- use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
- class BelwayController extends Controller
- {
- /**
- * @Route("/", name="homepage")
- */
- public function homeAction(Request $request)
- {
- return $this->render('default/baseLayout.html.twig');
- }
- /**
- * @Route("/accounts", name="accounts")
- */
- public function accountAction(Request $request)
- {
- $account = new accounts();
- $form = $this->createForm('AppBundle\Form\RegForm', $account);
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid()) {
- $em = $this->getDoctrine()->getManager();
- $p_username = $form['username']->getData();
- $p_password = $form['password']->getData();
- $p_name = $form['name']->getData();
- $p_country = $form['country']->getData();
- $factory = $this->get('security.encoder_factory');
- $encoder = $factory->getEncoder($this);
- $account->setUsername($p_username);
- $account->setPassword($encoder->encodePassword($account->getPassword(),$account->getSalt()));
- $account->setName($p_name);
- $account->setCountry($p_country);
- $em->persist($account);
- $em->flush();
- }
- return $this->render('accounts/accounts.html.twig', array(
- 'account' => $account,
- 'form' => $form->createView(),
- ));
- }
- /**
- * @Route("/login", name="login")
- */
- public function loginAction(Request $request)
- {
- $session = $request->getSession();
- if ($request->attributes->has(Security::AUTHENTICATION_ERROR)) {
- $error = $request->attributes->get(Security::AUTHENTICATION_ERROR);
- } else {
- $error = $session->get(Security::AUTHENTICATION_ERROR);
- $session->remove(Security::AUTHENTICATION_ERROR);
- }
- return $this->render('accounts/login.html.twig',
- array(
- 'last_username' => $session->get(Security::LAST_USERNAME),
- 'error' => $error,
- )
- );
- }
- /**
- * @Route("/logout", name="logout")
- */
- public function logoutAction() {
- }
- /**
- * @Route("/users", name="users")
- */
- public function showAllAction() {
- $users = $this->getDoctrine()
- ->getRepository(accounts::class)
- ->findAll();
- return $this->render('users/users.html.twig', array('viewUsers' => $users));
- }
- /**
- * @Route("/account_show/{id}", name="account_show")
- */
- public function showOneAction($id) {
- $users = $this->getDoctrine()
- ->getRepository(accounts::class)
- ->find($id);
- return $this->render('users/show.html.twig', array('viewUser' => $users));
- }
- /**
- * @Route("/account_edit/{id}", name="account_edit")
- */
- public function editOneAction(Request $request , $id) {
- $users = $this->getDoctrine()
- ->getRepository(accounts::class)
- ->find($id);
- $em = $this->getDoctrine()->getManager();
- $account = $em->getRepository(accounts::class)->find($id);
- $form = $this->createForm('AppBundle\Form\EditForm', $account);
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid()) {
- $em = $this->getDoctrine()->getManager();
- $account = $em->getRepository(accounts::class)->find($id);
- $p_username = $form['username']->getData();
- $p_password = $form['password']->getData();
- $p_name = $form['name']->getData();
- $p_country = $form['country']->getData();
- $p_factory = $form['factory']->getData();
- $factory = $this->get('security.encoder_factory');
- $encoder = $factory->getEncoder($this);
- $account->setUsername($p_username);
- $account->setPassword($encoder->encodePassword($account->getPassword(),$account->getSalt()));
- $account->setName($p_name);
- $account->setCountry($p_country);
- $account->setFactory($p_factory);
- $em->persist($account);
- $em->flush();
- }
- return $this->render('users/edit.html.twig', array(
- 'viewUser' => $users,
- 'form' => $form->createView(),
- ));
- }
- /**
- * @Route("/account_deact/{id}", name="account_deact")
- */
- public function editDeactivated(Request $request , $id) {
- $em = $this->getDoctrine()->getManager();
- $account = $em->getRepository(accounts::class)->find($id);
- if ($account->getActivated() == 1){$account->setActivated(0);};
- $em->persist($account);
- $em->flush();
- $users = $this->getDoctrine()
- ->getRepository(accounts::class)
- ->findAll();
- return $this->render('users/users.html.twig', array('viewUsers' => $users));
- }
- /**
- * @Route("/account_act/{id}", name="account_act")
- */
- public function editActivated(Request $request , $id) {
- $em = $this->getDoctrine()->getManager();
- $account = $em->getRepository(accounts::class)->find($id);
- if ($account->getActivated() == 0){$account->setActivated(1);};
- $em->persist($account);
- $em->flush();
- $users = $this->getDoctrine()
- ->getRepository(accounts::class)
- ->findAll();
- return $this->render('users/users.html.twig', array('viewUsers' => $users));
- }
- /**
- * @Route("/rightnew", name="rightnew")
- */
- public function rightAction(Request $request)
- {
- $rights = new rights();
- $form = $this->createForm('AppBundle\Form\RightsRegForm', $rights);
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid()) {
- $em = $this->getDoctrine()->getManager();
- $p_rightname = $form['rightname']->getData();
- $p_short = $form['short']->getData();
- $p_description = $form['description']->getData();
- $rights->setRightname($p_rightname);
- $rights->setShort($p_short);
- $rights->setDescription($p_description);
- $em->persist($rights);
- $em->flush();
- }
- return $this->render('rightnew/rightnew.html.twig', array(
- 'rights' => $rights,
- 'form' => $form->createView(),
- ));
- }
- /**
- * @Route("/rights", name="rights")
- */
- public function showAllRigtsAction() {
- $rights = $this->getDoctrine()
- ->getRepository(rights::class)
- ->findAll();
- return $this->render('rights/rights.html.twig', array('viewRights' => $rights));
- }
- /**
- * @Route("/right_edit/{id}", name="right_edit")
- */
- public function editOneRightAction(Request $request , $id) {
- $rightss = $this->getDoctrine()
- ->getRepository(rights::class)
- ->find($id);
- $em = $this->getDoctrine()->getManager();
- $rights = $em->getRepository(rights::class)->find($id);
- $form = $this->createForm('AppBundle\Form\RightEditForm', $rights);
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid()) {
- $em = $this->getDoctrine()->getManager();
- $rights = $em->getRepository(rights::class)->find($id);
- $em = $this->getDoctrine()->getManager();
- $p_rightname = $form['rightname']->getData();
- $p_short = $form['short']->getData();
- $p_description = $form['description']->getData();
- $rights->setRightname($p_rightname);
- $rights->setShort($p_short);
- $rights->setDescription($p_description);
- $em->persist($rights);
- $em->flush();
- }
- return $this->render('rights/edit.html.twig', array(
- 'viewRights' => $rightss,
- 'form' => $form->createView(),
- ));
- }
- /**
- * @Route("/right_show/{id}", name="right_show")
- */
- public function showOneRightAction(Request $request , $id) {
- $rightss = $this->getDoctrine()
- ->getRepository(rights::class)
- ->find($id);
- return $this->render('rights/show.html.twig', array(
- 'viewRight' => $rightss,
- ));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement