Дипломная работа: Автоматизация документооборота организации ООО "АРСтрой"

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам
102
->setPassword($encoder->encodePassword($user, $user-
>getPassword()));
$this->manager->persist($user);
$this->manager->flush();
$this->addNotice('success',
'users.html.twig',
array('notice' => 'user_added', 'username' => $user->getUsername())
);
return $this->redirectToRoute('site_users_index');
}
}
$this->forms['user'] = $form->createView();
$this->navigation = array('active' => 'users');
return $this->render('AppBundle:Users:add.html.twig');
}
}
/**
* @param User $user
* @return RedirectResponse|Response
* @Config\Route("/users/{user}/edit", name = "site_users_edit")
* @Config\ParamConverter("user", options = {"mapping": {"user": "id"}})
*/
public function editAction(User $user)
{
if (!($this->authChecker->isGranted(Role::ADMIN))) {
return $this->redirectToRoute('homepage');
}
else {
$password = $user->getPassword();
$form = $this->createForm(new UserFormType(), $user);
$form->handleRequest($this->request);
if ($form->isSubmitted() && $form->isValid()) {
$valid = true;
$sames = $this->getRepository('User')->createQueryBuilder('u')
->select('COUNT(u.id) AS id')
->where('u.username = :username')
->andWhere('u.id <> :id')
->setParameters(array('username' => $user->getUsername(), 'id' => $user-
>getId()))
->getQuery()->getSingleScalarResult();
if ($sames > 0) {
$form->get('username')->addError(new
FormError('Пользователь с таким логином уже
существует.'));
$valid = false;
}
if ($valid) {
if (!is_null($form->get('password')->getData())) {
103
/** @var UserPasswordEncoder $encoder */
$encoder = $this->get('security.password_encoder');
$user->setSalt(User::generateSalt())
->setPassword($encoder->encodePassword($user, $user-
>getPassword()));
} else {
$user->setPassword($password);
}
$this->manager->persist($user);
$this->manager->flush();
$this->addNotice('success',
'users.html.twig',
array('notice' => 'user_changed', 'username' => $user->getUsername())
);
return $this->redirectToRoute('site_users_index');
}
}
$this->forms['user'] = $form->createView();
$this->view['user'] = $user;
$this->navigation = array('active' => 'users');
return $this->render('AppBundle:Users:edit.html.twig');
}
}
/**
* @param User $user
* @return Response
* @Config\Route("/users/{user}/remove", name = "site_users_remove")
* @Config\ParamConverter("user", options = {"mapping": {"user": "id"}})
*/
public function removeAction(User $user)
{
$user->setDeleted(true);
$this->manager->persist($user);
$this->manager->flush();
return $this->redirectToRoute('site_users_index');
}
}
<?php
namespace AppBundle\Controller;
use AppBundle\Form\Type\LoginFormType;
use AppBundle\Form\Type\ProfileFormType;
use AppBundle\Controller\InitializableController;
use AppBundle\Entity\Role;
use AppBundle\Entity\User;
use Sensio\Bundle\FrameworkExtraBundle\Configuration as Config;
use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
104
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoder;
use Symfony\Component\Security\Core\Security;
class SecurityController extends InitializableController
{
/**
* @return RedirectResponse|Response
* @Config\Route("/login", name = "site_security_login")
*/
public function loginAction()
{
if ($this->authChecker->isGranted(Role::USER)) return $this-
>redirectToRoute('homepage');
$error = null;
if ($this->request->attributes->has(Security::AUTHENTICATION_ERROR))
$error = $this->request->attributes-
>get(Security::AUTHENTICATION_ERROR);
else {
$error = $this->session->get(Security::AUTHENTICATION_ERROR, null);
$this->session->remove(Security::AUTHENTICATION_ERROR);
}
if (!is_null($error)) {
$this->addNotice('error', 'security_login.html.twig', array('notice' =>
'auth_error'));
}
$form = $this->createForm(new LoginFormType(), new User());
$this->navigation = array('active' => 'login');
$this->forms = array(
'login' => $form->createView(),
'last_username' => $this->session->get(Security::LAST_USERNAME, null)
);
return $this->render('AppBundle:Security:login.html.twig');
}
/**
* @throws NotFoundHttpException
* @Config\Route("/login-check", name = "site_security_login_check")
*/
public function loginCheckAction()
{
throw $this->createNotFoundException();
}
/**
* @throws NotFoundHttpException
* @Config\Route("/logout", name = "site_security_logout")
*/
public function logoutAction()
{
throw $this->createNotFoundException();
105
}
/**
* @return RedirectResponse|Response
* @Config\Route("/profile", name = "site_security_profile")
*/
public function profileAction()
{
$form = $this->createForm(new ProfileFormType(), $this->user);
$form->handleRequest($this->request);
if ($form->isSubmitted() && $form->isValid()) {
if (!is_null($form->get('password')->getData())) {
/** @var UserPasswordEncoder $encoder */
$encoder = $this->get('security.password_encoder');
$this->user->setSalt(User::generateSalt())
->setPassword($encoder->encodePassword($this->user, $this->user-
>getPassword()));
$this->manager->persist($this->user);
$this->manager->flush();
}
$this->addNotice('success',
'security_profile.html.twig',
array('notice' => 'user_changed')
);
return $this->redirectToRoute('homepage');
}
$this->forms['profile'] = $form->createView();
$this->navigation = array('active' => 'homepage');
return $this->render('AppBundle:Security:profile.html.twig');
}
}
Источник: https://baza.diplomsite.ru/previewfile/1738