-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserAccountController.php
More file actions
71 lines (61 loc) · 2.12 KB
/
UserAccountController.php
File metadata and controls
71 lines (61 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace Dayspring\LoginBundle\Controller;
use Dayspring\LoginBundle\Form\Type\UserType;
use Dayspring\LoginBundle\Model\User;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\User\UserProviderInterface;
class UserAccountController extends AbstractController
{
protected $userProvider;
public function __construct(UserProviderInterface $userProvider)
{
$this->userProvider = $userProvider;
}
/**
* @Route("/account", name="account_dashboard")
* @Security("is_granted('IS_AUTHENTICATED_FULLY')")
*/
public function dashboardAction()
{
return $this->render('@DayspringLogin/UserAccount/dashboard.html.twig');
}
/**
* @Route("/users", name="list_users")
* @Security("is_granted('ROLE_Admin')")
*/
public function usersAction()
{
$users = $this->userProvider->getUsers();
return $this->render('@DayspringLogin/UserAccount/list.html.twig', ['users' => $users]);
}
/**
* @Route("/user/edit/{userId}", name="edit_user")
* @Route("/user/new", name="new_user", defaults={"userId" = null})
* @Security("is_granted('ROLE_Admin')")
*/
public function editUserAction(Request $request, $userId)
{
if ($userId) {
$user = $this->userProvider->loadUserById($userId);
} else {
$user = new User();
}
$form = $this->createForm(UserType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$user->save();
$this->addFlash(
'success',
'Your changes were saved!'
);
return $this->redirectToRoute('list_users');
}
return $this->render(
'@DayspringLogin/UserAccount/edit.html.twig',
['form' => $form->createView(), 'title' => $userId ? 'Edit User' : 'Create New User']
);
}
}