From 914a64b120059b8dc330a6ae2ebca8300dac16eb Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Sat, 3 Dec 2011 13:57:48 +0100 Subject: User management added to backend. --- ratatoeskr/backend.php | 217 ++++++++++++++++++++- ratatoeskr/cms_style/layout.css | 5 + .../src/systemtemplates/backend_login.html | 4 +- .../templates/src/systemtemplates/master.html | 2 +- ratatoeskr/templates/src/systemtemplates/user.html | 41 ++++ .../templates/src/systemtemplates/users.html | 89 +++++++++ ratatoeskr/translations/en.php | 29 ++- 7 files changed, 378 insertions(+), 9 deletions(-) create mode 100644 ratatoeskr/templates/src/systemtemplates/user.html create mode 100644 ratatoeskr/templates/src/systemtemplates/users.html diff --git a/ratatoeskr/backend.php b/ratatoeskr/backend.php index 0aeafc4..2efe00c 100644 --- a/ratatoeskr/backend.php +++ b/ratatoeskr/backend.php @@ -103,7 +103,7 @@ $backend_subactions = url_action_subactions(array( } catch(DoesNotExistError $e) { - unset($_SESSION["uid"]); + unset($_SESSION["ratatoeskr_uid"]); } } load_language(); @@ -127,7 +127,7 @@ $backend_subactions = url_action_subactions(array( $_SESSION["ratatoeskr_uid"] = $user->get_id(); $_SESSION["ratatoeskr_pwhash"] = $user->pwhash; $data["user"] = $user; - $ste->vars["user"] = array("name" => $user->username, "lang" => $user->language); + $ste->vars["user"] = array("id" => $user->get_id(), "name" => $user->username, "lang" => $user->language); } catch(Exception $e) { @@ -1321,7 +1321,218 @@ $backend_subactions = url_action_subactions(array( );}, $ratatoeskr_settings["languages"]); echo $ste->exectemplate("systemtemplates/settings.html"); - } + }, + "users" => url_action_subactions(array( + "_index" => function(&$data, $url_now, &$url_next) + { + global $ste, $translation, $languages, $rel_path_to_root, $ratatoeskr_settings, $textprocessors; + + $url_next = array(); + + $ste->vars["section"] = "admin"; + $ste->vars["submenu"] = "users"; + $ste->vars["pagetitle"] = $translation["menu_users_groups"]; + + /* Add a new group? */ + if(isset($_POST["new_group"])) + { + if(empty($_POST["group_name"])) + $ste->vars["error"] = $translation["empty_group_name"]; + else + { + try + { + Group::by_name($_POST["group_name"]); + $ste->vars["error"] = $translation["group_already_exists"]; + } + catch(DoesNotExistError $e) + { + $group = Group::create($_POST["group_name"]); + $ste->vars["success"] = $translation["successfully_created_group"]; + } + } + } + + /* Add a new user? */ + if(isset($_POST["new_user"])) + { + if(empty($_POST["username"])) + $ste->vars["error"] = $translation["empty_username"]; + else + { + try + { + User::by_name($_POST["username"]); + $ste->vars["error"] = $translation["user_already_exists"]; + } + catch(DoesNotExistError $e) + { + $group = User::create($_POST["username"], PasswordHash::create($_POST["initial_password"])); + $ste->vars["success"] = $translation["successfully_created_user"]; + } + } + } + + /* Delete groups? */ + if(isset($_POST["delete_groups"]) and ($_POST["really_delete"] == "yes") and (!empty($_POST["groups_multiselect"]))) + { + $deleted = 0; + foreach($_POST["groups_multiselect"] as $gid) + { + try + { + $group = Group::by_id($gid); + if($group->name == "admins") + { + $ste->vars["error"] = $translation["cannot_delete_admin_group"]; + } + else + { + $group->delete(); + ++$deleted; + } + } + catch(DoesNotExistError $e) + { + continue; + } + } + if($deleted > 0) + $ste->vars["success"] = $translation["successfully_deleted_groups"]; + } + + /* Delete users? */ + if(isset($_POST["delete_users"]) and ($_POST["really_delete"] == "yes") and (!empty($_POST["users_multiselect"]))) + { + $deleted = 0; + foreach($_POST["users_multiselect"] as $uid) + { + if($uid == $data["user"]->get_id()) + $ste->vars["error"] = $translation["cannot_delete_yourself"]; + else + { + try + { + $user = User::by_id($uid); + $user->delete(); + ++$deleted; + } + catch(DoesNotExistError $e) + { + continue; + } + } + } + if($deleted > 0) + $ste->vars["success"] = $translation["successfully_deleted_users"]; + } + + /* Get all groups */ + $ste->vars["groups"] = array_map(function($g) { return array( + "id" => $g->get_id(), + "name" => $g->name + ); }, Group::all()); + + /* Get all users */ + $ste->vars["users"] = array_map(function($u) { return array( + "id" => $u->get_id(), + "name" => $u->username, + "memberof" => array_map(function($g) { return $g->name; }, $u->get_groups()), + "fullname" => $u->fullname, + "mail" => $u->mail + ); }, User::all()); + + echo $ste->exectemplate("systemtemplates/users.html"); + }, + "u" => function(&$data, $url_now, &$url_next) + { + global $ste, $translation, $languages, $rel_path_to_root, $admin_grp; + + try + { + $user = User::by_id($url_next[0]); + } + catch(DoesNotExistError $e) + { + throw new NotFoundError(); + } + + $url_next = array(); + + $ste->vars["section"] = "admin"; + $ste->vars["submenu"] = "users"; + $ste->vars["pagetitle"] = $user->username; + + /* Modify data? */ + if(isset($_POST["change_data"])) + { + $user->fullname = $_POST["fullname"]; + $user->mail = $_POST["mail"]; + + $current_groups = array_map(function($g) { return $g->get_id(); }, $user->get_groups()); + $new_groups = empty($_POST[groups_multiselect]) ? array() : $_POST["groups_multiselect"]; + $groups_exclude = array_diff($current_groups, $new_groups); + $groups_include = array_diff($new_groups, $current_groups); + + foreach($groups_exclude as $gid) + { + try + { + $g = Group::by_id($gid); + $g->exclude_user($user); + } + catch(DoesNotExistError $e) + { + continue; + } + } + + foreach($groups_include as $gid) + { + try + { + $g = Group::by_id($gid); + $g->include_user($user); + } + catch(DoesNotExistError $e) + { + continue; + } + } + + $user->save(); + + $ste->vars["success"] = $translation["successfully_modified_user"]; + } + + /* New Password? */ + if(isset($_POST["new_password"])) + { + $pwhash = PasswordHash::create($_POST["password"]); + $user->pwhash = $pwhash; + if($user->get_id() == $data["user"]->get_id()) + $_SESSION["ratatoeskr_pwhash"] = $pwhash; + $user->save(); + + $ste->vars["success"] = $translation["successfully_set_new_password"]; + } + + /* Put data to STE */ + $ste->vars["u"] = array( + "id" => $user->get_id(), + "name" => $user->username, + "fullname" => $user->fullname, + "mail" => $user->mail + ); + $ste->vars["groups"] = array_map(function($g) use ($user) { return array( + "id" => $g->get_id(), + "name" => $g->name, + "member" => $user->member_of($g) + ); }, Group::all()); + + echo $ste->exectemplate("systemtemplates/user.html"); + } + )) )) )); diff --git a/ratatoeskr/cms_style/layout.css b/ratatoeskr/cms_style/layout.css index 766323d..a0d7e61 100644 --- a/ratatoeskr/cms_style/layout.css +++ b/ratatoeskr/cms_style/layout.css @@ -245,3 +245,8 @@ table.listtab tbody tr:hover { textarea.codeedit { font-family: monospace; } + +ul.bulletfree { + list-style: none; + padding-left: 0mm; +} diff --git a/ratatoeskr/templates/src/systemtemplates/backend_login.html b/ratatoeskr/templates/src/systemtemplates/backend_login.html index 73c2710..742dae8 100755 --- a/ratatoeskr/templates/src/systemtemplates/backend_login.html +++ b/ratatoeskr/templates/src/systemtemplates/backend_login.html @@ -22,8 +22,8 @@
-

:

-

:

+

:

+

:

diff --git a/ratatoeskr/templates/src/systemtemplates/master.html b/ratatoeskr/templates/src/systemtemplates/master.html index 99c8e35..b73f3b3 100755 --- a/ratatoeskr/templates/src/systemtemplates/master.html +++ b/ratatoeskr/templates/src/systemtemplates/master.html @@ -12,7 +12,7 @@
Ratatöskr::Noctilucent clouds (v. 0.1) - $user[name] | + $user[name] |
diff --git a/ratatoeskr/templates/src/systemtemplates/user.html b/ratatoeskr/templates/src/systemtemplates/user.html new file mode 100644 index 0000000..8bdce8b --- /dev/null +++ b/ratatoeskr/templates/src/systemtemplates/user.html @@ -0,0 +1,41 @@ +This template looks very boring/ugly, too much empty space, should be fixed some day... + + + $error + +
$error
+
+
+ $success + +
$success
+
+
+ +
+

+ :
+ +

+

+ :
+ +

+

:

+
    + +
  • + $group[name] +
  • +
    +
+

+ +

+

+ :
+ +

+

+
+
diff --git a/ratatoeskr/templates/src/systemtemplates/users.html b/ratatoeskr/templates/src/systemtemplates/users.html new file mode 100644 index 0000000..ade4f34 --- /dev/null +++ b/ratatoeskr/templates/src/systemtemplates/users.html @@ -0,0 +1,89 @@ + + + $error + +
$error
+
+
+ $success + +
$success
+
+
+ +
+
+
+

+ :
+
+ + +

+ :
+
+ :
+
+ +
+
+
+
+

+ + + + + + + + + + + + + + + +
 
$group[name]
+
+ +
+
+ +
+

+ + + + + + + + + + + + + + + + + + + + + +
 
$user_x[name] + + ?{~{$i|eq|0}||, }$group + + $user_x[fullname]$user_x[mail]
+
+ +
+
+
+
+
+
diff --git a/ratatoeskr/translations/en.php b/ratatoeskr/translations/en.php index 5c6bd5c..80b9806 100644 --- a/ratatoeskr/translations/en.php +++ b/ratatoeskr/translations/en.php @@ -1,8 +1,8 @@ "username", - "password" => "password", + "username" => "Username", + "password" => "Password", "login_form_header" => "Login", "login_form_button" => "Login", "login_background_image" => "Background image: [[FILENAME]] by [[AUTHOR]]. License: [[LICENSE]]", @@ -178,7 +178,30 @@ $translation = array( "cannot_delete_default_language" => "Can not delete default language.", "language_successfully_deleted" => "Language successfully deleted.", "successfully_set_default_language" => "Successfully set default language.", - "language_successfully_added" => "Language successfully added." + "language_successfully_added" => "Language successfully added.", + "new_user" => "New user", + "initial_password" => "Initial password", + "new_group" => "New Group", + "groupname" => "Group name", + "users" => "Users", + "groups" => "Groups", + "group" => "Group", + "member_of_groups" => "Member of these groups", + "cannot_delete_admin_group" => "Can not delete admin group.", + "successfully_deleted_groups" => "Successfully deleted groups.", + "empty_group_name" => "Can not create group: Empty group name.", + "group_already_exists" => "Group already exists.", + "successfully_created_group" => "Successfully created group.", + "empty_username" => "Can not create user: Empty username.", + "user_already_exists" => "User already exists.", + "successfully_created_user" => "Successfully created user.", + "cannot_delete_yourself" => "You can not delete yourself.", + "successfully_deleted_users" => "Successfully deleted users.", + "fullname" => "Full name", + "mail_address" => "Mail Address", + "new_password" => "New password", + "successfully_modified_user" => "Successfully modified user.", + "successfully_set_new_password" => "Successfully set new password." ); ?> -- cgit v1.2.3-70-g09d2