Skip to content

Commit

Permalink
Feature/user login (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-kwiatkowski authored Jun 15, 2023
2 parents 3a278d2 + 4abebe2 commit d5a4137
Show file tree
Hide file tree
Showing 15 changed files with 551 additions and 100 deletions.
9 changes: 8 additions & 1 deletion backend/SoftwareEngineering2/FlowerShopContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) {
// TODO: temporary solution (password: password)
modelBuilder.Entity<EmployeeModel>().HasData(new EmployeeModel {
Email = "[email protected]",
Name = "W³adys³aw Howalski",
Name = "Wadysaw Howalski",
Password = "AQAAAAIAAYagAAAAEHiYiXUCLpBDCy3l60OqSPW+GNZExxF4PwXI8VtkhKZqjVsMFdhw68orF475JKPXkA==",
EmployeeID = 1
});

modelBuilder.Entity<ClientModel>().HasData(new ClientModel {
Email = "[email protected]",
Name = "John Doe",
Password = "AQAAAAIAAYagAAAAEHiYiXUCLpBDCy3l60OqSPW+GNZExxF4PwXI8VtkhKZqjVsMFdhw68orF475JKPXkA==",
ClientID = 1
});
}
}
152 changes: 152 additions & 0 deletions frontend/client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@headlessui/react": "^1.7.14",
"@heroicons/react": "^2.0.17",
"@mui/material": "^5.13.1",
"axios": "^1.4.0",
"dotenv": "^16.0.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
61 changes: 61 additions & 0 deletions frontend/client/src/components/UserPopover.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React, {Fragment} from 'react';
import {Popover, Transition} from '@headlessui/react'
import {UserIcon} from "@heroicons/react/24/outline";
import {useAuth} from "../context/AuthContext";
import {Link} from "react-router-dom";

export default function UserPopover() {
const {user} = useAuth()

return (
<Popover className="relative h-6">
{({open}) => (<>
<Popover.Button
className={`
${open ? '' : 'text-opacity-90'}
group inline-flex items-center rounded-md text-base font-medium hover:text-opacity-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75`}
>
<UserIcon
className={`${open ? '' : 'text-opacity-70'}
h-6 w-6 transition duration-150 ease-in-out group-hover:text-opacity-80`}
aria-hidden="true"
/>
</Popover.Button>

<Popover.Overlay className="fixed inset-0 bg-black opacity-30"/>
<Transition
as={Fragment}
enter="transition ease-out duration-200"
enterFrom="opacity-0 translate-y-1"
enterTo="opacity-100 translate-y-0"
leave="transition ease-in duration-150"
leaveFrom="opacity-100 translate-y-0"
leaveTo="opacity-0 translate-y-1"
>
<Popover.Panel
className="absolute -right-40 z-10 mt-3 w-screen max-w-sm -translate-x-1/2 transform px-4 sm:px-0 lg:max-w-xs">
<div className="overflow-hidden rounded-lg shadow-lg ring-1 ring-black ring-opacity-5 bg-white p-4">
{user ? (<div className="flex flex-col">
<span>Welcome, {user.name}</span>
<Link to="/logout">
<span
className="block mt-4 px-4 py-1 text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900 rounded-md text-center text-sm">
Logout
</span>
</Link>
</div>) : (<>
<Link to="/login">
<span
className="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900 rounded-md text-center">
Login
</span>
</Link>
</>)
}
</div>
</Popover.Panel>
</Transition>
</>)}
</Popover>
);
}
Loading

0 comments on commit d5a4137

Please sign in to comment.