projects
/
timetracker.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Refactoring in export to use a generic get function to keep things simple.
[timetracker.git]
/
WEB-INF
/
lib
/
ttRegistrator.class.php
diff --git
a/WEB-INF/lib/ttRegistrator.class.php
b/WEB-INF/lib/ttRegistrator.class.php
index
48f4b0a
..
8e75583
100644
(file)
--- a/
WEB-INF/lib/ttRegistrator.class.php
+++ b/
WEB-INF/lib/ttRegistrator.class.php
@@
-35,7
+35,12
@@
class ttRegistrator {
var $group_name = null; // Group name.
var $currency = null; // Currency.
var $lang = null; // Language.
var $group_name = null; // Group name.
var $currency = null; // Currency.
var $lang = null; // Language.
+ var $created_by_id = null; // User, who uses the instance.
+ // Currently, there are 2 possibilities:
+ // 1) Self-registration, or null here.
+ // 2) Registration by admin with a user_id.
var $group_id = null; // Group id, set after we create a group.
var $group_id = null; // Group id, set after we create a group.
+ var $org_id = null; // Organization id, the same as group_id (top group in org).
var $role_id = null; // Role id for top managers.
var $user_id = null; // User id after registration.
var $err = null; // Error object, passed to us as reference.
var $role_id = null; // Role id for top managers.
var $user_id = null; // User id after registration.
var $err = null; // Error object, passed to us as reference.
@@
-52,6
+57,7
@@
class ttRegistrator {
$this->currency = $fields['currency'];
$this->lang = $fields['lang'];
if (!$this->lang) $this->lang = 'en';
$this->currency = $fields['currency'];
$this->lang = $fields['lang'];
if (!$this->lang) $this->lang = 'en';
+ $this->created_by_id = (int) $fields['created_by_id'];
$this->err = $err;
// Validate passed in parameters.
$this->err = $err;
// Validate passed in parameters.
@@
-84,11
+90,14
@@
class ttRegistrator {
if ($this->err->yes()) return false; // There are errors, do not proceed.
global $i18n;
if ($this->err->yes()) return false; // There are errors, do not proceed.
global $i18n;
-
- // Protection fom too many recent bot registrations from user IP.
- if ($this->registeredRecently()) {
- $this->err->add($i18n->get('error.access_denied'));
- return false;
+ global $user;
+
+ // Protection from too many recent bot registrations from user IP.
+ if (!$this->created_by_id) { // No problems for logged in user (site admin).
+ if ($this->registeredRecently()) {
+ $this->err->add($i18n->get('error.access_denied'));
+ return false;
+ }
}
import('ttUserHelper');
}
import('ttUserHelper');
@@
-100,6
+109,7
@@
class ttRegistrator {
// Create a new group.
$this->group_id = $this->createGroup();
// Create a new group.
$this->group_id = $this->createGroup();
+ $this->org_id = $this->group_id;
if (!$this->group_id) {
$this->err->add($i18n->get('error.db'));
return false;
if (!$this->group_id) {
$this->err->add($i18n->get('error.db'));
return false;
@@
-118,7
+128,9
@@
class ttRegistrator {
return false;
}
return false;
}
- if (!$this->setCreatedBy($this->user_id))
+ // Set created_by appropriately.
+ $created_by = $this->created_by_id ? $this->created_by_id : $this->user_id;
+ if (!$this->setCreatedBy($created_by))
return false;
return true;
return false;
return true;
@@
-159,9
+171,9
@@
class ttRegistrator {
$email = $mdb2->quote($this->email);
$created = 'now()';
$created_ip = $mdb2->quote($_SERVER['REMOTE_ADDR']);
$email = $mdb2->quote($this->email);
$created = 'now()';
$created_ip = $mdb2->quote($_SERVER['REMOTE_ADDR']);
- $values = "values($login, $password, $name, $this->group_id, $this->role_id, $email, $created, $created_ip)";
+ $values = "values($login, $password, $name, $this->group_id, $this->
org_id, $this->
role_id, $email, $created, $created_ip)";
- $sql = 'insert into tt_users (login, password, name, group_id, role_id, email, created, created_ip) '.$values;
+ $sql = 'insert into tt_users (login, password, name, group_id,
org_id,
role_id, email, created, created_ip) '.$values;
$affected = $mdb2->exec($sql);
if (!is_a($affected, 'PEAR_Error')) {
$user_id = $mdb2->lastInsertID('tt_users', 'id');
$affected = $mdb2->exec($sql);
if (!is_a($affected, 'PEAR_Error')) {
$user_id = $mdb2->lastInsertID('tt_users', 'id');
@@
-171,14
+183,14
@@
class ttRegistrator {
}
// The setCreatedBy sets created_by field for both group and user to passed in user_id.
}
// The setCreatedBy sets created_by field for both group and user to passed in user_id.
- function setCreatedBy($user_id) {
+
private
function setCreatedBy($user_id) {
if ($this->err->yes()) return false; // There are errors, do not proceed.
global $i18n;
$mdb2 = getConnection();
// Update group.
if ($this->err->yes()) return false; // There are errors, do not proceed.
global $i18n;
$mdb2 = getConnection();
// Update group.
- $sql = "update tt_groups set created_by = $user_id where id = $this->group_id";
+ $sql = "update tt_groups set created_by = $user_id where id = $this->group_id
and org_id = $this->org_id
";
$affected = $mdb2->exec($sql);
if (is_a($affected, 'PEAR_Error')) {
$this->err->add($i18n->get('error.db'));
$affected = $mdb2->exec($sql);
if (is_a($affected, 'PEAR_Error')) {
$this->err->add($i18n->get('error.db'));
@@
-186,7
+198,7
@@
class ttRegistrator {
}
// Update top manager.
}
// Update top manager.
- $sql = "update tt_users set created_by = $user_id where id = $
user_id and group_id = $this->group
_id";
+ $sql = "update tt_users set created_by = $user_id where id = $
this->user_id and group_id = $this->group_id and org_id = $this->org
_id";
$affected = $mdb2->exec($sql);
if (is_a($affected, 'PEAR_Error')) {
$this->err->add($i18n->get('error.db'));
$affected = $mdb2->exec($sql);
if (is_a($affected, 'PEAR_Error')) {
$this->err->add($i18n->get('error.db'));