Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Symfony2][Symfony] Potwierdzenie email[Solved]
miccom
post 20.03.2021, 12:38:34
Post #1





Grupa: Zarejestrowani
Postów: 493
Pomógł: 8
Dołączył: 7.07.2007
Skąd: Tychy

Ostrzeżenie: (0%)
-----


Cześć.
Przebrnąłem przez rejestrację użytkownika, teraz czas na potwierdzenie adresu.

Wysyłam do usera email z linkiem do potwierdzenia adresu.

User klika na link.

Funkcja odpowiadająca za sprawdzenie czy user o podanym is_activate jest w bazie.

  1. /**
  2.   * @Route("/activate/{isActivate}", name="app_activate")
  3.   */
  4. public function activate( string $isActivate )
  5. {
  6. /*
  7. if($this->getUser())
  8.   {
  9.   return $this->redirectToRoute('index');
  10.   }
  11. */
  12. $em = $this->getDoctrine()->getManager();
  13. $user = $em->getRepository(User::class)
  14. ->findOneBy(
  15. [
  16. 'is_activate' => $isActivate
  17. ]
  18. );
  19. print_r($user->getEmail());
  20.  
  21. }
  22.  


Po kliknięciu w link otrzymuję taki oto komunikat.

  1. The controller must return a "Symfony\Component\HttpFoundation\Response" object but it returned null. Did you forget to add a return statement somewhere in your controller?


Klasa User
  1. class User implements UserInterface
  2. {
  3. /**
  4.   * @ORM\Id()
  5.   * @ORM\GeneratedValue()
  6.   * @ORM\Column(type="integer")
  7.   */
  8. private $id;
  9.  
  10. /**
  11.   * @ORM\Column(type="string", length=180, unique=true)
  12.   */
  13. private $username;
  14.  
  15. /**
  16.   * @ORM\Column(type="json")
  17.   */
  18. private $roles = [];
  19.  
  20. /**
  21.   * @var string The hashed password
  22.   * @ORM\Column(type="string")
  23.   */
  24. private $password;
  25.  
  26. /**
  27.   *
  28.   */
  29. private $plainPassword;
  30.  
  31. /**
  32.   * @ORM\Column(type="string", length=255, unique=true)
  33.   */
  34. private $email;
  35.  
  36. /**
  37.   * @ORM\Column(type="integer")
  38.   */
  39. private $status = 0;
  40.  
  41. /**
  42.   * @ORM\Column(type="string")
  43.   */
  44. private $is_activate;
  45.  
  46.  
  47. /**
  48.   * @ORM\Column(type="boolean")
  49.   */
  50. private $isVerified = false;
  51.  
  52.  
  53. public function getId(): int
  54. {
  55. return (integer) $this->id;
  56. }
  57.  
  58. /**
  59.   * A visual identifier that represents this user.
  60.   *
  61.   * @see UserInterface
  62.   */
  63. public function getUsername(): string
  64. {
  65. return (string) $this->username;
  66. }
  67.  
  68. public function setUsername(string $username): self
  69. {
  70. $this->username = $username;
  71.  
  72. return $this;
  73. }
  74.  
  75.  
  76. public function getStatus(): int
  77. {
  78. return (integer) $this->status;
  79. }
  80.  
  81. public function setStatus(int $status): self
  82. {
  83. $this->status = $status;
  84.  
  85. return $this;
  86. }
  87.  
  88. /**
  89.   * @see UserInterface
  90.   */
  91. public function getRoles(): array
  92. {
  93. $roles = $this->roles;
  94. // guarantee every user at least has ROLE_USER
  95. $roles[] = 'ROLE_USER';
  96.  
  97. return array_unique($roles);
  98. }
  99.  
  100. public function setRoles(array $roles): self
  101. {
  102. $this->roles = $roles;
  103.  
  104. return $this;
  105. }
  106.  
  107. /**
  108.   * @see UserInterface
  109.   */
  110. public function getPassword(): string
  111. {
  112. return (string) $this->password;
  113. }
  114.  
  115. public function setPassword(string $password): self
  116. {
  117. $this->password = $password;
  118.  
  119. return $this;
  120. }
  121.  
  122. /**
  123.   * @see UserInterface
  124.   */
  125. public function getIsActivate(): string
  126. {
  127. return (string) $this->is_activate;
  128. }
  129.  
  130.  
  131. public function setIsActivate(string $is_activate): self
  132. {
  133. $this->is_activate = $is_activate;
  134.  
  135. return $this;
  136. }
  137.  
  138. /**
  139.   * @see UserInterface
  140.   */
  141. public function getSalt()
  142. {
  143. // not needed when using the "bcrypt" algorithm in security.yaml
  144. }
  145.  
  146. /**
  147.   * @see UserInterface
  148.   */
  149. public function eraseCredentials()
  150. {
  151. // If you store any temporary, sensitive data on the user, clear it here
  152. // $this->plainPassword = null;
  153. }
  154.  
  155. public function getEmail(): ?string
  156. {
  157. return $this->email;
  158. }
  159.  
  160. public function setEmail(string $email): self
  161. {
  162. $this->email = $email;
  163.  
  164. return $this;
  165. }
  166.  
  167. public function isVerified(): bool
  168. {
  169. return $this->isVerified;
  170. }
  171.  
  172. public function setIsVerified(bool $isVerified): self
  173. {
  174. $this->isVerified = $isVerified;
  175.  
  176. return $this;
  177. }
  178.  
  179. public function getPlainPassword()
  180. {
  181. return $this->plainPassword;
  182. }
  183.  
  184. public function setPlainPassword($password)
  185. {
  186. $this->plainPassword = $password;
  187. }
  188. }


Jak sprawdzić, czy dany user istnieje?

EDIT:

System działa, na samej górze system pokazuje mi email usera, ale oczekiwał zwrotu albo toRoute albo załadowania szablonu twiga.

Można zamknąć temat.

Ten post edytował miccom 20.03.2021, 12:55:59


--------------------
Jeśli pomogłem- kliknij POMÓGŁ-przyda się ;)- jeśli piszę bzdury- pisz pod postami. Poprawię się.
PISZĘ POPRAWNIE PO POLSKU!
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 26.04.2024 - 05:53