|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
7
|
|
|
use AppBundle\Entity\User; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
9
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
10
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class RegitrationController |
|
15
|
|
|
* @package AppBundle\Controller |
|
16
|
|
|
*/ |
|
17
|
|
|
class RegistrationController extends Controller |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @Route("/registration", name="user_registration") |
|
21
|
|
|
* @Template("@App/registration/registration.html.twig") |
|
22
|
|
|
*/ |
|
23
|
1 |
|
public function registerAction(Request $request) |
|
24
|
|
|
{ |
|
25
|
1 |
|
return $this->get('app.registration.user') |
|
26
|
1 |
|
->registrationUser($request); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @Route("/registrationNet", name="net_registration") |
|
31
|
|
|
* @Template("@App/registration/updateRegistration.html.twig") |
|
32
|
|
|
*/ |
|
33
|
1 |
|
public function registerSocialNetAction(Request $request) |
|
34
|
|
|
{ |
|
35
|
1 |
|
$user = $this->getUser(); |
|
36
|
|
|
|
|
37
|
1 |
|
if ($user) { |
|
38
|
|
|
if ($user->getIsReg() === false) { |
|
39
|
|
|
return $this->get('app.registration.user') |
|
40
|
|
|
->updateRegistrationUser($request, $user); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
return $this->redirectToRoute('account'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
return $this->redirectToRoute('homepage'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @Route("/register/check_useremail", name="register_check_email") |
|
51
|
|
|
*/ |
|
52
|
|
|
public function checkUserEmail(Request $request) |
|
53
|
|
|
{ |
|
54
|
|
|
$email = $request->request->get('email'); |
|
55
|
|
|
|
|
56
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
57
|
|
|
|
|
58
|
|
|
$user = $em->getRepository('AppBundle:User') |
|
59
|
|
|
->findOneBy(array('email' => $email)); |
|
60
|
|
|
|
|
61
|
|
|
if ($user) { |
|
62
|
|
|
|
|
63
|
|
|
return new Response('No', 200); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return new Response('Yes', 200); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @Route("/registration/check_hash/{hash}/{email}", name="register_check_hash") |
|
71
|
|
|
* @Method("GET") |
|
72
|
|
|
*/ |
|
73
|
|
|
public function checkUserHash($hash, $email) |
|
74
|
|
|
{ |
|
75
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
76
|
|
|
|
|
77
|
|
|
$user = $em->getRepository('AppBundle:User') |
|
78
|
|
|
->findOneBy(array('email' => $email, 'hash' => $hash)); |
|
79
|
|
|
|
|
80
|
|
|
if ($user) { |
|
81
|
|
|
|
|
82
|
|
|
$user->setIsReg(true); |
|
83
|
|
|
$user->setHash(null); |
|
84
|
|
|
$this->addFlash('notice', 'You have successfully passed registration confirmation'); |
|
85
|
|
|
|
|
86
|
|
|
$em->flush(); |
|
87
|
|
|
|
|
88
|
|
|
return $this->redirectToRoute('homepage'); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
$this->addFlash('notice', 'You haven\'t passed registration confirmation'); |
|
92
|
|
|
|
|
93
|
|
|
return $this->redirectToRoute('homepage'); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @Route("/registration/recovery-password", name="recovery_password") |
|
98
|
|
|
* @Template("@App/registration/recoveryPassword.html.twig") |
|
99
|
|
|
*/ |
|
100
|
|
|
public function recoveryPassword(Request $request) |
|
101
|
|
|
{ |
|
102
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
103
|
|
|
|
|
104
|
|
|
$email = trim($request->get('email')); |
|
105
|
|
|
|
|
106
|
|
|
$user = $em->getRepository('AppBundle:User') |
|
107
|
|
|
->findOneBy(['email' => $email]); |
|
108
|
|
|
|
|
109
|
|
|
if ($user && $user->getIsReg() == true) { |
|
110
|
|
|
$password = $this->get('app.custom.mailer')->sendMailRecovery($email); |
|
111
|
|
|
$newPassword = $this->get('security.password_encoder') |
|
112
|
|
|
->encodePassword($user, $password); |
|
113
|
|
|
$user->setPassword($newPassword); |
|
114
|
|
|
|
|
115
|
|
|
$em->flush(); |
|
116
|
|
|
$this->addFlash('notice', 'The new password is sent to your email'); |
|
117
|
|
|
|
|
118
|
|
|
return $this->redirectToRoute('homepage'); |
|
119
|
|
|
} elseif ($email && !$user) { |
|
120
|
|
|
|
|
121
|
|
|
$this->addFlash('notice', 'Email is incorrectly specified'); |
|
122
|
|
|
|
|
123
|
|
|
return $this->redirectToRoute('homepage'); |
|
124
|
|
|
} elseif ($user && $user->getIsReg() == false) { |
|
125
|
|
|
$this->addFlash('notice', 'You aren\'t registered'); |
|
126
|
|
|
|
|
127
|
|
|
return $this->redirectToRoute('homepage'); |
|
128
|
|
|
} else { |
|
129
|
|
|
|
|
130
|
|
|
return []; |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|