|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* Administration of user data and rights |
|
5
|
|
|
* Please read in User.php for description of relations |
|
6
|
|
|
* |
|
7
|
|
|
* @package Intraface_Administration |
|
8
|
|
|
* @author Sune Jensen <[email protected]> |
|
9
|
|
|
* @author Lars Olesen <[email protected]> |
|
10
|
|
|
* @since 0.1.0 |
|
11
|
|
|
* @version @package-version@ |
|
12
|
|
|
* |
|
13
|
|
|
* |
|
14
|
|
|
*/ |
|
15
|
|
|
class UserAdministration extends Intraface_User |
|
16
|
|
|
{ |
|
17
|
|
|
function __construct($kernel, $id) |
|
18
|
|
|
{ |
|
19
|
|
|
parent::__construct($id); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @todo why use this instead of the one in user? |
|
24
|
|
|
*/ |
|
25
|
|
View Code Duplication |
function update($input) |
|
|
|
|
|
|
26
|
|
|
{ |
|
27
|
|
|
$this->validate($input); |
|
28
|
|
|
$validator = new Intraface_Validator($this->error); |
|
29
|
|
|
|
|
30
|
|
|
if (!empty($input["password"])) { |
|
31
|
|
|
if ($this->id == 0) { |
|
32
|
|
|
$validator->isPassword($input["password"], 6, 16, "Ugyldig adgangskode. Den skal være mellem 6 og 16 tegn, og må indeholde store og små bogstaver samt tal"); |
|
33
|
|
|
} else { |
|
34
|
|
|
$validator->isPassword($input["password"], 6, 16, "Ugyldig adgangskode. Den skal være mellem 6 og 16 tegn, og må indeholde store og små bogstaver samt tal", "allow_empty"); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$sql = "email = \"".$input["email"]."\""; |
|
39
|
|
|
|
|
40
|
|
|
if (!empty($input["password"])) { |
|
41
|
|
|
if ($input["password"] === $input["confirm_password"]) { |
|
42
|
|
|
$sql .= ", password = \"".md5($input["password"])."\""; |
|
43
|
|
|
} else { |
|
44
|
|
|
$this->error->set("De to adgangskoder er ikke ens!"); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
if ($this->error->isError()) { |
|
|
|
|
|
|
49
|
|
|
return false; |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
if ($this->id) { |
|
53
|
|
|
$this->db->exec("UPDATE user SET ".$sql." WHERE id = ".$this->id); |
|
54
|
|
|
$this->load(); |
|
55
|
|
|
return $this->id; |
|
56
|
|
|
} else { |
|
57
|
|
|
$this->db->exec("INSERT INTO user SET ".$sql); |
|
58
|
|
|
$this->id = $this->db->lastInsertId(); |
|
59
|
|
|
$this->load(); |
|
60
|
|
|
return $this->id; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
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.