* 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")
return user_get_object(db_result($res, 0, 'user_id'), $res);
}
+/**
+ * user_get_object_by_name_or_email() - Get User object by username or email.
+ * 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
+ *
+ * @param string The unix username - required
+ * @param int The result set handle ("SELECT * FROM USERS WHERE user_id=xx")
+ * @return a user object or false on failure
+ */
+function &user_get_object_by_name_or_email($user_name, $res = false) {
+ $user = user_get_object_by_name($user_name, $res);
+ if (is_object($user)) {
+ return $user ;
+ }
+
+ $user = user_get_object_by_email($user_name, $res) ;
+ if (is_object($user)) {
+ return $user ;
+ }
+
+ return false;
+}
+
/**
* 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?
*
$this->is_logged_in=false;
return true;
}
-
+
/**
* create() - Create a new user.
*
* @param string The users preference for receiving community updates by email.
* @param int The ID of the language preference.
* @param string The users preferred timezone.
- * @param string The users Jabber address.
- * @param int The users Jabber preference.
+ * @param ignored (no longer used)
+ * @param ignored (no longer used)
* @param int The users theme_id.
* @param string The users unix_box.
* @param string The users address.
*
*/
function create($unix_name, $firstname, $lastname, $password1, $password2, $email,
- $mail_site, $mail_va, $language_id, $timezone, $jabber_address, $jabber_only, $theme_id,
+ $mail_site, $mail_va, $language_id, $timezone, $dummy1, $dummy2, $theme_id,
$unix_box = 'shell', $address = '', $address2 = '', $phone = '', $fax = '', $title = '', $ccode = 'US', $send_mail = true, $tooltips = true) {
global $SYS;
if (!$theme_id) {
$this->setError(_('Invalid Email Address:') .' '. $email);
return false;
}
- if ($jabber_address && !validate_email($jabber_address)) {
- $this->setError(_('Invalid Jabber Address'));
- return false;
- }
- if (!$jabber_only) {
- $jabber_only=0;
- } else {
- $jabber_only=1;
- }
if ($unix_name && db_numrows(db_query_params('SELECT user_id FROM users WHERE user_name LIKE $1',
array($unix_name))) > 0) {
$this->setError(_('That username already exists.'));
// ...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)
// if we got this far, it must be good
$confirm_hash = substr(md5($password1 . util_randbytes() . microtime()),0,16);
db_begin();
- $result = db_query_params('INSERT INTO users (user_name,user_pw,unix_pw,realname,firstname,lastname,email,add_date,status,confirm_hash,mail_siteupdates,mail_va,language,timezone,jabber_address,jabber_only,unix_box,address,address2,phone,fax,title,ccode,theme_id,tooltips)
- VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25)',
+ $result = db_query_params('INSERT INTO users (user_name,user_pw,unix_pw,realname,firstname,lastname,email,add_date,status,confirm_hash,mail_siteupdates,mail_va,language,timezone,unix_box,address,address2,phone,fax,title,ccode,theme_id,tooltips)
+ VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23)',
array($unix_name,
md5($password1),
account_genunixpw($password1),
(($mail_va)?"1":"0"),
$language_id,
$timezone,
- $jabber_address,
- $jabber_only,
$unix_box,
htmlspecialchars($address),
htmlspecialchars($address2),
$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>
plugin_hook("user_delete", $hook_params);
$this->setStatus('D');
+ $this->setUnixStatus('D');
db_commit();
}
return true;
* @param string The users preference for receiving site updates by email.
* @param string The users preference for receiving community updates by email.
* @param string The users preference for being participating in "peer ratings".
- * @param string The users Jabber account address.
- * @param int The users Jabber preference.
+ * @param ignored (no longer used)
+ * @param ignored (no longer used)
* @param int The users theme_id preference.
* @param string The users address.
* @param string The users address2.
* @param string The users email.
*/
function update($firstname, $lastname, $language_id, $timezone, $mail_site, $mail_va, $use_ratings,
- $jabber_address, $jabber_only, $theme_id, $address, $address2, $phone, $fax, $title, $ccode, $tooltips, $email='') {
+ $dummy1, $dummy2, $theme_id, $address, $address2, $phone, $fax, $title, $ccode, $tooltips, $email='') {
$mail_site = $mail_site ? 1 : 0;
$mail_va = $mail_va ? 1 : 0;
$block_ratings = $use_ratings ? 0 : 1;
- if ($jabber_address && !validate_email($jabber_address)) {
- $this->setError(_('Invalid Jabber Address'));
- return false;
- }
- if (!$jabber_only) {
- $jabber_only = 0;
- } else {
- $jabber_only = 1;
- }
-
db_begin();
$res = db_query_params('
mail_siteupdates=$6,
mail_va=$7,
block_ratings=$8,
- jabber_address=$9,
- jabber_only=$10,
- address=$11,
- address2=$12,
- phone=$13,
- fax=$14,
- title=$15,
- ccode=$16,
- theme_id=$17,
- tooltips=$18
- WHERE user_id=$19',
+ address=$9,
+ address2=$10,
+ phone=$11,
+ fax=$12,
+ title=$13,
+ ccode=$14,
+ theme_id=$15,
+ tooltips=$16
+ WHERE user_id=$17',
array (
htmlspecialchars($firstname . ' ' .$lastname),
htmlspecialchars($firstname),
$mail_site,
$mail_va,
$block_ratings,
- $jabber_address,
- $jabber_only,
htmlspecialchars($address),
htmlspecialchars($address2),
htmlspecialchars($phone),
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.
*
$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 $this->data_array['language'];
}
- /**
- * getJabberAddress - this user's optional jabber address.
- *
- * @return string This user's jabber address.
- */
- function getJabberAddress() {
- return $this->data_array['jabber_address'];
- }
-
- /**
- * getJabberOnly - whether this person wants updates sent ONLY to jabber.
- *
- * @return boolean This user's jabber preference.
- */
- function getJabberOnly() {
- return $this->data_array['jabber_only'];
- }
-
/**
* getAddress - get this user's address.
*
$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);
}
/**
$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;
$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())) {
}
/**
- * 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
}
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;
+ break;
case 'F2':
//forum admin
return forge_check_perm_for_user($this, 'forum_admin', $group_id);
- break;
+ break;
case 'A':
//admin for this group
return forge_check_perm_for_user($this, 'project_admin', $group_id);
//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;
- 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