-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from Pietrucci-Blacher/feat/separate-levels-b…
…y-role Feat/separate levels by role
- Loading branch information
Showing
30 changed files
with
427 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
| Feature Name | Author | Link PR | | ||
|-------------------------------------------------------------------------------|--------------|---------| | ||
| Separer le front par role & rajouter la securité & rajouter layout par niveau | Ossama DAHBI | https://github.com/Pietrucci-Blacher/Challenge-Semestriel-1-5IW/pull/152 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,19 +18,17 @@ public function __construct(private readonly ProcessorInterface $processor, priv | |
*/ | ||
public function process($data, Operation $operation, array $uriVariables = [], array $context = []) | ||
{ | ||
if (!$data->getPassword()) { | ||
if (!$data->getPlainPassword()) { | ||
return $this->processor->process($data, $operation, $uriVariables, $context); | ||
} | ||
|
||
$hashedPassword = $this->passwordHasher->hashPassword( | ||
$data, | ||
$data->getPassword() | ||
$data->getPlainPassword() | ||
); | ||
$data->setPassword($hashedPassword); | ||
$data->eraseCredentials(); | ||
|
||
|
||
// $email = new Email(); | ||
// $email->sendEmail("[email protected]", $data->getEmail(), 'Welcome to Resend', 'Welcome to Resend'); | ||
return $this->processor->process($data, $operation, $uriVariables, $context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = {} | ||
const nextConfig = { | ||
async rewrites() { | ||
return { | ||
fallback: [{source: '/:path*', destination: '/user/:path*'}] | ||
} | ||
}, | ||
} | ||
|
||
module.exports = nextConfig |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import {useAuthContext} from "@/providers/AuthProvider"; | ||
import {useRouter} from "next/router"; | ||
import AdminLayout from "@/layouts/AdminLayout"; | ||
import UserLayout from "@/layouts/UserLayout"; | ||
import ProviderLayout from "@/layouts/ProviderLayout"; | ||
import DefaultLayout from "@/layouts/DefaultLayout"; | ||
import Header from "@/components/Header"; | ||
import {Flowbite} from "flowbite-react"; | ||
import {useEffect} from "react"; | ||
|
||
const canAccessTo = (path, roles) => { | ||
const lowerCaseRoles = roles.join(',').toLowerCase() ?? "" | ||
if (path.startsWith('/admin')) { | ||
return lowerCaseRoles.includes('admin'); | ||
} | ||
else if (path.startsWith('/provider')) { | ||
return lowerCaseRoles.includes('provider') || lowerCaseRoles.includes('admin'); | ||
} | ||
else if (path.startsWith('/user')) { | ||
return lowerCaseRoles.includes('user') || lowerCaseRoles.includes('admin') || lowerCaseRoles.includes('provider'); | ||
} | ||
return true | ||
}; | ||
|
||
const ChooseLayout = ({children}) => { | ||
const {user, isLogged} = useAuthContext() | ||
const router = useRouter() | ||
const path = router.pathname | ||
const needsAuth = path.startsWith('/admin') || path.startsWith('/provider') || path.startsWith('/user'); | ||
useEffect(() => { | ||
if (user !== undefined && needsAuth && !isLogged) { | ||
router.push('/auth/login'); | ||
} | ||
if (user !== undefined && needsAuth && !canAccessTo(path, user?.roles)) { | ||
router.push('/auth/login'); | ||
} | ||
}, [user, path]); | ||
|
||
let Layout; | ||
|
||
if (path.startsWith('/admin')) { | ||
Layout = AdminLayout | ||
} else if (path.startsWith('/provider')) { | ||
Layout = ProviderLayout | ||
} else if (path.startsWith('/user')) { | ||
Layout = UserLayout | ||
} else { | ||
Layout = DefaultLayout | ||
} | ||
if (!needsAuth) { | ||
return ( | ||
<> | ||
<Flowbite> | ||
<div className="grid grid-rows-[auto,1fr] h-screen dark:bg-gray-900"> | ||
<div> | ||
<Header/> | ||
</div> | ||
<div className="flex flex-row"> | ||
|
||
<Layout> | ||
{children} | ||
</Layout> | ||
</div> | ||
</div> | ||
</Flowbite> | ||
</> | ||
); | ||
} | ||
return ( | ||
<> | ||
{isLogged && <Flowbite> | ||
<div className="grid grid-rows-[auto,1fr] h-screen dark:bg-gray-900"> | ||
<div> | ||
<Header/> | ||
</div> | ||
<div className="flex flex-row"> | ||
|
||
<Layout> | ||
{children} | ||
</Layout> | ||
</div> | ||
</div> | ||
</Flowbite>} | ||
</> | ||
) | ||
} | ||
export default ChooseLayout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import {Avatar, DarkThemeToggle, Dropdown, Navbar} from "flowbite-react"; | ||
import Image from "next/image"; | ||
import {useAuthContext} from "@/providers/AuthProvider"; | ||
|
||
export default function Header() { | ||
const {user} = useAuthContext(); | ||
return ( | ||
<header className="sticky top-0 z-20"> | ||
<Navbar fluid rounded> | ||
<Navbar.Brand href="/"> | ||
<Image | ||
alt="Flowbite logo" | ||
height="32" | ||
src="https://flowbite.com/docs/images/logo.svg" | ||
width="32" | ||
/> | ||
<span | ||
className="self-center whitespace-nowrap pl-3 text-xl font-semibold dark:text-white">Flowbite</span> | ||
</Navbar.Brand> | ||
|
||
<div className="flex md:order-2"> | ||
<DarkThemeToggle className="mx-4"/> | ||
{ user && <Dropdown | ||
inline | ||
label={ | ||
<Avatar | ||
alt="User settings" | ||
img="https://flowbite.com/docs/images/people/profile-picture-5.jpg" | ||
rounded | ||
/> | ||
} | ||
> | ||
<Dropdown.Header> | ||
<span className="block text-sm">{user.lastname} {user.firstname}</span> | ||
<span className="block truncate text-sm font-medium">{user.email}</span> | ||
</Dropdown.Header> | ||
<Dropdown.Item>Dashboard</Dropdown.Item> | ||
<Dropdown.Item>Settings</Dropdown.Item> | ||
<Dropdown.Item>Earnings</Dropdown.Item> | ||
<Dropdown.Divider/> | ||
<Dropdown.Item href="/auth/logout">Sign out</Dropdown.Item> | ||
</Dropdown> } | ||
<Navbar.Toggle/> | ||
</div> | ||
|
||
<Navbar.Collapse> | ||
<Navbar.Link href="#" active> | ||
Home | ||
</Navbar.Link> | ||
<Navbar.Link href="#">About</Navbar.Link> | ||
<Navbar.Link href="#">Services</Navbar.Link> | ||
<Navbar.Link href="#">Pricing</Navbar.Link> | ||
<Navbar.Link href="#">Contact</Navbar.Link> | ||
</Navbar.Collapse> | ||
</Navbar> | ||
</header> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {useState} from "react"; | ||
import {HiChartPie, HiViewBoards} from "react-icons/hi"; | ||
import {Sidebar as FlowbiteSidebar} from "flowbite-react"; | ||
import {BiBuoy} from "react-icons/bi"; | ||
|
||
const Sidebar = function ({content = []}) { | ||
const [isOpen, setOpen] = useState(false); | ||
|
||
const toggle = () => { | ||
setOpen(!isOpen); | ||
} | ||
|
||
return ( | ||
<FlowbiteSidebar> | ||
<FlowbiteSidebar.Items className="flex flex-col h-full justify-between"> | ||
<FlowbiteSidebar.ItemGroup> | ||
{content.map((element, index)=>( | ||
<FlowbiteSidebar.Item key={index} {...element}> | ||
{element.text} | ||
</FlowbiteSidebar.Item> | ||
))} | ||
</FlowbiteSidebar.ItemGroup> | ||
<FlowbiteSidebar.ItemGroup className="py-4"> | ||
<FlowbiteSidebar.Item href="#" icon={HiChartPie}> | ||
Upgrade to Pro | ||
</FlowbiteSidebar.Item> | ||
<FlowbiteSidebar.Item href="#" icon={HiViewBoards}> | ||
Documentation | ||
</FlowbiteSidebar.Item> | ||
<FlowbiteSidebar.Item href="#" icon={BiBuoy}> | ||
Help | ||
</FlowbiteSidebar.Item> | ||
</FlowbiteSidebar.ItemGroup> | ||
</FlowbiteSidebar.Items> | ||
</FlowbiteSidebar> | ||
); | ||
}; | ||
|
||
export default Sidebar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Sidebar from "@/components/Sidebar"; | ||
import {HiChartPie, HiInbox, HiShoppingBag, HiTable, HiUser, HiViewBoards} from "react-icons/hi"; | ||
|
||
const AdminLayout = ({children}) => { | ||
|
||
const sidebarContent = [ | ||
{icon: HiChartPie, text: "Dashboard", href: "/admin", label: "Pro", labelColor: "gray"}, | ||
{icon: HiViewBoards, text: "Requests", href: "/admin/requests", label: "Pro", labelColor: "gray"}, | ||
{icon: HiInbox, text: "Establishment", href: "#", label: "Pro", labelColor: "gray"}, | ||
{icon: HiShoppingBag, text: "Services", href: "#", label: "Pro", labelColor: "gray"}, | ||
{icon: HiUser, text: "Users", href: "#", label: "Pro", labelColor: "gray"}, | ||
{icon: HiTable, text: "Reviews", href: "#", label: "Pro", labelColor: "gray"} | ||
] | ||
return ( | ||
<> | ||
|
||
<Sidebar content={sidebarContent}/> | ||
<main className="p-6"> | ||
{children} | ||
</main> | ||
</> | ||
) | ||
} | ||
export default AdminLayout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const DefaultLayout = ({children}) => { | ||
return ( | ||
<> | ||
<main className="p-6"> | ||
{children} | ||
</main> | ||
</> | ||
) | ||
} | ||
|
||
export default DefaultLayout |
Oops, something went wrong.