UsersController::initialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
use Phalcon\Acl\Adapter\Memory as AclList;
4
use Phalcon\Acl\Role;
5
use Phalcon\Acl\Resource;
6
7
class UsersController extends ControllerBase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
    protected $model;
10
    protected $title;
11
    protected $controller;
12
13
    public function initialize()
14
    {
15
        $this->model = "User";
16
        $this->title = "Utilisateurs";
17
        $this->controller = "Users";
18
    }
19
20
    public function loginAction() {
21
22
    }
23
    
24
    public function signInAction() {
0 ignored issues
show
Coding Style introduced by
signInAction uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
25
    	$bootstrap = $this->jquery->bootstrap();
26
    	 
27
    	if(!empty($_POST['identite']) && !empty($_POST['password'])) {
28
    		
29
    		$userPseudo = User::findFirst("identite = '".$_POST['identite']."'");
30
31
    		$userMail = User::findFirst("mail = '".$_POST['identite']."'");
32
    	
33
    		if($userPseudo != NULL && password_verify($_POST['password'], $userPseudo->getPassword())) {
34
    			$this->session->set("user", $userPseudo);
35
    			$this->response->redirect("Index/index");
36
    			$this->loadAclAction($userPseudo->getIdTypeUser());
37
    		} else if($userMail != NULL && password_verify($_POST['password'], $userMail->getPassword())) {
38
    			$this->session->set("user", $userMail);
39
    			$this->response->redirect("Index/index");
40
    			$this->loadAclAction($userMail->getIdTypeUser());
41
    		} else {
42
    			echo $bootstrap->htmlAlert("alert1","L'identifiant ou le mot de passe est incorrecte.");
43
    		}
44
    	}
45
    }
46
	
47
	public function rulesAction() {
48
		$accordion=$this->jquery->bootstrap()->htmlAccordion("accordion1");
49
		$accordion->addPanel("Panel 1","Contenu du panel 1");
50
		$accordion->addPanel("Panel 2","Contenu du panel 2");
51
		echo $accordion;
52
	}
53
54
 
55
56
    public function readAction($id = null)
57
    {
58
        if ($this->verifyAccessAction($this->controller, "read")) {
59
60
        $user = User::findFirst($id);
61
        $usecases = Usecase::find("idDev=$id");
62
        $projets = array();
63
        foreach ($usecases as $u) {
64
            $projets[$u->getProjet()->getId()] = $u->getProjet();
65
        }
66
        $projetsCree = Projet::find("idClient = $id");
67
68
        $this->view->setVar("user", $user);
69
        $this->view->setVar("projets", $projets);
70
        $this->view->setVar("projetsCree", $projetsCree);
71
        $this->view->setVar("usecases", $usecases);
72
73
        $this->jquery->exec("$('#mail').editable()", true);
74
75
        $this->jquery->compile($this->view);
76
77
        }else {
78
            $this->view->pick("main/error");
79
        }
80
    }
81
82
    public function passwordAction(){
83
        $password = password_hash("password", PASSWORD_DEFAULT);
84
        echo $password;
85
    }
86
87
    public function frmAction()
88
    {
89
        if ($this->verifyAccessAction($this->controller, "write")) {
90
            $typeUser = TypeUser::find();
91
            $this->view->setVar("typeUser", $typeUser);
92
        }else {
93
            $this->view->pick("main/error");
94
        }
95
96
    }
97
98
    public function updateAction(){
99
        if ($this->verifyAccessAction($this->controller, "write")) {
100
            if ($this->request->isPost()) {
101
                $user = new User();
102
                $this->setValuesToObject($user);
103
                $user->setPassword(password_hash($this->request->getPost("password", "string"), PASSWORD_DEFAULT));
104
                try {
105
                    $user->save();
106
                    echo "Instance de " . $this->model . " ajoutée";
107
                } catch (\Exception $e) {
108
                    echo "Impossible d'ajouter l'instance de " . $this->model, "danger : $e";
109
                }
110
            }
111
        }
112
        $this->response->redirect("$this->controller/index");
113
    }
114
}
115
116