This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
|||||||||||
2 | /** |
|||||||||||
3 | * Signup |
|||||||||||
4 | * |
|||||||||||
5 | * @todo Could easily be changed so one could create oneself on an intranet, you have a code for |
|||||||||||
6 | * |
|||||||||||
7 | * @package Intraface |
|||||||||||
8 | * @author Lars Olesen <[email protected]> |
|||||||||||
9 | * @since 0.1.0 |
|||||||||||
10 | * @version @package-version@ |
|||||||||||
11 | */ |
|||||||||||
12 | class Intraface_Controller_Signup extends k_Component |
|||||||||||
13 | { |
|||||||||||
14 | public $msg = ''; |
|||||||||||
15 | public $errors = array(); |
|||||||||||
16 | protected $kernel; |
|||||||||||
17 | protected $template; |
|||||||||||
18 | protected $mdb2; |
|||||||||||
19 | ||||||||||||
20 | function __construct(k_TemplateFactory $template, MDB2_Driver_Common $mdb2) |
|||||||||||
21 | { |
|||||||||||
22 | $this->mdb2 = $mdb2; |
|||||||||||
23 | $this->template = $template; |
|||||||||||
24 | } |
|||||||||||
25 | ||||||||||||
26 | function execute() |
|||||||||||
27 | { |
|||||||||||
28 | $this->url_state->init("continue", $this->url('/login')); |
|||||||||||
29 | return parent::execute(); |
|||||||||||
30 | } |
|||||||||||
31 | ||||||||||||
32 | View Code Duplication | function renderHtml() |
||||||||||
0 ignored issues
–
show
|
||||||||||||
33 | { |
|||||||||||
34 | $this->document->setTitle('Signup'); |
|||||||||||
35 | ||||||||||||
36 | $smarty = $this->template->create(dirname(__FILE__) . '/templates/signup'); |
|||||||||||
37 | return $smarty->render($this); |
|||||||||||
38 | } |
|||||||||||
39 | ||||||||||||
40 | function postForm() |
|||||||||||
41 | { |
|||||||||||
42 | if (!Validate::email($this->body('email'))) { |
|||||||||||
43 | $this->error[] = 'E-mail ugyldig'; |
|||||||||||
0 ignored issues
–
show
The property
error does not seem to exist. Did you mean errors ?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
||||||||||||
44 | } |
|||||||||||
45 | if (!Validate::string($this->body('password'), VALIDATE_ALPHA . VALIDATE_NUM)) { |
|||||||||||
46 | $this->error[] = 'Password ugyldigt'; |
|||||||||||
0 ignored issues
–
show
The property
error does not seem to exist. Did you mean errors ?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
||||||||||||
47 | } |
|||||||||||
48 | if (!empty($error) and count($error) > 0) { |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
and instead of && is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
49 | $this->msg = 'Vi kunne ikke oprette dig'; |
|||||||||||
50 | return $this->render(); |
|||||||||||
51 | } else { |
|||||||||||
52 | $db = $this->mdb2; |
|||||||||||
53 | $res = $db->query("SELECT id FROM user WHERE email = ".$db->quote($this->body('email'), 'text')); |
|||||||||||
54 | if (PEAR::isError($res)) { |
|||||||||||
55 | throw new Exception($res->getMessage()); |
|||||||||||
56 | } |
|||||||||||
57 | if ($res->numRows() == 0) { |
|||||||||||
58 | $res = $db->query("INSERT INTO user SET email = ".$db->quote($this->body('email'), 'text').", password=".$db->quote(md5($this->body('password')), 'text')); |
|||||||||||
0 ignored issues
–
show
$res is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
||||||||||||
59 | $user_id = $db->lastInsertID('user'); |
|||||||||||
60 | } else { |
|||||||||||
61 | $this->error[] = 'Du er allerede oprettet'; |
|||||||||||
0 ignored issues
–
show
The property
error does not seem to exist. Did you mean errors ?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
||||||||||||
62 | } |
|||||||||||
63 | ||||||||||||
64 | if (!empty($error) and count($error) > 0) { |
|||||||||||
0 ignored issues
–
show
The variable
$error seems to never exist, and therefore empty should always return true . Did you maybe rename this variable?
This check looks for calls to This is most likely caused by the renaming of a variable or the removal of a function/method parameter. ![]() Comprehensibility
Best Practice
introduced
by
Using logical operators such as
and instead of && is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
65 | $this->msg = 'Du er allerede oprettet. <a href="'.url('/login').'">Login</a>.'; |
|||||||||||
66 | return $this->render(); |
|||||||||||
67 | } else { |
|||||||||||
68 | require_once 'Intraface/modules/intranetmaintenance/IntranetMaintenance.php'; |
|||||||||||
69 | $intranet = new IntranetMaintenance(); |
|||||||||||
70 | $data = array('identifier' => $this->body('identifier'), 'name' => $this->body('name')); |
|||||||||||
71 | if (!$intranet->save($data)) { |
|||||||||||
72 | $this->msg = $intranet->error->view(); |
|||||||||||
0 ignored issues
–
show
The property
error does not seem to exist in IntranetMaintenance .
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
||||||||||||
73 | } else { |
|||||||||||
74 | $intranet_id = $intranet->getId(); // betatest intranet for forskellige brugere |
|||||||||||
75 | ||||||||||||
76 | // intranet access |
|||||||||||
77 | $db->query("INSERT INTO permission SET intranet_id = ".$db->quote($intranet_id, 'integer').", user_id = ".$db->quote($user_id, 'integer')); |
|||||||||||
0 ignored issues
–
show
The variable
$user_id does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
||||||||||||
78 | ||||||||||||
79 | // module access |
|||||||||||
80 | $modules = array('administration', 'modulepackage', 'onlinepayment', 'cms', 'filemanager', 'contact', 'debtor','quotation', 'invoice', 'order','accounting', 'product', 'stock', 'webshop'); |
|||||||||||
81 | ||||||||||||
82 | foreach ($modules as $module) { |
|||||||||||
83 | $res = $db->query("SELECT id FROM module WHERE name = ".$db->quote($module, 'text')." LIMIT 1"); |
|||||||||||
84 | if ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) { |
|||||||||||
85 | $db->query("INSERT INTO permission SET |
|||||||||||
86 | intranet_id = ".$db->quote($intranet_id, 'integer').", |
|||||||||||
87 | user_id = ".$db->quote($user_id, 'integer').", |
|||||||||||
88 | module_id = ".$db->quote($row['id'], 'integer')); |
|||||||||||
89 | $db->query("INSERT INTO permission SET |
|||||||||||
90 | intranet_id = ".$db->quote($intranet_id, 'integer').", |
|||||||||||
91 | user_id = ".$db->quote(0, 'integer').", |
|||||||||||
92 | module_id = ".$db->quote($row['id'], 'integer')); |
|||||||||||
93 | } |
|||||||||||
94 | } |
|||||||||||
95 | ||||||||||||
96 | $sub_access = array('edit_templates', 'setting', 'vat_report', 'endyear'); |
|||||||||||
97 | ||||||||||||
98 | foreach ($sub_access as $module) { |
|||||||||||
99 | $res = $db->query("SELECT id, module_id FROM module_sub_access WHERE name = ".$db->quote($module, 'text')." LIMIT 1"); |
|||||||||||
100 | if ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) { |
|||||||||||
101 | $res = $db->query("INSERT INTO permission SET intranet_id = ".$db->quote($intranet_id, 'integer').", module_sub_access_id = ".$db->quote($row['id'], 'integer').", module_id = ".$db->quote($row['module_id'], 'integer').", user_id = ".$db->quote($user_id, 'integer')); |
|||||||||||
102 | if (PEAR::isError($res)) { |
|||||||||||
103 | throw new Exception($res->getUserInfo()); |
|||||||||||
104 | $this->error[] = 'Kunne ikke oprette nogle af rettighederne'; |
|||||||||||
0 ignored issues
–
show
$this->error[] = 'Kunne ...ogle af rettighederne'; does not seem to be reachable.
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed. Unreachable code is most often the result of function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last ![]() |
||||||||||||
105 | } |
|||||||||||
106 | } |
|||||||||||
107 | } |
|||||||||||
108 | $user = new Intraface_User($user_id); |
|||||||||||
109 | $user->setActiveIntranetId($intranet_id); |
|||||||||||
110 | ||||||||||||
111 | return new k_SeeOther($this->url('../login')); |
|||||||||||
112 | } |
|||||||||||
113 | } |
|||||||||||
114 | } |
|||||||||||
115 | return $this->render(); |
|||||||||||
116 | } |
|||||||||||
117 | } |
|||||||||||
118 |
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.