Guest User

Untitled

a guest
Jan 19th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. login:
  2. pattern: ^/api/login
  3. stateless: true
  4. anonymous: true
  5. form_login:
  6. check_path: /api/login_check
  7. require_previous_session: false
  8. success_handler: lexik_jwt_authentication.handler.authentication_success
  9. failure_handler: lexik_jwt_authentication.handler.authentication_failure
  10.  
  11. register:
  12. pattern: ^/api/registrations
  13. stateless: true
  14. anonymous: true
  15.  
  16. public function postRegistrationAction(Request $request)
  17. {
  18. $em = $this->get('doctrine')->getManager();
  19. $encoder = $this->container->get('security.password_encoder');
  20. $logger = $this->container->get('logger');
  21.  
  22. try {
  23. $auth = $this->get('app.auth');
  24.  
  25. /** @var User $user */
  26. $user = $auth->validateEntites('request', User::class, ['registration']);
  27. $password = $request->request->get('_password');
  28.  
  29. $user
  30. ->setPassword($encoder->encodePassword($user, $password));
  31.  
  32. $em->persist($user);
  33. $em->flush();
  34.  
  35. return $this->createSuccessResponse($user, ['profile'], true);
  36. } catch (ValidatorException $e) {
  37. $view = $this->view(['message' => $e->getErrorsMessage()], self::HTTP_STATUS_CODE_BAD_REQUEST);
  38. $logger->error($this->getMessagePrefix().'validate error: '.$e->getErrorsMessage());
  39. } catch (Exception $e) {
  40. $view = $this->view((array) $e->getMessage(), self::HTTP_STATUS_CODE_BAD_REQUEST);
  41. $logger->error($this->getMessagePrefix().'error: '.$e->getMessage());
  42. }
  43.  
  44. return $this->handleView($view);
  45. }
Add Comment
Please, Sign In to add comment