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 — user-entity ( a5fdbe...6d5c03 )
by Luis Ramón
02:54
created

UserController::apiNewUserAction()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 32
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 32
rs 8.8571
cc 3
eloc 20
nc 2
nop 1
1
<?php
2
/*
3
  ÁTICA - Aplicación web para la gestión documental de centros educativos
4
5
  Copyright (C) 2015-2016: Luis Ramón López López
6
7
  This program is free software: you can redistribute it and/or modify
8
  it under the terms of the GNU Affero General Public License as published by
9
  the Free Software Foundation, either version 3 of the License, or
10
  (at your option) any later version.
11
12
  This program is distributed in the hope that it will be useful,
13
  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
  GNU Affero General Public License for more details.
16
17
  You should have received a copy of the GNU Affero General Public License
18
  along with this program.  If not, see [http://www.gnu.org/licenses/].
19
*/
20
21
namespace AppBundle\Controller;
22
23
use AppBundle\Entity\User;
24
use AppBundle\Form\Type\UserType;
25
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
26
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
27
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
28
use Symfony\Component\Form\SubmitButton;
29
use Symfony\Component\HttpFoundation\JsonResponse;
30
use Symfony\Component\HttpFoundation\RedirectResponse;
31
use Symfony\Component\HttpFoundation\Request;
32
33
class UserController extends Controller
34
{
35
    /**
36
     * @Route("/datos", name="personal_form", methods={"GET", "POST"})
37
     */
38
    public function indexAction(Request $request)
39
    {
40
        /** @var User $user */
41
        $user = $this->getUser();
42
        $form = $this->createForm('AppBundle\Form\Type\UserType', $user, [
43
            'admin' => $this->isGranted('ROLE_ADMIN'),
44
            'me' => true
45
        ]);
46
47
        $form->handleRequest($request);
48
49
        if ($form->isSubmitted() && $form->isValid()) {
50
51
            // Guardar el usuario en la base de datos
52
53
            // Si es solicitado, cambiar la contraseña
54
            $passwordSubmit = $form->get('changePassword');
55 View Code Duplication
            if (($passwordSubmit instanceof SubmitButton) && $passwordSubmit->isClicked()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
                $user->setPassword($this->container->get('security.password_encoder')
57
                    ->encodePassword($user, $form->get('newPassword')->get('first')->getData()));
58
                $message = $this->get('translator')->trans('alert.password_changed', [], 'user');
59
            } else {
60
                $message = $this->get('translator')->trans('alert.saved', [], 'user');
61
            }
62
63
            // Probar a guardar los cambios
64
            try {
65
                $this->getDoctrine()->getManager()->flush();
66
                $this->addFlash('success', $message);
67
                return new RedirectResponse(
68
                    $this->generateUrl('frontpage')
69
                );
70
            } catch (\Exception $e) {
71
                $this->addFlash('error', $this->get('translator')->trans('alert.not_saved', [], 'user'));
72
            }
73
        }
74
75
        return $this->render('user/form.html.twig', [
76
            'form' => $form->createView(),
77
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('personal_form'),
78
            'title' => null
79
        ]);
80
    }
81
    
82
    /**
83
     * @Route("/api/usuario/crear", name="api_user_new", methods={"GET", "POST"})
84
     * @Security("is_granted('ROLE_DEPARTMENT_HEAD')")
85
     */
86
    public function apiNewUserAction(Request $request)
87
    {
88
        $em = $this->getDoctrine()->getManager();
89
90
        $newUser = new User();
91
92
        $form = $this->createForm('AppBundle\Form\Type\NewUserType', $newUser, [
93
            'action' => $this->generateUrl('api_user_new'),
94
            'method' => 'POST'
95
        ]);
96
        $form->handleRequest($request);
97
98
        if ($form->isValid() && $form->isSubmitted()) {
99
            $newUser
100
                ->setEnabled(true)
101
                ->setFinancialManager(false)
102
                ->setGlobalAdministrator(false);
103
104
            $em->persist($newUser);
105
            $em->flush();
106
107
            return new JsonResponse([
108
                'success' => true,
109
                'id' => $newUser->getId(),
110
                'name' => $newUser->getFullPersonDisplayName()
111
            ]);
112
        }
113
114
        return $this->render('user/new_user_partial.html.twig', [
115
            'form' => $form->createView()
116
        ]);
117
    }
118
}
119