Completed
Branch develop (b9c805)
by Pavel
06:33
created

RegistrationController::checkUserHash()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 22
ccs 0
cts 12
cp 0
rs 9.2
cc 2
eloc 12
nc 2
nop 2
crap 6
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