* Copyright 2011, Franck Villaume - Capgemini
* http://fusionforge.org
*
- * This file is part of FusionForge.
+ * This file is part of FusionForge. FusionForge is free software;
+ * you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the Licence, or (at your option)
+ * any later version.
*
- * FusionForge is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * FusionForge is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with FusionForge; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * You should have received a copy of the GNU General Public License along
+ * with FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
$USER_OBJ=array();
/**
* user_get_object_by_name() - Get User object by username.
* user_get_object is useful so you can pool user objects/save database queries
- * You should always use this instead of instantiating the object directly
+ * You should always use this instead of instantiating the object directly
*
* @param string The unix username - required
* @param int The result set handle ("SELECT * FROM USERS WHERE user_id=xx")
/**
* user_get_object() - Get User object by user ID.
* user_get_object is useful so you can pool user objects/save database queries
- * You should always use this instead of instantiating the object directly
+ * You should always use this instead of instantiating the object directly
*
* @param int The ID of the user - required
* @param int The result set handle ("SELECT * FROM USERS WHERE user_id=xx")
function &user_get_object($user_id, $res = false) {
//create a common set of group objects
//saves a little wear on the database
-
- //automatically checks group_type and
+
+ //automatically checks group_type and
//returns appropriate object
-
+
global $USER_OBJ;
if (!isset($USER_OBJ["_".$user_id."_"])) {
if ($res) {
}
class GFUser extends Error {
- /**
+ /**
* Associative array of data from db.
*
* @var array $data_array.
*/
var $data_array;
-
+
/**
* Is this person a site super-admin?
*
* @param int The user_id
* @param int The database result set OR array of data
*/
- function GFUser($id=false,$res=false) {
+ function GFUser($id = false, $res = false) {
$this->Error();
if (!$id) {
//setting up an empty object
$this->is_logged_in=false;
return true;
}
-
+
/**
* create() - Create a new user.
*
// ...based on the email address:
$email_array = explode ('@', $email, 2) ;
$email_u = $email_array [0];
- $l = ereg_replace('[^a-z0-9]', '', $email_u);
+ $l = preg_replace('/[^a-z0-9]/', '', $email_u);
$l = substr ($l, 0, 15);
// Is the user part of the email address okay?
if (account_namevalid($l)
$hook_params['user_name'] = $unix_name;
$hook_params['user_password'] = $password1;
plugin_hook("user_create", $hook_params);
-
+
if ($send_mail) {
setup_gettext_from_lang_id($language_id);
$this->sendRegistrationEmail();
function sendRegistrationEmail() {
$message=stripcslashes(sprintf(_('Thank you for registering on the %3$s web site. You have
account with username %1$s created for you. In order
-to complete your registration, visit the following url:
+to complete your registration, visit the following url:
<%2$s>
-- the %3$s staff
'),
$this->getUnixName(),
- util_make_url ('/account/verify.php?confirm_hash=_'.$this->getConfirmHash()),
- forge_get_config ('forge_name')));
+ util_make_url('/account/verify.php?confirm_hash=_'.$this->getConfirmHash()),
+ forge_get_config('forge_name')));
util_send_message(
$this->getEmail(),
- sprintf(_('%1$s Account Registration'), forge_get_config ('forge_name')),
+ sprintf(_('%1$s Account Registration'), forge_get_config('forge_name')),
$message
);
}
$block_ratings,
$jabber_address,
$jabber_only,
- htmlspecialchars($address) ,
- htmlspecialchars($address2) ,
- htmlspecialchars($phone) ,
- htmlspecialchars($fax) ,
- htmlspecialchars($title) ,
+ htmlspecialchars($address),
+ htmlspecialchars($address2),
+ htmlspecialchars($phone),
+ htmlspecialchars($fax),
+ htmlspecialchars($title),
$ccode,
$theme_id,
$tooltips,
- $this->getID())) ;
+ $this->getID()));
if (!$res) {
$this->setError(_('ERROR - Could Not Update User Object:'). ' ' .db_error());
db_rollback();
return false;
}
-
+
$hook_params = array ();
$hook_params['user'] = $this;
$hook_params['user_id'] = $this->getID();
plugin_hook ("user_update", $hook_params);
-
+
db_commit();
return true;
}
$this->data_array = db_fetch_array($res);
return true;
}
-
+
/**
* getID - Simply return the user_id for this object.
*
$this->setError(_('ERROR: Invalid status value'));
return false;
}
+ if ($this->getStatus() != 'P' && $status == 'P') {
+ $this->setError('ERROR: You can\'t set pending status if user is suspend or active');
+ return false;
+ }
db_begin();
$res = db_query_params ('UPDATE users SET status=$1 WHERE user_id=$2',
$hook_params['user_id'] = $this->getID();
$hook_params['status'] = $status;
plugin_hook ("user_setstatus", $hook_params);
-
+
db_commit();
-
+
return true;
}
}
}
}
}
-
+
$this->data_array['unix_status']=$status;
db_commit();
return true;
function getMD5Passwd() {
return $this->data_array['user_pw'];
}
-
+
//Added to be compatible with codendi getUserPw function
function getUserPw() {
return $this->data_array['user_pw'];
function getEmail() {
return str_replace("\n", "", $this->data_array['email']);
}
-
+
/**
* getSha1Email - a SHA1 encoded hash of the email URI (including mailto: prefix)
- *
+ *
* @return string The SHA1 encoded value for the email
*/
function getSha1Email() {
$hook_params['user_id'] = $this->getID();
$hook_params['user_email'] = $email;
plugin_hook("user_setemail", $hook_params);
-
+
if (!$this->fetchData($this->getId())) {
db_rollback();
return false;
* @return array Array of groups.
*/
function &getGroups($onlylocal = true) {
- $ids = array () ;
+ $ids = array();
foreach ($this->getRoles() as $r) {
if ($onlylocal) {
if ($r instanceof RoleExplicit
&& $r->getHomeProject() != NULL) {
- $ids[] = $r->getHomeProject()->getID() ;
+ $ids[] = $r->getHomeProject()->getID();
}
} else {
foreach ($r->getLinkedProjects() as $p) {
- $ids[] = $p->getID() ;
+ $ids[] = $p->getID();
}
}
}
$res = db_query_params('DELETE FROM user_preferences WHERE user_id=$1 AND preference_name=$2',
array ($this->getID(),
$preference_name));
- return $res;
+ return ((!$res || db_affected_rows($res) < 1) ? false : true);
}
/**
$preference_name,
$value,
time())) ;
- return $result;
}
}
+ return ((!$result || db_affected_rows($result) < 1) ? false : true);
}
/**
return true;
}
+ /**
+ * setMD5Passwd - Changes user's MD5 password.
+ *
+ * @param string The MD5-hashed password.
+ * @return boolean success.
+ */
+ function setMD5Passwd($md5) {
+ global $SYS;
+
+ db_begin();
+
+ if ($md5) {
+ $res = db_query_params('UPDATE users SET user_pw=$1 WHERE user_id=$2',
+ array($md5_pw,
+ $this->getID()));
+
+ if (!$res || db_affected_rows($res) < 1) {
+ $this->setError(_('ERROR - Could Not Change User Password:') . ' ' .db_error());
+ db_rollback();
+ return false;
+ }
+ }
+ db_commit();
+ return true;
+ }
+
+ /**
+ * setUnixPasswd - Changes user's Unix-hashed password.
+ *
+ * @param string The Unix-hashed password.
+ * @return boolean success.
+ */
+ function setUnixPasswd($unix) {
+ global $SYS;
+
+ db_begin();
+
+ if ($unix) {
+ $res = db_query_params('UPDATE users SET unix_pw=$1 WHERE user_id=$1',
+ array ($unix_pw,
+ $this->getID()));
+
+ if (!$res || db_affected_rows($res) < 1) {
+ $this->setError(_('ERROR - Could Not Change User Password:') . ' ' .db_error());
+ db_rollback();
+ return false;
+ }
+
+ // Now change system password, but only if corresponding
+ // entry exists (i.e. if user have shell access)
+ if ($SYS->sysCheckUser($this->getID())) {
+ if (!$SYS->sysUserSetAttribute($this->getID(),"userPassword",'{crypt}'.$unix)) {
+ $this->setError($SYS->getErrorMessage());
+ db_rollback();
+ return false;
+ }
+ }
+ }
+ db_commit();
+ return true;
+ }
+
/**
* usesRatings - whether user participates in rating system.
*
}
/**
- * usesPlugin - returns true if the user uses a particular plugin
+ * usesPlugin - returns true if the user uses a particular plugin
*
* @param string name of the plugin
* @return boolean whether plugin is being used or not
* @return boolean success.
*/
function getMailingsPrefs($mailing_id) {
- if ($mailing_id=='va') {
+ if ($mailing_id == 'va') {
return $this->data_array['mail_va'];
- } else if ($mailing_id=='site') {
+ } else if ($mailing_id == 'site') {
return $this->data_array['mail_siteupdates'];
} else {
return 0;
* @param boolean If false, disable general site mailings, else - all.
* @return boolean success.
*/
- function unsubscribeFromMailings($all=false) {
+ function unsubscribeFromMailings($all = false) {
$res1 = $res2 = $res3 = true;
$res1 = db_query_params ('UPDATE users SET mail_siteupdates=0, mail_va=0 WHERE user_id=$1',
array ($this->getID())) ;
if ($all) {
- $res2 = db_query_params ('DELETE FROM forum_monitored_forums WHERE user_id=$1',
+ $res2 = db_query_params('DELETE FROM forum_monitored_forums WHERE user_id=$1',
array ($this->getID())) ;
- $res3 = db_query_params ('DELETE FROM filemodule_monitor WHERE user_id=$1',
+ $res3 = db_query_params('DELETE FROM filemodule_monitor WHERE user_id=$1',
array ($this->getID())) ;
}
return false;
}
- function getRoles () {
- return RBACEngine::getInstance()->getAvailableRolesForUser($this) ;
+ function getRoles() {
+ return RBACEngine::getInstance()->getAvailableRolesForUser($this);
}
/* Codendi Glue */
- function isMember($g,$type=0){
+ function isMember($g, $type = 0){
if (is_int ($g) || is_string($g)) {
$group = group_get_object ($g) ;
$group_id = $g ;
}
switch ($type) {
+ case 0:
+ default:
+ foreach ($this->getGroups() as $p) {
+ if ($p->getID() == $group_id) {
+ return true ;
+ }
+ }
+ return false ;
+ break;
case 'P2':
//pm admin
- return forge_check_perm_for_user($this,'pm_admin',$group_id) ;
- break;
+ return forge_check_perm_for_user($this, 'pm_admin', $group_id);
+ break;
case 'F2':
//forum admin
- return forge_check_perm_for_user($this,'forum_admin',$group_id) ;
- break;
+ return forge_check_perm_for_user($this, 'forum_admin', $group_id);
+ break;
case 'A':
//admin for this group
- return forge_check_perm_for_user($this,'project_admin',$group_id) ;
+ return forge_check_perm_for_user($this, 'project_admin', $group_id);
break;
case 'D1':
//document editor
- return forge_check_perm_for_user($this,'docman',$group_id,'admin') ;
- break;
- case '0':
- default:
- foreach ($this->getGroups() as $p) {
- if ($p->getID() == $group_id) {
- return true ;
- }
- }
- return false ;
+ return forge_check_perm_for_user($this, 'docman', $group_id, 'admin');
break;
}
}
/**
* user_ismember() - DEPRECATED; DO NOT USE! (TODO: document what should be used instead)
- * May need to be replaced by forge_check_perm ('project_admin', $group_id) if checking for project admin
+ * Replace user_ismember(1[, 'A']) with forge_check_global_perm('forge_admin')
+ * Replace user_ismember($group_id, 'A') with forge_check_perm('project_admin', $group_id)
+ * For now, keep user_ismember($group_id) alone
* @param int The Group ID
* @param int The Type
* @deprecated