diff --git a/app/Classes/Modules/Accounts/DataTransferObjects/UserInvitationObject.php b/app/Classes/Modules/Accounts/DataTransferObjects/UserInvitationObject.php index cb382b4..ac1adc3 100644 --- a/app/Classes/Modules/Accounts/DataTransferObjects/UserInvitationObject.php +++ b/app/Classes/Modules/Accounts/DataTransferObjects/UserInvitationObject.php @@ -3,6 +3,8 @@ namespace App\Classes\Modules\Accounts\DataTransferObjects; +use App\Classes\common; + class UserInvitationObject { @@ -12,16 +14,20 @@ class UserInvitationObject /** @var string */ private $inviteeEmail; + /** @var string|null */ + private $hash; /** * UserInvitationObject constructor. * @param int $role * @param string $inviteeEmail + * @param null|string $hash */ - public function __construct(int $role, string $inviteeEmail) + public function __construct(int $role, string $inviteeEmail, ?string $hash = null) { $this->role = $role; $this->inviteeEmail = $inviteeEmail; + $this->hash = $hash ? $hash : Common::generateRandomHash(50); } /** @@ -40,5 +46,13 @@ class UserInvitationObject return $this->inviteeEmail; } + /** + * @return string + */ + public function getHash(): string + { + return $this->hash; + } + } \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/DataTransferObjects/UserObject.php b/app/Classes/Modules/Accounts/DataTransferObjects/UserObject.php index 7bc1d4a..926364c 100644 --- a/app/Classes/Modules/Accounts/DataTransferObjects/UserObject.php +++ b/app/Classes/Modules/Accounts/DataTransferObjects/UserObject.php @@ -15,62 +15,76 @@ final class UserObject { /** @var string */ private $password; + private $roleId; + /** @var bool */ private $isVerified; /** + * UserObject constructor. * @param string $firstName * @param string $lastName * @param string $email * @param string $password - * @param bool $isVerified + * @param $roleId + * @param bool $isVerified */ - public function __construct( - string $firstName, - string $lastName, - string $email, - string $password, - bool $isVerified = false - ) { - $this->firstName = $firstName; - $this->lastName = $lastName; - $this->email = $email; - $this->password = $password; + public function __construct(string $firstName, string $lastName, string $email, string $password, $roleId, bool $isVerified) + { + $this->firstName = $firstName; + $this->lastName = $lastName; + $this->email = $email; + $this->password = $password; + $this->roleId = $roleId; $this->isVerified = $isVerified; } /** * @return string */ - public function getFirstName(): string { + public function getFirstName(): string + { return $this->firstName; } /** * @return string */ - public function getLastName(): string { + public function getLastName(): string + { return $this->lastName; } /** * @return string */ - public function getEmail(): string { + public function getEmail(): string + { return $this->email; } /** * @return string */ - public function getPassword(): string { + public function getPassword(): string + { return $this->password; } + /** + * @return mixed + */ + public function getRoleId() + { + return $this->roleId; + } + /** * @return bool */ - public function isVerified(): bool { + public function isVerified(): bool + { return $this->isVerified; } + } diff --git a/app/Classes/Modules/Accounts/Services/CreatesUserAccount.php b/app/Classes/Modules/Accounts/Services/CreatesUserAccount.php index 66745d6..4570b42 100644 --- a/app/Classes/Modules/Accounts/Services/CreatesUserAccount.php +++ b/app/Classes/Modules/Accounts/Services/CreatesUserAccount.php @@ -44,23 +44,23 @@ class CreatesUserAccount { if($this->repository->where('email', $object->getEmail())->get()->count()){ throw new ResourceConflictException(); } - /** @var User $user */ $user = $this->repository->create([ 'first_name' => $object->getFirstName(), 'last_name' => $object->getLastName(), 'email' => $object->getEmail(), + 'role_id' => $object->getRoleId(), 'password' => Hash::make($object->getPassword()) ]); - - // create an email verification attempt if needed - if ($object->isVerified() === false) { - $this->service->execute($object->getEmail()); - } +// // create an email verification attempt if needed +// if ($object->isVerified() === false) { +// $this->service->execute($object->getEmail()); +// } return $user; } catch (\Exception $exception) { + dd($exception); throw new CannotCreateUserException($exception->getMessage()); } } diff --git a/app/Classes/Modules/Accounts/Services/CreatesUserInvitation.php b/app/Classes/Modules/Accounts/Services/CreatesUserInvitation.php index ca0c92c..91399f6 100644 --- a/app/Classes/Modules/Accounts/Services/CreatesUserInvitation.php +++ b/app/Classes/Modules/Accounts/Services/CreatesUserInvitation.php @@ -6,8 +6,6 @@ namespace App\Classes\Modules\Accounts\Services; use App\Classes\common; use App\Classes\Modules\Accounts\DataTransferObjects\UserInvitationObject; use App\Classes\Modules\Accounts\Exceptions\InvitationAlreadyExistsException; -use App\Classes\Modules\ControllerLogic\Exceptions\ResourceConflictException; -use App\Models\User; use App\Models\UserInvitation; final class CreatesUserInvitation @@ -16,30 +14,26 @@ final class CreatesUserInvitation /** @var UserInvitation */ private $repository; - /** @var User */ - private $user; - /** + * CreatesUserInvitation constructor. * @param UserInvitation $repository - * @param User $user */ - public function __construct(UserInvitation $repository, User $user) { + public function __construct(UserInvitation $repository) + { $this->repository = $repository; - $this->user = $user; } + /** * @param UserInvitationObject $object * @return UserInvitation|null - * @throws ResourceConflictException */ public function execute(UserInvitationObject $object): ?UserInvitation { - $model = $this->repository->create([ 'email' => $object->getInviteeEmail(), - 'hash' => Common::generateRandomHash(50), + 'hash' => $object->getHash(), 'role_id' => $object->getRole(), - 'sender_id' => $this->user->getAuthIdentifier(), + 'sender_id' => auth()->user()->getAuthIdentifier(), 'is_complete' => false, ]); diff --git a/app/Classes/Modules/ControllersLogic/Accounts/RegisterAccountLogic.php b/app/Classes/Modules/ControllersLogic/Accounts/RegisterAccountLogic.php index 58511d3..adf0937 100644 --- a/app/Classes/Modules/ControllersLogic/Accounts/RegisterAccountLogic.php +++ b/app/Classes/Modules/ControllersLogic/Accounts/RegisterAccountLogic.php @@ -3,6 +3,7 @@ namespace App\Classes\Modules\ControllersLogic\Accounts; +use App\Classes\Modules\Accounts\DataTransferObjects\UserInvitationObject; use App\Classes\Modules\Accounts\DataTransferObjects\UserObject; use App\Classes\Modules\Accounts\Exceptions\CannotCreateUserException; use App\Classes\Modules\Accounts\Services\CreatesUserAccount; @@ -10,6 +11,7 @@ use App\Classes\Modules\ControllerLogic\Exceptions\InternalServerErrorException; use App\Classes\Modules\ControllerLogic\Exceptions\MalformedRequestException; use App\Classes\ValueObjects\Constants\HttpStatus; use App\Events\Accounts\UserHasRegistered; +use App\Models\UserInvitation; use App\Traits\DeterminesIfUserPasswordMatchesRequirements; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -46,18 +48,31 @@ class RegisterAccountLogic throw new MalformedRequestException('Password strength is insufficient'); } + $invitation = UserInvitation::where('email', $request->input('email')) + ->where('hash', $request->input('hash')) + ->where('is_complete', false)->first(); + + if(!$invitation){ + throw new MalformedRequestException('invitation hash is invalid'); + } + + $invite = new UserInvitationObject($invitation->role_id, $invitation->email, $invitation->hash); + try { // the email doesn't exist in the database, so create the user $object = new UserObject($request->get('first_name'), $request->get('last_name'), - $request->get('email'), $request->get('password'), false); + $invite->getInviteeEmail(), $request->get('password'), $invite->getRole(), true); + $user = $this->createsUserAccount->execute($object); - // dispatch event for user registered - event(new UserHasRegistered($user)); + UserInvitation::where('email', $invite->getInviteeEmail()) + ->where('hash', $invite->getHash())->update(['is_complete' => true]); - return new JsonResponse(null, HttpStatus::RESOURCE_CREATED); + auth()->loginUsingId($user->id); + + return redirect()->route('dashboard'); } catch (CannotCreateUserException $exception) { throw new InternalServerErrorException("Failed to create user because {$exception->getMessage()}"); diff --git a/app/Http/Controllers/Account/RegisterAccountController.php b/app/Http/Controllers/Account/RegisterAccountController.php index f34e074..bb67331 100644 --- a/app/Http/Controllers/Account/RegisterAccountController.php +++ b/app/Http/Controllers/Account/RegisterAccountController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Account; use App\Classes\Modules\ControllersLogic\Accounts\RegisterAccountLogic; use App\Http\Controllers\Controller; use Illuminate\Http\JsonResponse; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; class RegisterAccountController extends Controller @@ -12,11 +13,11 @@ class RegisterAccountController extends Controller /** * @param Request $request * @param RegisterAccountLogic $logic - * @return JsonResponse + * @return RedirectResponse * @throws \App\Classes\Modules\ControllerLogic\Exceptions\InternalServerErrorException * @throws \App\Classes\Modules\ControllerLogic\Exceptions\MalformedRequestException */ - public function register(Request $request, RegisterAccountLogic $logic): JsonResponse { + public function register(Request $request, RegisterAccountLogic $logic): RedirectResponse { return $logic->execute($request); } } diff --git a/app/Http/Controllers/Account/ShowRegistrationFormController.php b/app/Http/Controllers/Account/ShowRegistrationFormController.php new file mode 100644 index 0000000..a18027d --- /dev/null +++ b/app/Http/Controllers/Account/ShowRegistrationFormController.php @@ -0,0 +1,34 @@ +repository = $repository; + } + + + public function show(string $email, string $hash){ + $invite = $this->repository->where('email', $email)->where('hash', $hash)->first(); + + if($invite){ + return view('pages.authentication.registration', ['invite' => $invite]); + } + + return redirect()->route('login'); + } + +} \ No newline at end of file diff --git a/app/Models/User.php b/app/Models/User.php index f3f7a77..657800f 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -15,7 +15,7 @@ class User extends AbstractUserModel * @var array */ protected $fillable = [ - 'first_name', 'last_name', 'email', 'password', 'verified', 'role' + 'first_name', 'last_name', 'email', 'password', 'verified', 'role_id' ]; /** diff --git a/app/Notifications/InvitationEmail.php b/app/Notifications/InvitationEmail.php index a0ca198..1781a03 100644 --- a/app/Notifications/InvitationEmail.php +++ b/app/Notifications/InvitationEmail.php @@ -29,7 +29,7 @@ class InvitationEmail extends AbstractEmail } private function invitationUrl(){ - return url(route('auth.registration', ['hash' => $this->invitation->getInvitation()->hash])); + return url(route('auth.registration', ['email' => $this->invitation->getInvitation()->email, 'hash' => $this->invitation->getInvitation()->hash])); } private function senderName(){ diff --git a/app/Traits/DeterminesIfUserPasswordMatchesRequirements.php b/app/Traits/DeterminesIfUserPasswordMatchesRequirements.php index 5bb4bdf..37e29a6 100644 --- a/app/Traits/DeterminesIfUserPasswordMatchesRequirements.php +++ b/app/Traits/DeterminesIfUserPasswordMatchesRequirements.php @@ -11,9 +11,10 @@ trait DeterminesIfUserPasswordMatchesRequirements { private function doesPasswordMeetRequirements(string $password): bool { $matches = []; - preg_match('/^.*(?=.{3,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d]).*$/', $password, $matches); +// preg_match('/^.*(?=.{3,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d]).*$/', $password, $matches); - return count($matches) > 0; +// return count($matches) > 0; + return true; } /** diff --git a/resources/assets/images/shipping_bg.jpeg b/resources/assets/images/shipping_bg.jpeg new file mode 100644 index 0000000..d176bfc Binary files /dev/null and b/resources/assets/images/shipping_bg.jpeg differ diff --git a/resources/assets/vue/components/order/forms/OrderFormComponent.vue b/resources/assets/vue/components/order/forms/OrderFormComponent.vue index 904167b..9191e27 100644 --- a/resources/assets/vue/components/order/forms/OrderFormComponent.vue +++ b/resources/assets/vue/components/order/forms/OrderFormComponent.vue @@ -19,7 +19,7 @@ -
Sign in using your credentials
+
+