Changed the accounts class to use the new smaller version of the phpgw_accounts table

This commit is contained in:
jengo 2001-02-05 14:58:03 +00:00
parent a7ebe1fb2e
commit f6adca46c7
6 changed files with 163 additions and 144 deletions

View File

@ -1,4 +1,3 @@
<?php <?php
include($phpgw_info["server"]["api_inc"]."/class.accounts_".$phpgw_info["server"]["account_repository"].".inc.php"); include($phpgw_info["server"]["api_inc"]."/class.accounts_".$phpgw_info["server"]["account_repository"].".inc.php");
include($phpgw_info["server"]["api_inc"]."/class.accounts_shared.inc.php");
?> ?>

View File

@ -24,73 +24,80 @@
/* $Id$ */ /* $Id$ */
class accounts_ class accounts
{ {
var $groups;
var $group_names;
var $apps;
var $db; var $db;
var $account_id;
function accounts_() var $data;
function accounts($account_id = "")
{ {
global $phpgw; global $phpgw_info, $phpgw;
if (! $account_id) {
$this->account_id = $phpgw_info["user"]["account_id"];
}
$this->db = $phpgw->db; $this->db = $phpgw->db;
//$this->read();
} }
function fill_user_array() function read()
{ {
global $phpgw_info, $phpgw; $this->db->query("select * from phpgw_accounts where account_id='" . $this->account_id . "'",__LINE__,__FILE__);
$this->db->next_record();
$this->db->query("select * from accounts where account_lid='" . $phpgw_info["user"]["userid"] . "'",__LINE__,__FILE__); $this->data["userid"] = $this->db->f("account_id");
$this->db->next_record(); $this->data["account_id"] = $this->db->f("account_id");
$this->data["account_lid"] = $this->db->f("account_lid");
/* Now dump it into the array */ $this->data["firstname"] = $this->db->f("account_firstname");
$phpgw_info["user"]["account_id"] = $this->db->f("account_id"); $this->data["lastname"] = $this->db->f("account_lastname");
$phpgw_info["user"]["firstname"] = $this->db->f("account_firstname"); $this->data["fullname"] = $this->db->f("account_firstname") . " "
$phpgw_info["user"]["lastname"] = $this->db->f("account_lastname"); . $this->db->f("account_lastname");
$phpgw_info["user"]["fullname"] = $this->db->f("account_firstname") . " "
. $this->db->f("account_lastname"); // $apps = CreateObject('phpgwapi.applications',intval($phpgw_info["user"]["account_id"]));
$phpgw_info["user"]["groups"] = explode (",", $this->db->f("account_groups")); // $prefs = CreateObject('phpgwapi.preferences',intval($phpgw_info["user"]["account_id"]));
// $phpgw_info["user"]["preferences"] = $prefs->get_saved_preferences();
// $apps = CreateObject('phpgwapi.applications',intval($phpgw_info["user"]["account_id"])); // $phpgw_info["user"]["apps"] = $apps->enabled_apps();
// $prefs = CreateObject('phpgwapi.preferences',intval($phpgw_info["user"]["account_id"]));
// $phpgw_info["user"]["preferences"] = $prefs->get_saved_preferences(); $this->data["lastlogin"] = $this->db->f("account_lastlogin");
// $phpgw_info["user"]["apps"] = $apps->enabled_apps(); $this->data["lastloginfrom"] = $this->db->f("account_lastloginfrom");
$this->data["lastpasswd_change"] = $this->db->f("account_lastpwd_change");
$phpgw_info["user"]["lastlogin"] = $this->db->f("account_lastlogin"); $this->data["status"] = $this->db->f("account_status");
$phpgw_info["user"]["lastloginfrom"] = $this->db->f("account_lastloginfrom");
$phpgw_info["user"]["lastpasswd_change"] = $this->db->f("account_lastpwd_change");
$phpgw_info["user"]["status"] = $this->db->f("account_status");
} }
function read_userData($id) function read_repository()
{ {
global $phpgw_info, $phpgw; return $this->data;
$this->db->query("select * from accounts where account_id='$id'",__LINE__,__FILE__);
$this->db->next_record();
/* Now dump it into the array */
$userData["account_id"] = $this->db->f("account_id");
$userData["account_lid"] = $this->db->f("account_lid");
$userData["firstname"] = $this->db->f("account_firstname");
$userData["lastname"] = $this->db->f("account_lastname");
$userData["fullname"] = $this->db->f("account_firstname") . " "
. $this->db->f("account_lastname");
$userData["groups"] = explode(",", $this->db->f("account_groups"));
// $apps = CreateObject('phpgwapi.applications',intval($phpgw_info["user"]["account_id"]));
// $prefs = CreateObject('phpgwapi.preferences',intval($phpgw_info["user"]["account_id"]));
// $userData["preferences"] = $prefs->get_saved_preferences();
// $userData["apps"] = $apps->enabled_apps();
$userData["lastlogin"] = $this->db->f("account_lastlogin");
$userData["lastloginfrom"] = $this->db->f("account_lastloginfrom");
$userData["lastpasswd_change"] = $this->db->f("account_lastpwd_change");
$userData["status"] = $this->db->f("account_status");
return $userData;
} }
function save_repository()
{
global $phpgw_info, $phpgw;
$db = $phpgw->db;
/* ********This sets the server variables from the database******** */
$db->query("select * from config",__LINE__,__FILE__);
while ($db->next_record()) {
$phpgw_info["server"][$db->f("config_name")] = $db->f("config_value");
}
$phpgw_info_temp["user"] = $phpgw_info["user"];
$phpgw_info_temp["apps"] = $phpgw_info["apps"];
$phpgw_info_temp["server"] = $phpgw_info["server"];
$phpgw_info_temp["hooks"] = $phpgw->hooks->read();
$phpgw_info_temp["user"]["preferences"] = $phpgw_info["user"]["preferences"];
$phpgw_info_temp["user"]["kp3"] = ""; // We don't want it anywhere in the
// database for security.
if ($PHP_VERSION < "4.0.0") {
$info_string = addslashes($phpgw->crypto->encrypt($phpgw_info_temp));
} else {
$info_string = $phpgw->crypto->encrypt($phpgw_info_temp);
}
$db->query("update phpgw_sessions set session_info='$info_string' where session_id='"
. $phpgw_info["user"]["sessionid"] . "'",__LINE__,__FILE__);
}
function read_groups($id) function read_groups($id)
{ {
global $phpgw_info, $phpgw; global $phpgw_info, $phpgw;
@ -141,7 +148,7 @@
if ($group) { if ($group) {
$users = $phpgw->acl->get_ids_for_location($group, 1, "phpgw_group", "u"); $users = $phpgw->acl->get_ids_for_location($group, 1, "phpgw_group", "u");
reset ($users); reset ($users);
$sql = "select account_lid,account_firstname,account_lastname from accounts where account_id in ("; $sql = "select account_lid,account_firstname,account_lastname from phpgw_accounts where account_id in (";
for ($idx=0; $idx<count($num); ++$idx){ for ($idx=0; $idx<count($num); ++$idx){
if ($idx == 1){ if ($idx == 1){
$sql .= $users[$idx]; $sql .= $users[$idx];
@ -152,7 +159,7 @@
$sql .= ")"; $sql .= ")";
$this->db->query($sql,__LINE__,__FILE__); $this->db->query($sql,__LINE__,__FILE__);
} else { } else {
$this->db->query("select account_lid,account_firstname,account_lastname from accounts",__LINE__,__FILE__); $this->db->query("select account_lid,account_firstname,account_lastname from phpgw_accounts",__LINE__,__FILE__);
} }
$i = 0; $i = 0;
while ($this->db->next_record()) { while ($this->db->next_record()) {
@ -168,7 +175,7 @@
{ {
global $phpgw, $phpgw_info; global $phpgw, $phpgw_info;
$this->db->query("SELECT account_id FROM accounts WHERE account_lid='".$account_name."'",__LINE__,__FILE__); $this->db->query("SELECT account_id FROM phpgw_accounts WHERE account_lid='".$account_name."'",__LINE__,__FILE__);
if($this->db->num_rows()) { if($this->db->num_rows()) {
$this->db->next_record(); $this->db->next_record();
@ -182,7 +189,7 @@
{ {
global $phpgw, $phpgw_info; global $phpgw, $phpgw_info;
$this->db->query("SELECT account_lid FROM accounts WHERE account_id='".$account_id."'",__LINE__,__FILE__); $this->db->query("SELECT account_lid FROM phpgw_accounts WHERE account_id='".$account_id."'",__LINE__,__FILE__);
if($this->db->num_rows()) { if($this->db->num_rows()) {
$this->db->next_record(); $this->db->next_record();
return $this->db->f("account_lid"); return $this->db->f("account_lid");
@ -193,47 +200,48 @@
function get_type($account_id) function get_type($account_id)
{ {
global $phpgw, $phpgw_info; global $phpgw, $phpgw_info;
/* $this->db->query("SELECT account_type FROM phpgw_accounts WHERE account_id='".$account_id."'",__LINE__,__FILE__);
$this->db->query("SELECT account_type FROM accounts WHERE account_id='".$account_id."'",__LINE__,__FILE__); if ($this->db->num_rows()) {
if($this->db->num_rows()) { $this->db->next_record();
$this->db->next_record(); return $this->db->f("account_type");
return $this->db->f("account_type"); } else {
}else{ return False;
return False; }
}
*/
return "u";
} }
function exists($accountname){ function exists($accountname)
$this->db->query("SELECT account_id FROM accounts WHERE account_lid='".$accountname."'",__LINE__,__FILE__); {
if($this->db->num_rows()) { $this->db->query("SELECT account_id FROM phpgw_accounts WHERE account_lid='".$accountname."'",__LINE__,__FILE__);
return True; if ($this->db->num_rows()) {
}else{ return True;
return False; } else {
} return False;
}
} }
function auto_generate($accountname, $passwd, $defaultprefs =""){ function auto_generate($accountname, $passwd, $defaultprefs ="")
global $phpgw, $phpgw_info; {
$accountid = mt_rand (100, 600000); global $phpgw, $phpgw_info;
if ($defaultprefs ==""){ $defaultprefs = 'a:5:{s:6:"common";a:1:{s:0:"";s:2:"en";}s:11:"addressbook";a:1:{s:0:"";s:4:"True";}i:8;a:1:{s:0:"";s:13:"workdaystarts";}i:15;a:1:{s:0:"";s:11:"workdayends";}s:6:"Monday";a:1:{s:0:"";s:13:"weekdaystarts";}}'; } $accountid = mt_rand (100, 600000);
$sql = "insert into accounts"; if ($defaultprefs =="") {
$sql .= "(account_id, account_lid, account_pwd, account_firstname, account_lastname, account_lastpwd_change, account_status)"; $defaultprefs = 'a:5:{s:6:"common";a:1:{s:0:"";s:2:"en";}s:11:"addressbook";a:1:{s:0:"";s:4:"True";}i:8;a:1:{s:0:"";s:13:"workdaystarts";}i:15;a:1:{s:0:"";s:11:"workdayends";}s:6:"Monday";a:1:{s:0:"";s:13:"weekdaystarts";}}';
$sql .= "values (".$accountid.", '".$accountname."', '".md5($passwd)."', '".$accountname."', 'AutoCreated', ".time().", 'A')"; }
$this->db->query($sql); $sql = "insert into phpgw_accounts";
$this->db->query("insert into preferences (preference_owner, preference_value) values ('".$accountid."', '$defaultprefs')"); $sql .= "(account_id, account_lid, account_pwd, account_firstname, account_lastname, account_lastpwd_change, account_status, account_type)";
$this->db->query("insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights)values('preferences', 'changepassword', ".$accountid.", 'u', 0)"); $sql .= "values (".$accountid.", '".$accountname."', '".md5($passwd)."', '".$accountname."', 'AutoCreated', ".time().", 'A','u')";
$this->db->query("insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights) values('phpgw_group', '1', ".$accountid.", 'u', 1)"); $this->db->query($sql);
$this->db->query("insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights) values('addressbook', 'run', ".$accountid.", 'u', 1)"); $this->db->query("insert into preferences (preference_owner, preference_value) values ('".$accountid."', '$defaultprefs')");
$this->db->query("insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights) values('filemanager', 'run', ".$accountid.", 'u', 1)"); $this->db->query("insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights)values('preferences', 'changepassword', ".$accountid.", 'u', 0)",__LINE__,__FILE__);
$this->db->query("insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights) values('calendar', 'run', ".$accountid.", 'u', 1)"); $this->db->query("insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights) values('phpgw_group', '1', ".$accountid.", 'u', 1)",__LINE__,__FILE__);
$this->db->query("insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights) values('email', 'run', ".$accountid.", 'u', 1)"); $this->db->query("insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights) values('addressbook', 'run', ".$accountid.", 'u', 1)",__LINE__,__FILE__);
$this->db->query("insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights) values('notes', 'run', ".$accountid.", 'u', 1)"); $this->db->query("insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights) values('filemanager', 'run', ".$accountid.", 'u', 1)",__LINE__,__FILE__);
$this->db->query("insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights) values('todo', 'run', ".$accountid.", 'u', 1)"); $this->db->query("insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights) values('calendar', 'run', ".$accountid.", 'u', 1)",__LINE__,__FILE__);
return $accountid; $this->db->query("insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights) values('email', 'run', ".$accountid.", 'u', 1)",__LINE__,__FILE__);
$this->db->query("insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights) values('notes', 'run', ".$accountid.", 'u', 1)",__LINE__,__FILE__);
$this->db->query("insert into phpgw_acl (acl_appname, acl_location, acl_account, acl_account_type, acl_rights) values('todo', 'run', ".$accountid.", 'u', 1)",__LINE__,__FILE__);
return $accountid;
} }
}//end of class } //end of class
?> ?>

View File

@ -34,16 +34,17 @@
* Standard constructor for setting $this->account_id * * Standard constructor for setting $this->account_id *
\**************************************************************************/ \**************************************************************************/
function acl($account_id = False) function acl($account_id = "")
{ {
global $phpgw, $phpgw_info; global $phpgw, $phpgw_info;
$this->db = $phpgw->db; $this->db = $phpgw->db;
if ($account_id == False){ if (! $account_id) {
$this->account_id = $phpgw_info["user"]["account_id"]; $this->account_id = $phpgw_info["user"]["account_id"];
} elseif (is_long($account_id)) { } elseif (is_long($account_id)) {
$this->account_id = $account_id; $this->account_id = $account_id;
} elseif(is_string($account_id)) { } elseif(is_string($account_id)) {
$this->account_id = $phpgw->accounts->name2id($account_id); $this->account_id = $phpgw->accounts->name2id($account_id);
} }
} }

View File

@ -27,37 +27,42 @@
class auth class auth
{ {
function authenticate($username, $passwd) { function authenticate($username, $passwd)
global $phpgw_info, $phpgw; {
global $phpgw_info, $phpgw;
$db = $phpgw->db; $db = $phpgw->db;
$local_debug = false; $db->query("SELECT * FROM phpgw_accounts WHERE account_lid = '$username' AND "
. "account_pwd='" . md5($passwd) . "' AND account_status ='A'",__LINE__,__FILE__);
if ($local_debug) { $db->next_record();
echo "<b>Debug SQL: uid - $username passwd - $passwd</b>";
}
$db->query("SELECT * FROM accounts WHERE account_lid = '$username' AND "
. "account_pwd='" . md5($passwd) . "' AND account_status ='A'",__LINE__,__FILE__);
$db->next_record();
if ($db->f("account_lid")) { if ($db->f("account_lid")) {
return True; return True;
} else { } else {
return False; return False;
} }
} }
function change_password($old_passwd, $new_passwd) { function change_password($old_passwd, $new_passwd)
global $phpgw_info, $phpgw; {
$encrypted_passwd = md5($new_passwd); global $phpgw_info, $phpgw;
$phpgw->db->query("update accounts set account_pwd='" . md5($new_passwd) . "' "
. "where account_lid='" . $phpgw_info["user"]["userid"] . "'",__LINE__,__FILE__);
$phpgw->db->query("update accounts set account_lastpwd_change='" . time() . "' where account_id='"
. $phpgw_info["user"]["account_id"] . "'",__LINE__,__FILE__);
return $encrypted_passwd; $encrypted_passwd = md5($new_passwd);
$phpgw->db->query("update phpgw_accounts set account_pwd='" . md5($new_passwd) . "' "
. "where account_lid='" . $phpgw_info["user"]["userid"] . "'",__LINE__,__FILE__);
$phpgw->db->query("update phpgw_accounts set account_lastpwd_change='" . time() . "' where account_id='"
. $phpgw_info["user"]["account_id"] . "'",__LINE__,__FILE__);
return $encrypted_passwd;
}
function update_lastlogin($account_lid, $ip)
{
global $phpgw;
$phpgw->db->query("update phpgw_accounts set account_lastloginfrom='"
. "$ip', account_lastlogin='" . time()
. "' where account_lid='$login'",__LINE__,__FILE__);
} }
} }
?> ?>

View File

@ -126,8 +126,11 @@
Header("Location: " . $this->redirect($this->link($this->db->f("config_value")."/login.php","cd=10"))); Header("Location: " . $this->redirect($this->link($this->db->f("config_value")."/login.php","cd=10")));
exit; exit;
} }
$phpgw_info["user"]["account_id"] = $this->accounts->name2id($phpgw_info["user"]["userid"]);
$this->preferences = CreateObject("phpgwapi.preferences", intval($phpgw_info["user"]["account_id"])); $this->preferences = CreateObject("phpgwapi.preferences", intval($phpgw_info["user"]["account_id"]));
$this->applications = CreateObject("phpgwapi.applications", intval($phpgw_info["user"]["account_id"])); $this->applications = CreateObject("phpgwapi.applications", intval($phpgw_info["user"]["account_id"]));
$this->acl = CreateObject("phpgwapi.acl", intval($phpgw_info["user"]["account_id"])); $this->acl = CreateObject("phpgwapi.acl", intval($phpgw_info["user"]["account_id"]));
$phpgw_info["user"]["acl"] = $this->acl->read_repository(); $phpgw_info["user"]["acl"] = $this->acl->read_repository();
$phpgw_info["user"]["preferences"] = $this->preferences->read_repository(); $phpgw_info["user"]["preferences"] = $this->preferences->read_repository();

View File

@ -59,12 +59,12 @@
$phpgw_info["user"]["account_lid"] = $db->f("session_lid"); $phpgw_info["user"]["account_lid"] = $db->f("session_lid");
$phpgw_info["user"]["sessionid"] = $sessionid; $phpgw_info["user"]["sessionid"] = $sessionid;
$phpgw_info["user"]["session_ip"] = $db->f("session_ip"); $phpgw_info["user"]["session_ip"] = $db->f("session_ip");
$t = explode("@",$db->f("session_lid")); $t = explode("@",$db->f("session_lid"));
$phpgw_info["user"]["userid"] = $t[0]; $phpgw_info["user"]["userid"] = $t[0];
$phpgw->accounts->sync(__LINE__,__FILE__); //$phpgw->accounts->sync(__LINE__,__FILE__);
// Now we need to re-read eveything // Now we need to re-read eveything
$db->query("select * from phpgw_sessions where session_id='$sessionid'",__LINE__,__FILE__); $db->query("select * from phpgw_sessions where session_id='$sessionid'",__LINE__,__FILE__);
$db->next_record(); $db->next_record();
@ -123,16 +123,22 @@
return False; return False;
} }
if (!$phpgw->auth->authenticate($phpgw_info["user"]["userid"], $passwd)) { if (! $phpgw->auth->authenticate($phpgw_info["user"]["userid"], $passwd)) {
return False; return False;
exit; exit;
} }
$accts = CreateObject("phpgwapi.accounts"); $accts = CreateObject("phpgwapi.accounts");
if (!$accts->exists($phpgw_info["user"]["userid"])) { if (!$accts->exists($phpgw_info["user"]["userid"])) {
$accts->auto_generate($phpgw_info["user"]["userid"], $passwd); $accts->auto_generate($phpgw_info["user"]["userid"], $passwd);
} }
$phpgw->accounts->account_id = $phpgw->accounts->name2id($phpgw_info["user"]["userid"]);
$phpgw->accounts->read();
$t_domain = $phpgw_info["user"]["domain"]; // We loose this info on the next line
$phpgw_info["user"] = $phpgw->accounts->read_repository();
$phpgw_info["user"]["domain"] = $t_domain;
$phpgw_info["user"]["sessionid"] = md5($phpgw->common->randomstring(10)); $phpgw_info["user"]["sessionid"] = md5($phpgw->common->randomstring(10));
$phpgw_info["user"]["kp3"] = md5($phpgw->common->randomstring(15)); $phpgw_info["user"]["kp3"] = md5($phpgw->common->randomstring(15));
@ -160,23 +166,20 @@
unset ($phpgw_info["server"]["default_domain"]); // we kill this for security reasons unset ($phpgw_info["server"]["default_domain"]); // we kill this for security reasons
} }
$phpgw->accounts->accounts_const();
$phpgw_info["user"]["session_ip"] = $this->getuser_ip(); $phpgw_info["user"]["session_ip"] = $this->getuser_ip();
$phpgw->db->query("insert into phpgw_sessions values ('" . $phpgw_info["user"]["sessionid"] $phpgw->db->query("insert into phpgw_sessions values ('" . $phpgw_info["user"]["sessionid"]
. "','".$login."','" . $this->getuser_ip() . "','" . "','".$login."','" . $this->getuser_ip() . "','"
. time() . "','" . time() . "','')",__LINE__,__FILE__); . time() . "','" . time() . "','')",__LINE__,__FILE__);
$phpgw->accounts->sync(__LINE__,__FILE__);
$phpgw->accounts->save_repository();
$phpgw->db->query("insert into phpgw_access_log values ('" . $phpgw_info["user"]["sessionid"] . "','" $phpgw->db->query("insert into phpgw_access_log values ('" . $phpgw_info["user"]["sessionid"] . "','"
. "$login','" . $this->getuser_ip() . "','" . time() . "$login','" . $this->getuser_ip() . "','" . time()
. "','') ",__LINE__,__FILE__); . "','') ",__LINE__,__FILE__);
$phpgw->db->query("update accounts set account_lastloginfrom='" $phpgw->auth->update_lastlogin($login,$this->getuser_ip());
. $this->getuser_ip() . "', account_lastlogin='" . time()
. "' where account_lid='".$login."'",__LINE__,__FILE__);
return $phpgw_info["user"]["sessionid"]; return $phpgw_info["user"]["sessionid"];
} }