Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
Wishlist-application
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ZAHDI Mohcine
Wishlist-application
Commits
dd31259d
Commit
dd31259d
authored
2 months ago
by
user
Browse files
Options
Downloads
Plain Diff
Merge branch 'main' of
https://github.com/MohcineProject/Wishlist-application
parents
00b332b8
8a07b911
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
config/packages/security.yaml
+10
-0
10 additions, 0 deletions
config/packages/security.yaml
src/Controller/WishlistController.php
+27
-40
27 additions, 40 deletions
src/Controller/WishlistController.php
with
37 additions
and
40 deletions
config/packages/security.yaml
+
10
−
0
View file @
dd31259d
...
@@ -25,7 +25,17 @@ security:
...
@@ -25,7 +25,17 @@ security:
secret
:
'
%kernel.secret%'
secret
:
'
%kernel.secret%'
access_control
:
access_control
:
# Allow access to /login without being authenticated
-
{
path
:
^/login
,
allow_if
:
"
1"
}
# Allow users who are admins to access the /admin path
-
{
path
:
^/admin
,
allow_if
:
"
user
and
user.isAdmin()
==
true"
}
-
{
path
:
^/admin
,
allow_if
:
"
user
and
user.isAdmin()
==
true"
}
# Allow users who are not locked to access other pages
-
{
path
:
^/.*
,
allow_if
:
"
user
and
user.isLocked()
!=
true"
}
# Allow all authenticated users to access other routes (outside /admin or /login)
-
{
path
:
^/
,
allow_if
:
"
user"
}
when@test
:
when@test
:
security
:
security
:
...
...
This diff is collapsed.
Click to expand it.
src/Controller/WishlistController.php
+
27
−
40
View file @
dd31259d
...
@@ -14,56 +14,54 @@ use Symfony\Component\Routing\Attribute\Route;
...
@@ -14,56 +14,54 @@ use Symfony\Component\Routing\Attribute\Route;
#[Route('/wishlist')]
#[Route('/wishlist')]
final
class
WishlistController
extends
AbstractController
final
class
WishlistController
extends
AbstractController
{
{
// Method to display all wishlists for the currently logged-in user
#[Route(name: 'app_wishlist_index', methods: ['GET'])]
#[Route(name: 'app_wishlist_index', methods: ['GET'])]
public
function
getWishLists
(
WishlistRepository
$wishlistRepository
):
Response
public
function
getWishLists
(
WishlistRepository
$wishlistRepository
):
Response
{
{
$user
=
$this
->
getUser
()
;
$user
=
$this
->
getUser
();
// Get the currently authenticated user
return
$this
->
render
(
'wishlist/index.html.twig'
,
[
return
$this
->
render
(
'wishlist/index.html.twig'
,
[
'wishlists'
=>
$user
->
getWishlists
()
'wishlists'
=>
$user
->
getWishlists
()
->
toArray
()
// Pass the user's wishlists to the template
]);
]);
}
}
// Method to create a new wishlist
#[Route('/new', name: 'app_wishlist_new', methods: ['GET', 'POST'])]
#[Route('/new', name: 'app_wishlist_new', methods: ['GET', 'POST'])]
public
function
createWishlist
(
Request
$request
,
EntityManagerInterface
$entityManager
):
Response
public
function
createWishlist
(
Request
$request
,
EntityManagerInterface
$entityManager
):
Response
{
{
$wishlist
=
new
Wishlist
();
$wishlist
=
new
Wishlist
();
// Create a new Wishlist entity
$form
=
$this
->
createForm
(
WishlistType
::
class
,
$wishlist
);
$form
=
$this
->
createForm
(
WishlistType
::
class
,
$wishlist
);
// Create a form for the Wishlist entity
$form
->
handleRequest
(
$request
);
$form
->
handleRequest
(
$request
);
// Handle the form submission
if
(
$form
->
isSubmitted
()
&&
$form
->
isValid
())
{
if
(
$form
->
isSubmitted
()
&&
$form
->
isValid
())
{
$entityManager
->
persist
(
$wishlist
);
$entityManager
->
persist
(
$wishlist
);
// Persist the new wishlist to the database
$entityManager
->
flush
();
$entityManager
->
flush
();
// Save changes to the database
return
$this
->
redirectToRoute
(
'app_wishlist_index'
,
[],
Response
::
HTTP_SEE_OTHER
);
return
$this
->
redirectToRoute
(
'app_wishlist_index'
,
[],
Response
::
HTTP_SEE_OTHER
);
// Redirect to the wishlist index page
}
}
return
$this
->
render
(
'wishlist/new.html.twig'
,
[
return
$this
->
render
(
'wishlist/new.html.twig'
,
[
'wishlists'
=>
$wishlist
,
'wishlist'
=>
$wishlist
,
// Pass the wishlist entity to the template
'form'
=>
$form
,
'form'
=>
$form
,
// Pass the form to the template
]);
]);
}
}
// Method to display a specific wishlist
#[Route('/{id}', name: 'app_wishlist_show', methods: ['GET'])]
#[Route('/{id}', name: 'app_wishlist_show', methods: ['GET'])]
public
function
show
(
Wishlist
$wishlist
):
Response
public
function
show
(
Wishlist
$wishlist
):
Response
{
{
return
$this
->
render
(
'wishlist/show.html.twig'
,
[
return
$this
->
render
(
'wishlist/show.html.twig'
,
[
'wishlist'
=>
$wishlist
,
'wishlist'
=>
$wishlist
,
// Pass the wishlist entity to the template
]);
]);
}
}
// Method to edit an existing wishlist
#[Route('/{id}/edit', name: 'app_wishlist_edit', methods: ['GET', 'POST'])]
#[Route('/{id}/edit', name: 'app_wishlist_edit', methods: ['GET', 'POST'])]
public
function
edit
(
Request
$request
,
Wishlist
$wishlist
,
EntityManagerInterface
$entityManager
):
Response
public
function
edit
(
Request
$request
,
Wishlist
$wishlist
,
EntityManagerInterface
$entityManager
):
Response
{
{
$wishlist
->
setName
(
$request
->
get
(
'name'
));
$wishlist
->
setDeadline
(
$request
->
get
(
'deadline'
))
;
$entityManager
->
persist
(
$wishlist
);
$form
=
$this
->
createForm
(
WishlistType
::
class
,
$wishlist
);
$entityManager
->
flush
();
return
new
Response
(
'wishlist was modified successfully '
,
Response
::
HTTP_ACCEPTED
)
;
/* $form = $this->createForm(WishlistType::class, $wishlist);
$form
->
handleRequest
(
$request
);
$form
->
handleRequest
(
$request
);
if
(
$form
->
isSubmitted
()
&&
$form
->
isValid
())
{
if
(
$form
->
isSubmitted
()
&&
$form
->
isValid
())
{
...
@@ -75,31 +73,20 @@ final class WishlistController extends AbstractController
...
@@ -75,31 +73,20 @@ final class WishlistController extends AbstractController
return
$this
->
render
(
'wishlist/edit.html.twig'
,
[
return
$this
->
render
(
'wishlist/edit.html.twig'
,
[
'wishlist'
=>
$wishlist
,
'wishlist'
=>
$wishlist
,
'form'
=>
$form
,
'form'
=>
$form
,
]); */
]);
}
}
// Method to delete a wishlist
#[Route('/{id}', name: 'app_wishlist_delete', methods: ['POST'])]
#[Route('/{id}', name: 'app_wishlist_delete', methods: ['POST'])]
public
function
delete
(
Request
$request
,
Wishlist
$wishlist
,
EntityManagerInterface
$entityManager
):
Response
public
function
delete
(
Request
$request
,
Wishlist
$wishlist
,
EntityManagerInterface
$entityManager
):
Response
{
{
// Validate the CSRF token before deleting the wishlist
if
(
$this
->
isCsrfTokenValid
(
'delete'
.
$wishlist
->
getId
(),
$request
->
getPayload
()
->
getString
(
'_token'
)))
{
if
(
$this
->
isCsrfTokenValid
(
'delete'
.
$wishlist
->
getId
(),
$request
->
getPayload
()
->
getString
(
'_token'
)))
{
$entityManager
->
remove
(
$wishlist
);
$entityManager
->
remove
(
$wishlist
);
// Remove the wishlist from the database
$entityManager
->
flush
();
$entityManager
->
flush
();
// Save changes to the database
}
}
return
$this
->
redirectToRoute
(
'app_wishlist_index'
,
[],
Response
::
HTTP_SEE_OTHER
);
return
$this
->
redirectToRoute
(
'app_wishlist_index'
,
[],
Response
::
HTTP_SEE_OTHER
);
// Redirect to the wishlist index page
}
}
}
\ No newline at end of file
}
/*
$wishlist = new Wishlist();
$name = $request->get(key: 'name');
$wishlist->setName(name: $name);
$deadline = $request->get('deadline') ;
$wishlist->setDeadline($deadline);
$this->getUser()->addToAuthorWhishlists($wishlist);
$entityManager->persist($wishlist);
$entityManager->persist($this->getUser()) ;
$entityManager->flush(); */
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment