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() |
|
|
|
|
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'; |
|
|
|
|
44
|
|
|
} |
45
|
|
|
if (!Validate::string($this->body('password'), VALIDATE_ALPHA . VALIDATE_NUM)) { |
46
|
|
|
$this->error[] = 'Password ugyldigt'; |
|
|
|
|
47
|
|
|
} |
48
|
|
|
if (!empty($error) and count($error) > 0) { |
|
|
|
|
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')); |
|
|
|
|
59
|
|
|
$user_id = $db->lastInsertID('user'); |
60
|
|
|
} else { |
61
|
|
|
$this->error[] = 'Du er allerede oprettet'; |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
if (!empty($error) and count($error) > 0) { |
|
|
|
|
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(); |
|
|
|
|
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')); |
|
|
|
|
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'; |
|
|
|
|
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.