[Mapbender-commits] r4112 - branches/kmq_dev/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Jun 24 05:17:15 EDT 2009
Author: kmq
Date: 2009-06-24 05:17:15 -0400 (Wed, 24 Jun 2009)
New Revision: 4112
Modified:
branches/kmq_dev/http/classes/class_user.php
Log:
class User expandend for persistence
Modified: branches/kmq_dev/http/classes/class_user.php
===================================================================
--- branches/kmq_dev/http/classes/class_user.php 2009-06-23 18:07:13 UTC (rev 4111)
+++ branches/kmq_dev/http/classes/class_user.php 2009-06-24 09:17:15 UTC (rev 4112)
@@ -28,23 +28,23 @@
*/
var $id;
var $name;
- var $password = ""; // passwords should be set, not read
- var $owner; // make this reference to a USER object
- var $descr;
+ // var $password = ""; // password is readonly,
+ var $owner = 0;
+ var $descr ="";
var $loginCount;
- var $email;
- var $phone;
- var $department;
- var $resolution;
- var $organization;
- var $position;
- var $phone1;
- var $fax;
- var $deliveryPoint;
- var $city;
+ var $email = "";
+ var $phone ="";
+ var $department ="";
+ var $resolution = 72;
+ var $organization ="";
+ var $position = "";
+ var $phone1 = "";
+ var $fax = "";
+ var $deliveryPoint ="";
+ var $city ="";
var $postalCode;
- var $country;
- var $url;
+ var $country ="";
+ var $url ="";
/**
@@ -54,8 +54,14 @@
*/
public function __construct ($userId) {
$this->id = $userId;
-
- if($userId ) {$this->load();}
+ try{
+ if($userId) {$this->load();}
+ }
+ catch(Exception $E)
+ {
+ new mb_exception($E->getMessage());
+ }
+
}
/**
@@ -73,7 +79,7 @@
{
$result = '{"name":"'. $this->name .'",'
- .'"password":"'. $this->password .'",'
+ .'"password": "*************",'
.'"owner":"'. $this->owner .'",'
.'"descr":"'. $this->descr .'",'
.'"loginCount":"'. $this->loginCount .'",'
@@ -97,22 +103,28 @@
public function create()
{
//FIXME: can users exist that have the same name? I think not, but the db does not enforce it
- if($this->name == ""){ $e = new mb_exception("Can' t create user without name");}
+ if($this->name == ""){ $e = new Exception("Can' t create user without name");}
- $sql_user_create = "INSERT INTO mb_user (mb_user_name) VALUES ($1) ; ";
+ //$sql_user_create = "INSERT INTO mb_user (mb_user_name) VALUES ($1) ; ";
+ $sql_user_create = "INSERT INTO mb_user (mb_user_name) VALUES ('". $this->name ."');";
$v = array($this->name);
$t = array("s");
db_begin();
- // $sql_user_prepared = db_prepare_query($sql_user_create,$v,$t);
- $sql_user_prepared = "INSERT INTO mb_user (mb_user_name) VALUES ('". $this->name ."') ; ";
- $result = db_query($sql_user_prepared);
- if($result == false)
+ //$insert_result = db_prep_query($sql_user_create,$v,$t);
+ $insert_result = db_query($sql_user_create);
+ if($insert_result == false)
{
db_rollback();
- $e = new mb_exception("Could not insert new user");
+ $e = new Exception("Could not insert new user");
}
+
+ $id = db_insertid($insert_result,'mb_user','mb_user_id');
+ if($id != 0)
+ {
+ $this->id = $id;
+ }
$commit_result = $this->commit();
if($commit_result == false)
@@ -122,11 +134,13 @@
}
catch(Exception $E)
{
- print "cautght it";
- $newE = new mb_exception("Could not set inital values of new user");
+ print "caught it";
+ $newE = new Exception("Could not set inital values of new user");
throw $newE;
}
}
+
+
db_commit();
@@ -134,21 +148,69 @@
public function commit()
{
- //db_begin();
- //db_commit();
+
+ $sql_update = "UPDATE mb_user SET ".
+ "mb_user_name = $1, ".
+ "mb_user_owner = $2, ".
+ "mb_user_description = $3, ".
+ "mb_user_email = $4, ".
+ "mb_user_phone = $5, ".
+ "mb_user_department = $6, ".
+ "mb_user_resolution = $7, ".
+ "mb_user_organisation_name = $8, ".
+ "mb_user_position_name = $9, ".
+ "mb_user_phone1 = $10, ".
+ "mb_user_facsimile = $11, ".
+ "mb_user_delivery_point = $12, ".
+ "mb_user_city = $13, ".
+ "mb_user_postal_code = $14, ".
+ "mb_user_country = $15, ".
+ "mb_user_online_resource = $16 ".
+ "WHERE mb_user_id = $17;";
+
+
+ $v = array($this->name,
+ $this->owner,
+ $this->description,
+ $this->email,
+ $this->phone,
+ $this->department,
+ $this->resolution,
+ $this->organization,
+ $this->position,
+ $this->phone1,
+ $this->facsimile,
+ $this->deliveryPoint,
+ $this->city,
+ $this->postalCode,
+ $this->country,
+ $this->url,
+ $this->id);
+
+ $t = array("s", "i", "s", "s", "s", "s", "i", "s", "s", "s", "s", "s", "s", "i", "s", "s", "i");
+
+ $update_result = db_prep_query($sql_update,$v,$t);
+ if(!$update_result)
+ {
+ throw new Exception("Database error updating user");
+ }
+
+ return true;
}
+
+
public function remove()
{
$sql_user_remove = "DELETE FROM mb_user WHERE mb_user_id = $1";
$v = array($this->id);
$t = array("i");
- $sql_prepared = db_prepare_query($sql_user_remove,$v,$t);
- $result = db_query($sql_prepared);
+ $result = db_prep_query($sql_user_remove,$v,$t);
+
if($result == false)
{
- $e = new mb_exception("Could not delete user");
+ $e = new mb_exception("Database error deleting userr");
}
return true;
}
@@ -162,7 +224,6 @@
if($row = db_fetch_array($res_user)){
$this->name = $row['mb_user_name'];
- $this->password = ""; // passwords should be set, not read
$this->owner = $row['mb_user_owner'];
$this->descr = $row['mb_user_description'];
$this->loginCount = $row['mb_user_login_count'];
@@ -182,10 +243,16 @@
}else{
//no such user
- echo "no such user";
+ throw new Exception("no such user");
}
return true;
}
+
+ public function setPassword($newPassword)
+ {
+ //
+ return false;
+ }
/**
* Returns an array of application IDs that the user is allowed to access.
More information about the Mapbender_commits
mailing list