user classes
This commit is contained in:
parent
629e998f45
commit
3c1b20e05b
@ -30,5 +30,47 @@ _d("WH_SPLITS", 1); // int how many levels of subfolders to put in
|
||||
_d("VERSION", 'trunk'); // string shimmie version
|
||||
_d("SCORE_VERSION", 's2hack/'.VERSION); // string SCore version
|
||||
_d("TIMEZONE", null); // string timezone
|
||||
_d("EXTRA_USER_CLASSES", serialize(array())); // array extra classes that a user can be*
|
||||
|
||||
/**
|
||||
* Defining extra user classes:
|
||||
* see core/userclass.class.php for flags
|
||||
*
|
||||
* This is a kind of ugly way of doing things...
|
||||
*
|
||||
|
||||
define("EXTRA_USER_CLASSES", serialize(array(
|
||||
// a regular user, with some extra powers
|
||||
array(
|
||||
"moderator", # name for the new class
|
||||
"user", # class to base it on
|
||||
array( # parts of the base class to override
|
||||
"lock_image" => True,
|
||||
"view_ip" => True,
|
||||
"ban_ip" => True,
|
||||
"delete_image" => True,
|
||||
"delete_comment" => True,
|
||||
"manage_alias_list" => True,
|
||||
"mass_tag_edit" => True,
|
||||
"edit_image_tag" => True,
|
||||
"edit_image_source" => True,
|
||||
"edit_image_owner" => True,
|
||||
"view_image_report" => True,
|
||||
)
|
||||
),
|
||||
// an admin, minus the ability to create / remove other admins
|
||||
array(
|
||||
"manager", # name for the new class
|
||||
"admin", # class to base it on
|
||||
array( # parts of the base class to override
|
||||
"override_config" => False,
|
||||
"change_password" => False,
|
||||
"change_user_info" => False,
|
||||
"delete_user" => False,
|
||||
"manage_extension_list" => False,
|
||||
)
|
||||
),
|
||||
)));
|
||||
|
||||
*/
|
||||
?>
|
||||
|
@ -31,16 +31,14 @@ class User {
|
||||
* would be to use User::by_id, User::by_session, etc
|
||||
*/
|
||||
public function User($row) {
|
||||
global $_user_classes;
|
||||
|
||||
$this->id = int_escape($row['id']);
|
||||
$this->name = $row['name'];
|
||||
$this->email = $row['email'];
|
||||
$this->join_date = $row['joindate'];
|
||||
$this->passhash = $row['pass'];
|
||||
|
||||
global $config;
|
||||
if($row['admin'] == 'Y') $this->class = "admin";
|
||||
else if($this->id != $config->get_int('anon_id')) $this->class = "user";
|
||||
else $this->class = "anonymous";
|
||||
$this->class = $_user_classes[$row["class"]];
|
||||
}
|
||||
|
||||
public static function by_session(/*string*/ $name, /*string*/ $session) {
|
||||
@ -96,80 +94,7 @@ class User {
|
||||
* useful user object functions start here
|
||||
*/
|
||||
public function can($ability) {
|
||||
global $config;
|
||||
|
||||
// TODO: make this into an editable database table
|
||||
$user_classes = array(
|
||||
"anonymous" => array(
|
||||
"change_setting" => False, # web-level settings, eg the config table
|
||||
"override_config" => False, # sys-level config, eg config.php
|
||||
"big_search" => False, # more than 3 tags (speed mode only)
|
||||
"lock_image" => False,
|
||||
"view_ip" => False, # view IP addresses associated with things
|
||||
"ban_ip" => False,
|
||||
"change_password" => False,
|
||||
"change_user_info" => False,
|
||||
"delete_user" => False,
|
||||
"delete_image" => False,
|
||||
"delete_comment" => False,
|
||||
"replace_image" => False,
|
||||
"manage_extension_list" => False,
|
||||
"manage_alias_list" => False,
|
||||
"edit_image_tag" => $config->get_bool("tag_edit_anon"),
|
||||
"edit_image_source" => $config->get_bool("source_edit_anon"),
|
||||
"edit_image_owner" => False,
|
||||
"mass_tag_edit" => False,
|
||||
"report_image" => $config->get_bool('report_image_anon'),
|
||||
"view_image_report" => False,
|
||||
),
|
||||
"user" => array(
|
||||
"change_setting" => False,
|
||||
"override_config" => False,
|
||||
"big_search" => True,
|
||||
"lock_image" => False,
|
||||
"view_ip" => False,
|
||||
"ban_ip" => False,
|
||||
"change_password" => False,
|
||||
"change_user_info" => False,
|
||||
"delete_user" => False,
|
||||
"delete_image" => False,
|
||||
"delete_comment" => False,
|
||||
"change_image_owner" => False,
|
||||
"replace_image" => False,
|
||||
"manage_extension_list" => False,
|
||||
"manage_alias_list" => False,
|
||||
"edit_image_tag" => True,
|
||||
"edit_image_source" => True,
|
||||
"edit_image_owner" => False,
|
||||
"mass_tag_edit" => False,
|
||||
"report_image" => True,
|
||||
"view_image_report" => False,
|
||||
),
|
||||
"admin" => array(
|
||||
"change_setting" => True,
|
||||
"override_config" => True,
|
||||
"big_search" => True,
|
||||
"lock_image" => True,
|
||||
"view_ip" => True,
|
||||
"ban_ip" => True,
|
||||
"change_password" => True,
|
||||
"change_user_info" => True,
|
||||
"delete_user" => True,
|
||||
"delete_image" => True,
|
||||
"delete_comment" => True,
|
||||
"replace_image" => True,
|
||||
"manage_extension_list" => True,
|
||||
"manage_alias_list" => True,
|
||||
"edit_image_tag" => True,
|
||||
"edit_image_source" => True,
|
||||
"edit_image_owner" => True,
|
||||
"mass_tag_edit" => True,
|
||||
"report_image" => True,
|
||||
"view_image_report" => True,
|
||||
),
|
||||
);
|
||||
|
||||
return $user_classes[$this->class][$ability];
|
||||
return $this->class->can($ability);
|
||||
}
|
||||
|
||||
|
||||
@ -202,12 +127,11 @@ class User {
|
||||
return ($this->class === "admin");
|
||||
}
|
||||
|
||||
public function set_admin(/*bool*/ $admin) {
|
||||
assert(is_bool($admin));
|
||||
public function set_class(/*string*/ $class) {
|
||||
assert(is_string($class));
|
||||
global $database;
|
||||
$yn = $admin ? 'Y' : 'N';
|
||||
$database->Execute("UPDATE users SET admin=:yn WHERE id=:id", array("yn"=>$yn, "id"=>$this->id));
|
||||
log_info("core-user", 'Made '.$this->name.' admin='.$yn);
|
||||
$database->Execute("UPDATE users SET class=:class WHERE id=:id", array("class"=>$class, "id"=>$this->id));
|
||||
log_info("core-user", 'Set class for '.$this->name.' to '.$class);
|
||||
}
|
||||
|
||||
public function set_password(/*string*/ $password) {
|
||||
|
@ -62,6 +62,19 @@ class Upgrade extends Extension {
|
||||
log_info("upgrade", "Database at version 10");
|
||||
$config->set_bool("in_upgrade", false);
|
||||
}
|
||||
|
||||
if($config->get_int("db_version") < 11) {
|
||||
$config->set_bool("in_upgrade", true);
|
||||
$config->set_int("db_version", 11);
|
||||
|
||||
log_info("upgrade", "Converting user flags to classes");
|
||||
$database->execute("ALTER TABLE users ADD COLUMN class VARCHAR(32) NOT NULL default :user", array("user" => "user"));
|
||||
$database->execute("UPDATE users SET class = :name WHERE id=:id", array("name"=>"anonymous", "id"=>$config->get_int('anon_id')));
|
||||
$database->execute("UPDATE users SET class = :name WHERE admin=:admin", array("name"=>"admin", "admin"=>'Y'));
|
||||
|
||||
log_info("upgrade", "Database at version 11");
|
||||
$config->set_bool("in_upgrade", false);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_priority() {return 5;}
|
||||
|
@ -131,7 +131,7 @@ class UserPage extends Extension {
|
||||
}
|
||||
}
|
||||
else if($event->get_arg(0) == "set_more") {
|
||||
$this->set_more_wrapper($page);
|
||||
$this->set_more_wrapper();
|
||||
}
|
||||
else if($event->get_arg(0) == "list") {
|
||||
// select users.id,name,joindate,admin,
|
||||
@ -411,10 +411,8 @@ class UserPage extends Extension {
|
||||
}
|
||||
}
|
||||
|
||||
private function set_more_wrapper(Page $page) {
|
||||
global $user;
|
||||
global $config;
|
||||
global $database;
|
||||
private function set_more_wrapper() {
|
||||
global $config, $database, $page, $user;
|
||||
|
||||
$page->set_title("Error");
|
||||
$page->set_heading("Error");
|
||||
@ -427,10 +425,14 @@ class UserPage extends Extension {
|
||||
"You need to specify the account number to edit"));
|
||||
}
|
||||
else {
|
||||
$admin = (isset($_POST['admin']) && ($_POST['admin'] == "on"));
|
||||
global $_user_classes;
|
||||
$class = $_POST['class'];
|
||||
if(!array_key_exists($class, $_user_classes)) {
|
||||
throw Exception("Invalid user class: ".html_escape($class));
|
||||
}
|
||||
|
||||
$duser = User::by_id($_POST['id']);
|
||||
$duser->set_admin($admin);
|
||||
$duser->set_class($class);
|
||||
|
||||
$page->set_mode("redirect");
|
||||
if($duser->id == $user->id) {
|
||||
|
@ -179,7 +179,17 @@ class UserPageTheme extends Themelet {
|
||||
$html .= "
|
||||
<p>".make_form(make_link("user_admin/set_more"))."
|
||||
<input type='hidden' name='id' value='$i_user_id'>
|
||||
Admin: <input name='admin' type='checkbox'$h_is_admin>
|
||||
Class: <select name='class'>
|
||||
";
|
||||
global $_user_classes;
|
||||
foreach($_user_classes as $name => $values) {
|
||||
$h_name = html_escape($name);
|
||||
$h_title = html_escape(ucwords($name));
|
||||
$h_selected = ($name == $duser->class->name ? " selected" : "");
|
||||
$html .= "<option value='$h_name'$h_selected>$h_title</option>\n";
|
||||
}
|
||||
$html .= "
|
||||
</select>
|
||||
<input type='submit' value='Set'>
|
||||
</form>
|
||||
|
||||
@ -191,7 +201,8 @@ class UserPageTheme extends Themelet {
|
||||
".make_form(make_link("user_admin/delete_user_with_images"))."
|
||||
<input type='hidden' name='id' value='$i_user_id'>
|
||||
<input type='submit' value='Delete User with images' onclick='confirm(\"Delete the user with his uploaded images?\");' />
|
||||
</form>";
|
||||
</form>
|
||||
";
|
||||
}
|
||||
}
|
||||
return $html;
|
||||
|
Loading…
x
Reference in New Issue
Block a user