move user stuff into the user class

git-svn-id: file:///home/shish/svn/shimmie2/trunk@1004 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
shish 2008-08-23 12:49:47 +00:00
parent 434fab2dc5
commit aee1af4e0e
5 changed files with 15 additions and 38 deletions

View file

@ -374,6 +374,7 @@ class DanbooruApi implements Extension
// or makes them anonymous. Does not set any cookies or anything permanent.
private function authenticate_user()
{
global $config;
global $database;
global $user;
@ -384,12 +385,12 @@ class DanbooruApi implements Extension
$name = $_REQUEST['login'];
$pass = $_REQUEST['password'];
$hash = md5( strtolower($name) . $pass );
$duser = $database->get_user_by_name_and_hash($name, $hash);
$duser = User::by_name_and_hash($config, $database, $name, $hash);
if(!is_null($duser)) {
$user = $duser;
} else
{
$user = $database->get_user_by_id($config->get_int("anon_id", 0));
$user = User::by_id($config, $database, $config->get_int("anon_id", 0));
}
}
}

View file

@ -162,7 +162,7 @@ class IPBan implements Extension {
(strstr($row['ip'], '/') && ip_in_range($remote, $row['ip'])) ||
($row['ip'] == $remote)
) {
$admin = $database->get_user_by_id($row['banner_id']);
$admin = User::by_id($config, $database, $row['banner_id']);
$date = date("Y-m-d", $row['end_timestamp']);
print "IP <b>{$row['ip']}</b> has been banned until <b>$date</b> by <b>{$admin->name}</b> because of <b>{$row['reason']}</b>";

View file

@ -42,8 +42,9 @@ class WikiPage {
}
public function get_owner() {
global $config;
global $database;
return $database->get_user_by_id($this->owner_id);
return User::by_id($config, $database, $this->owner_id);
}
public function is_locked() {

View file

@ -502,34 +502,5 @@ class Database {
$this->execute("DELETE FROM images WHERE id=?", array($id));
}
// }}}
// users {{{
var $SELECT_USER = "SELECT *,(unix_timestamp(now()) - unix_timestamp(joindate))/(60*60*24) AS days_old FROM users ";
public function get_user_session($name, $session) {
$row = $this->db->GetRow("{$this->SELECT_USER} WHERE name LIKE ? AND md5(concat(pass, ?)) = ?",
array($name, get_session_ip(), $session));
return $row ? new User($row) : null;
}
public function get_user_by_id($id) {
assert(is_numeric($id));
$row = $this->db->GetRow("{$this->SELECT_USER} WHERE id=?", array($id));
return $row ? new User($row) : null;
}
public function get_user_by_name($name) {
assert(is_string($name));
$row = $this->db->GetRow("{$this->SELECT_USER} WHERE name=?", array($name));
return $row ? new User($row) : null;
}
public function get_user_by_name_and_hash($name, $hash) {
assert(is_string($name));
assert(is_string($hash));
assert(strlen($hash) == 32);
$row = $this->db->GetRow("{$this->SELECT_USER} WHERE name LIKE ? AND pass = ?", array($name, $hash));
return $row ? new User($row) : null;
}
// }}}
}
?>

View file

@ -99,8 +99,9 @@ class UserPage implements Extension {
}
if(($event instanceof PageRequestEvent) && ($event->page_name == "user")) {
global $user;
global $config;
global $database;
$duser = ($event->count_args() == 0) ? $user : $database->get_user_by_name($event->get_arg(0));
$duser = ($event->count_args() == 0) ? $user : User::by_name($config, $database, $event->get_arg(0));
if(!is_null($duser)) {
send_event(new UserPageBuildingEvent($event->page, $duser));
}
@ -161,8 +162,9 @@ class UserPage implements Extension {
if($event instanceof SearchTermParseEvent) {
$matches = array();
if(preg_match("/(poster|user)=(.*)/i", $event->term, $matches)) {
global $config;
global $database;
$user = $database->get_user_by_name($matches[2]);
$user = User::by_name($config, $database, $matches[2]);
if(!is_null($user)) {
$user_id = $user->id;
}
@ -188,7 +190,7 @@ class UserPage implements Extension {
$pass = $_POST['pass'];
$hash = md5(strtolower($name) . $pass);
$duser = $database->get_user_by_name_and_hash($name, $hash);
$duser = User::by_name_and_hash($config, $database, $name, $hash);
if(!is_null($duser)) {
$user = $duser;
$this->set_login_cookie($name, $pass);
@ -246,6 +248,7 @@ class UserPage implements Extension {
// Things done *to* the user {{{
private function change_password_wrapper($page) {
global $user;
global $config;
global $database;
$page->set_title("Error");
@ -261,7 +264,7 @@ class UserPage implements Extension {
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
$duser = $database->get_user_by_id($id);
$duser = User::by_id($config, $database, $id);
if((!$user->is_admin()) && ($duser->name != $user->name)) {
$page->add_block(new Block("Error",
@ -291,6 +294,7 @@ class UserPage implements Extension {
private function set_more_wrapper($page) {
global $user;
global $config;
global $database;
$page->set_title("Error");
@ -306,7 +310,7 @@ class UserPage implements Extension {
else {
$admin = (isset($_POST['admin']) && ($_POST['admin'] == "on"));
$duser = $database->get_user_by_id($_POST['id']);
$duser = User::by_id($config, $database, $_POST['id']);
$duser->set_admin($admin);
$page->set_mode("redirect");