Пример #1
0
 public function __invoke(Request $request)
 {
     $invitationToken = $request->query->get('invitation-token');
     try {
         // we need to know if the invitation token given exists in
         // database, in case that it isn't, it throws 404.
         $user = $this->queryHandler->__invoke(new UserOfInvitationTokenQuery($invitationToken));
     } catch (UserDoesNotExistException $exception) {
         throw new NotFoundHttpException();
     } catch (UserTokenExpiredException $exception) {
         throw new NotFoundHttpException();
     } catch (\InvalidArgumentException $exception) {
         throw new NotFoundHttpException();
     }
     $form = $this->formFactory->createNamedBuilder('', SignUpType::class, null, ['roles' => ['ROLE_USER'], 'invitation_token' => $invitationToken])->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->commandBus->handle($form->getData());
         try {
             $this->userCommandBus->handle(new LogInUserCommand($user['email'], $form->getData()->password()));
         } catch (UserDoesNotExistException $exception) {
             throw new NotFoundHttpException();
         } catch (UserInactiveException $exception) {
             throw new NotFoundHttpException();
         } catch (UserPasswordInvalidException $exception) {
             throw new BadCredentialsException();
         }
         $token = $this->jwtEncoder->encode(['email' => $user['email']]);
         return new JsonResponse(['token' => $token]);
     }
     return new JsonResponse(FormErrorSerializer::errors($form), 400);
 }
Пример #2
0
 public function __invoke(Request $request)
 {
     $form = $this->formFactory->createNamedBuilder('', InviteType::class, null, ['roles' => ['ROLE_USER']])->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         try {
             $this->commandBus->handle($form->getData());
             return new JsonResponse(['user_id' => $form->getData()->id(), 'email' => $form->getData()->email(), 'role' => $form->getData()->roles()]);
         } catch (UserAlreadyExistException $exception) {
             return new JsonResponse(sprintf('The %s email is already invited', $form->getData()->email()), 409);
         }
     }
     return new JsonResponse(FormErrorSerializer::errors($form), 400);
 }
Пример #3
0
 public function __invoke(Request $request)
 {
     $form = $this->formFactory->createNamedBuilder('', ResendInvitationType::class)->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         try {
             $this->commandBus->handle($form->getData());
             return new JsonResponse(['email' => $form->getData()->email()]);
         } catch (UserDoesNotExistException $exception) {
             return new JsonResponse(sprintf('The %s email is does not exist', $form->getData()->email()), 404);
         } catch (UserInvitationAlreadyAcceptedException $exception) {
             return new JsonResponse(sprintf('The %s email is already accepted invitation', $form->getData()->email()), 409);
         }
     }
     return new JsonResponse(FormErrorSerializer::errors($form), 400);
 }