GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( a45ff7...6e1cf9 )
by Borut
03:30
created

MyController::passwordAction()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 43
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 43
rs 8.5806
cc 4
eloc 24
nc 4
nop 2
1
<?php
2
3
namespace Application\Controller\MembersArea;
4
5
use Silex\Application;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Application\Form\Type\User\SettingsType;
9
use Application\Form\Type\User\PasswordType;
10
11
/**
12
 * @author Borut Balažek <[email protected]>
13
 */
14
class MyController
15
{
16
    /**
17
     * @param Application $app
18
     *
19
     * @return Response
20
     */
21
    public function indexAction(Application $app)
22
    {
23
        return $app->redirect(
24
            $app['url_generator']->generate('members-area.my.profile')
25
        );
26
    }
27
28
    /**
29
     * @param Application $app
30
     *
31
     * @return Response
32
     */
33
    public function profileAction(Application $app)
34
    {
35
        return new Response(
36
            $app['twig']->render(
37
                'contents/members-area/my/profile.html.twig'
38
            )
39
        );
40
    }
41
42
    /**
43
     * @param Request     $request
44
     * @param Application $app
45
     *
46
     * @return Response
47
     */
48
    public function settingsAction(Request $request, Application $app)
49
    {
50
        $data = array();
51
52
        $form = $app['form.factory']->create(
53
            new SettingsType(),
54
            $app['user']
55
        );
56
57
        // IMPORTANT Security fix!
58
        $currentUserUsername = $app['user']->getUsername();
59
60
        if ($request->getMethod() == 'POST') {
61
            $form->handleRequest($request);
62
63
            // IMPORTANT Security fix!
64
            /*
65
             * Some weird bug here allows to impersonate to another user
66
             *   by just changing to his (like some admins) username
67
             *   (after failed "username already used" message)
68
             *   when the validation kicks in, and one refresh later,
69
             *   you're logged in as that user.
70
             */
71
            $app['user']->setUsername($currentUserUsername);
72
73
            if ($form->isValid()) {
74
                $userEntity = $form->getData();
75
76
                /*** Image ***/
77
                $userEntity
78
                    ->getProfile()
79
                    ->setImageUploadPath($app['baseUrl'].'/assets/uploads/')
80
                    ->setImageUploadDir(WEB_DIR.'/assets/uploads/')
81
                    ->imageUpload()
82
                ;
83
84
                $app['orm.em']->persist($userEntity);
85
                $app['orm.em']->flush();
86
87
                $app['flashbag']->add(
88
                    'success',
89
                    $app['translator']->trans(
90
                        'members-area.my.settings.successText'
91
                    )
92
                );
93
            }
94
        }
95
96
        $data['form'] = $form->createView();
97
98
        return new Response(
99
            $app['twig']->render(
100
                'contents/members-area/my/settings.html.twig',
101
                $data
102
            )
103
        );
104
    }
105
106
    /**
107
     * @param Request     $request
108
     * @param Application $app
109
     *
110
     * @return Response
111
     */
112
    public function passwordAction(Request $request, Application $app)
113
    {
114
        $data = array();
115
116
        $form = $app['form.factory']->create(
117
            new PasswordType(),
118
            $app['user']
119
        );
120
121
        if ($request->getMethod() == 'POST') {
122
            $form->handleRequest($request);
123
124
            if ($form->isValid()) {
125
                $userEntity = $form->getData();
126
127
                if ($userEntity->getPlainPassword()) {
128
                    $userEntity->setPlainPassword(
129
                        $userEntity->getPlainPassword(),
130
                        $app['security.encoder_factory']
131
                    );
132
133
                    $app['orm.em']->persist($userEntity);
134
                    $app['orm.em']->flush();
135
136
                    $app['flashbag']->add(
137
                        'success',
138
                        $app['translator']->trans(
139
                            'members-area.my.password.successText'
140
                        )
141
                    );
142
                }
143
            }
144
        }
145
146
        $data['form'] = $form->createView();
147
148
        return new Response(
149
            $app['twig']->render(
150
                'contents/members-area/my/password.html.twig',
151
                $data
152
            )
153
        );
154
    }
155
}
156