diff options
Diffstat (limited to 'modules/gallery')
-rw-r--r-- | modules/gallery/controllers/admin_users.php | 290 | ||||
-rw-r--r-- | modules/gallery/controllers/login.php | 81 | ||||
-rw-r--r-- | modules/gallery/controllers/logout.php | 38 | ||||
-rw-r--r-- | modules/gallery/controllers/password.php | 133 | ||||
-rw-r--r-- | modules/gallery/controllers/users.php | 67 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_block.php | 23 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_event.php | 12 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_theme.php | 13 | ||||
-rw-r--r-- | modules/gallery/helpers/locales.php | 17 | ||||
-rw-r--r-- | modules/gallery/views/admin_users.html.php | 128 | ||||
-rw-r--r-- | modules/gallery/views/admin_users_group.html.php | 38 | ||||
-rw-r--r-- | modules/gallery/views/login.html.php | 22 | ||||
-rw-r--r-- | modules/gallery/views/login_ajax.html.php | 43 | ||||
-rw-r--r-- | modules/gallery/views/reset_password.html.php | 17 | ||||
-rw-r--r-- | modules/gallery/views/user_languages_block.html.php | 19 |
15 files changed, 941 insertions, 0 deletions
diff --git a/modules/gallery/controllers/admin_users.php b/modules/gallery/controllers/admin_users.php new file mode 100644 index 00000000..6c72440a --- /dev/null +++ b/modules/gallery/controllers/admin_users.php @@ -0,0 +1,290 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2009 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class Admin_Users_Controller extends Admin_Controller { + public function index() { + $view = new Admin_View("admin.html"); + $view->content = new View("admin_users.html"); + $view->content->users = user::users(array("orderby" => array("name" => "ASC"))); + $view->content->groups = group::groups(array("orderby" => array("name" => "ASC"))); + print $view; + } + + public function add_user() { + access::verify_csrf(); + + $form = user::get_add_form_admin(); + $valid = $form->validate(); + $name = $form->add_user->inputs["name"]->value; + if ($user = user::lookup_by_name($name)) { + $form->add_user->inputs["name"]->add_error("in_use", 1); + $valid = false; + } + + if ($valid) { + $user = user::create( + $name, $form->add_user->full_name->value, $form->add_user->password->value); + $user->email = $form->add_user->email->value; + $user->admin = $form->add_user->admin->checked; + + if ($form->add_user->locale) { + $desired_locale = $form->add_user->locale->value; + $user->locale = $desired_locale == "none" ? null : $desired_locale; + } + $user->save(); + module::event("user_add_form_admin_completed", $user, $form); + + message::success(t("Created user %user_name", array("user_name" => $user->name))); + print json_encode(array("result" => "success")); + } else { + print json_encode(array("result" => "error", + "form" => $form->__toString())); + } + } + + public function add_user_form() { + print user::get_add_form_admin(); + } + + public function delete_user($id) { + access::verify_csrf(); + + if ($id == user::active()->id || $id == user::guest()->id) { + access::forbidden(); + } + + $user = user::lookup($id); + if (empty($user)) { + kohana::show_404(); + } + + $form = user::get_delete_form_admin($user); + if($form->validate()) { + $name = $user->name; + $user->delete(); + } else { + print json_encode(array("result" => "error", + "form" => $form->__toString())); + } + + $message = t("Deleted user %user_name", array("user_name" => $name)); + log::success("user", $message); + message::success($message); + print json_encode(array("result" => "success")); + } + + public function delete_user_form($id) { + $user = user::lookup($id); + if (empty($user)) { + kohana::show_404(); + } + print user::get_delete_form_admin($user); + } + + public function edit_user($id) { + access::verify_csrf(); + + $user = user::lookup($id); + if (empty($user)) { + kohana::show_404(); + } + + $form = user::get_edit_form_admin($user); + $valid = $form->validate(); + if ($valid) { + $new_name = $form->edit_user->inputs["name"]->value; + $temp_user = user::lookup_by_name($new_name); + if ($new_name != $user->name && + ($temp_user && $temp_user->id != $user->id)) { + $form->edit_user->inputs["name"]->add_error("in_use", 1); + $valid = false; + } else { + $user->name = $new_name; + } + } + + if ($valid) { + $user->full_name = $form->edit_user->full_name->value; + if ($form->edit_user->password->value) { + $user->password = $form->edit_user->password->value; + } + $user->email = $form->edit_user->email->value; + $user->url = $form->edit_user->url->value; + if ($form->edit_user->locale) { + $desired_locale = $form->edit_user->locale->value; + $user->locale = $desired_locale == "none" ? null : $desired_locale; + } + + // An admin can change the admin status for any user but themselves + if ($user->id != user::active()->id) { + $user->admin = $form->edit_user->admin->checked; + } + $user->save(); + module::event("user_edit_form_admin_completed", $user, $form); + + message::success(t("Changed user %user_name", array("user_name" => $user->name))); + print json_encode(array("result" => "success")); + } else { + print json_encode(array("result" => "error", + "form" => $form->__toString())); + } + } + + public function edit_user_form($id) { + $user = user::lookup($id); + if (empty($user)) { + kohana::show_404(); + } + + $form = user::get_edit_form_admin($user); + // Don't allow the user to control their own admin bit, else you can lock yourself out + if ($user->id == user::active()->id) { + $form->edit_user->admin->disabled(1); + } + print $form; + } + + public function add_user_to_group($user_id, $group_id) { + access::verify_csrf(); + $group = group::lookup($group_id); + $user = user::lookup($user_id); + $group->add($user); + $group->save(); + } + + public function remove_user_from_group($user_id, $group_id) { + access::verify_csrf(); + $group = group::lookup($group_id); + $user = user::lookup($user_id); + $group->remove($user); + $group->save(); + } + + public function group($group_id) { + $view = new View("admin_users_group.html"); + $view->group = group::lookup($group_id); + print $view; + } + + public function add_group() { + access::verify_csrf(); + + $form = group::get_add_form_admin(); + $valid = $form->validate(); + if ($valid) { + $new_name = $form->add_group->inputs["name"]->value; + $group = group::lookup_by_name($new_name); + if (!empty($group)) { + $form->add_group->inputs["name"]->add_error("in_use", 1); + $valid = false; + } + } + + if ($valid) { + $group = group::create($new_name); + $group->save(); + message::success( + t("Created group %group_name", array("group_name" => $group->name))); + print json_encode(array("result" => "success")); + } else { + print json_encode(array("result" => "error", + "form" => $form->__toString())); + } + } + + public function add_group_form() { + print group::get_add_form_admin(); + } + + public function delete_group($id) { + access::verify_csrf(); + + $group = group::lookup($id); + if (empty($group)) { + kohana::show_404(); + } + + $form = group::get_delete_form_admin($group); + if ($form->validate()) { + $name = $group->name; + $group->delete(); + } else { + print json_encode(array("result" => "error", + "form" => $form->__toString())); + } + + $message = t("Deleted group %group_name", array("group_name" => $name)); + log::success("group", $message); + message::success($message); + print json_encode(array("result" => "success")); + } + + public function delete_group_form($id) { + $group = group::lookup($id); + if (empty($group)) { + kohana::show_404(); + } + + print group::get_delete_form_admin($group); + } + + public function edit_group($id) { + access::verify_csrf(); + + $group = group::lookup($id); + if (empty($group)) { + kohana::show_404(); + } + + $form = group::get_edit_form_admin($group); + $valid = $form->validate(); + + if ($valid) { + $new_name = $form->edit_group->inputs["name"]->value; + $group = group::lookup_by_name($name); + if ($group->loaded) { + $form->edit_group->inputs["name"]->add_error("in_use", 1); + $valid = false; + } + } + + if ($valid) { + $group->name = $form->edit_group->inputs["name"]->value; + $group->save(); + message::success( + t("Changed group %group_name", array("group_name" => $group->name))); + print json_encode(array("result" => "success")); + } else { + message::error( + t("Failed to change group %group_name", array("group_name" => $group->name))); + print json_encode(array("result" => "error", + "form" => $form->__toString())); + } + } + + public function edit_group_form($id) { + $group = group::lookup($id); + if (empty($group)) { + kohana::show_404(); + } + + print group::get_edit_form_admin($group); + } + +} diff --git a/modules/gallery/controllers/login.php b/modules/gallery/controllers/login.php new file mode 100644 index 00000000..2c4bd557 --- /dev/null +++ b/modules/gallery/controllers/login.php @@ -0,0 +1,81 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2009 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class Login_Controller extends Controller { + + public function ajax() { + $view = new View("login_ajax.html"); + $view->form = user::get_login_form("login/auth_ajax"); + print $view; + } + + public function auth_ajax() { + access::verify_csrf(); + + list ($valid, $form) = $this->_auth("login/auth_ajax"); + if ($valid) { + print json_encode( + array("result" => "success")); + } else { + print json_encode( + array("result" => "error", + "form" => $form->__toString())); + } + } + + public function html() { + print user::get_login_form("login/auth_html"); + } + + public function auth_html() { + access::verify_csrf(); + + list ($valid, $form) = $this->_auth("login/auth_html"); + if ($valid) { + url::redirect(item::root()->abs_url()); + } else { + print $form; + } + } + private function _auth($url) { + $form = user::get_login_form($url); + $valid = $form->validate(); + if ($valid) { + $user = user::lookup_by_name($form->login->inputs["name"]->value); + if (empty($user) || !user::is_correct_password($user, $form->login->password->value)) { + log::warning( + "user", + t("Failed login for %name", + array("name" => $form->login->inputs["name"]->value))); + $form->login->inputs["name"]->add_error("invalid_login", 1); + $valid = false; + } + } + + if ($valid) { + user::login($user); + log::info("user", t("User %name logged in", array("name" => $user->name))); + } + + // Either way, regenerate the session id to avoid session trapping + Session::instance()->regenerate(); + + return array($valid, $form); + } +}
\ No newline at end of file diff --git a/modules/gallery/controllers/logout.php b/modules/gallery/controllers/logout.php new file mode 100644 index 00000000..45d397ad --- /dev/null +++ b/modules/gallery/controllers/logout.php @@ -0,0 +1,38 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2009 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class Logout_Controller extends Controller { + public function index() { + //access::verify_csrf(); + + $user = user::active(); + user::logout(); + log::info("user", t("User %name logged out", array("name" => $user->name)), + html::anchor("user/$user->id", html::clean($user->name))); + if ($continue_url = $this->input->get("continue")) { + $item = url::get_item_from_uri($continue_url); + if (access::can("view", $item)) { + // Don't use url::redirect() because it'll call url::site() and munge the continue url. + header("Location: $continue_url"); + } else { + url::redirect(item::root()->abs_url()); + } + } + } +}
\ No newline at end of file diff --git a/modules/gallery/controllers/password.php b/modules/gallery/controllers/password.php new file mode 100644 index 00000000..817ff01c --- /dev/null +++ b/modules/gallery/controllers/password.php @@ -0,0 +1,133 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2009 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class Password_Controller extends Controller { + public function reset() { + if (request::method() == "post") { + // @todo separate the post from get parts of this function + access::verify_csrf(); + $this->_send_reset(); + } else { + print $this->_reset_form(); + } + } + + public function do_reset() { + if (request::method() == "post") { + $this->_change_password(); + } else { + $user = user::lookyp_by_hash(Input::instance()->get("key")); + if (!empty($user)) { + print $this->_new_password_form($user->hash); + } else { + throw new Exception("@todo FORBIDDEN", 503); + } + } + } + + private function _send_reset() { + $form = $this->_reset_form(); + + $valid = $form->validate(); + if ($valid) { + $user = user::lockup_by_name($form->reset->inputs["name"]->value); + if (!$user->loaded || empty($user->email)) { + $form->reset->inputs["name"]->add_error("no_email", 1); + $valid = false; + } + } + + if ($valid) { + $user->hash = md5(rand()); + $user->save(); + $message = new View("reset_password.html"); + $message->confirm_url = url::abs_site("password/do_reset?key=$user->hash"); + $message->user = $user; + + Sendmail::factory() + ->to($user->email) + ->subject(t("Password Reset Request")) + ->header("Mime-Version", "1.0") + ->header("Content-type", "text/html; charset=iso-8859-1") + ->message($message->render()) + ->send(); + + log::success( + "user", + t("Password reset email sent for user %name", array("name" => $user->name))); + } else { + // Don't include the username here until you're sure that it's XSS safe + log::warning( + "user", "Password reset email requested for bogus user"); + } + + message::success(t("Password reset email sent")); + print json_encode( + array("result" => "success")); + } + + private function _reset_form() { + $form = new Forge(url::current(true), "", "post", array("id" => "g-reset-form")); + $group = $form->group("reset")->label(t("Reset Password")); + $group->input("name")->label(t("Username"))->id("g-name")->class(null)->rules("required"); + $group->inputs["name"]->error_messages("no_email", t("No email, unable to reset password")); + $group->submit("")->value(t("Reset")); + + return $form; + } + + private function _new_password_form($hash=null) { + $template = new Theme_View("page.html", "reset"); + + $form = new Forge("password/do_reset", "", "post", array("id" => "g-change-password-form")); + $group = $form->group("reset")->label(t("Change Password")); + $hidden = $group->hidden("hash"); + if (!empty($hash)) { + $hidden->value($hash); + } + $group->password("password")->label(t("Password"))->id("g-password") + ->rules("required|length[1,40]"); + $group->password("password2")->label(t("Confirm Password"))->id("g-password2") + ->matches($group->password); + $group->inputs["password2"]->error_messages( + "mistyped", t("The password and the confirm password must match")); + $group->submit("")->value(t("Update")); + + $template->content = $form; + return $template; + } + + private function _change_password() { + $view = $this->_new_password_form(); + if ($view->content->validate()) { + $user = user::lookyp_by_hash(Input::instance()->get("key")); + if (empty($user)) { + throw new Exception("@todo FORBIDDEN", 503); + } + + $user->password = $view->content->reset->password->value; + $user->hash = null; + $user->save(); + message::success(t("Password reset successfully")); + url::redirect(item::root()->abs_url()); + } else { + print $view; + } + } +}
\ No newline at end of file diff --git a/modules/gallery/controllers/users.php b/modules/gallery/controllers/users.php new file mode 100644 index 00000000..4ad704f0 --- /dev/null +++ b/modules/gallery/controllers/users.php @@ -0,0 +1,67 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2009 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class Users_Controller extends REST_Controller { + protected $resource_type = "user"; + + public function _update($user) { + if ($user->guest || $user->id != user::active()->id) { + access::forbidden(); + } + + $form = user::get_edit_form($user); + $valid = $form->validate(); + if ($valid) { + $user->full_name = $form->edit_user->full_name->value; + if ($form->edit_user->password->value) { + $user->password = $form->edit_user->password->value; + } + $user->email = $form->edit_user->email->value; + $user->url = $form->edit_user->url->value; + if ($form->edit_user->locale) { + $desired_locale = $form->edit_user->locale->value; + $new_locale = $desired_locale == "none" ? null : $desired_locale; + if ($new_locale != $user->locale) { + // Delete the session based locale preference + setcookie("g_locale", "", time() - 24 * 3600, "/"); + } + $user->locale = $new_locale; + } + $user->save(); + module::event("user_edit_form_completed", $user, $form); + + message::success(t("User information updated.")); + print json_encode( + array("result" => "success", + "resource" => url::site("users/{$user->id}"))); + } else { + print json_encode( + array("result" => "error", + "form" => $form->__toString())); + } + } + + public function _form_edit($user) { + if ($user->guest || $user->id != user::active()->id) { + access::forbidden(); + } + + print user::get_edit_form($user); + } +} diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php index 5d49a9de..f43d82c9 100644 --- a/modules/gallery/helpers/gallery_block.php +++ b/modules/gallery/helpers/gallery_block.php @@ -28,6 +28,10 @@ class gallery_block_Core { "project_news" => t("Gallery Project News")); } + static function get_site_list() { + return array("language" => t("Language Preference")); + } + static function get($block_id) { $block = new Block(); switch($block_id) { @@ -85,6 +89,25 @@ class gallery_block_Core { $block->css_id = "g-block-adder"; $block->title = t("Dashboard Content"); $block->content = self::get_add_block_form(); + break; + + case "language": + $locales = locales::installed(); + if (count($locales)) { + foreach ($locales as $locale => $display_name) { + $locales[$locale] = SafeString::of_safe_html($display_name); + } + $block = new Block(); + $block->css_id = "g-user-language-block"; + $block->title = t("Language Preference"); + $block->content = new View("user_languages_block.html"); + $block->content->installed_locales = + array_merge(array("" => t("« none »")), $locales); + $block->content->selected = (string) user::cookie_locale(); + } else { + $block = ""; + } + break; } return $block; diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 290d7d12..e0de2152 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -19,6 +19,14 @@ */ class gallery_event_Core { + /** + * Initialization. + */ + static function gallery_ready() { + user::load_user(); + locales::set_request_locale(); + } + static function group_created($group) { access::add_group($group); } @@ -179,6 +187,10 @@ class gallery_event_Core { ->id("sidebar") ->label(t("Manage Sidebar")) ->url(url::site("admin/sidebar")))) + ->append(Menu::factory("link") + ->id("users_groups") + ->label(t("Users/Groups")) + ->url(url::site("admin/users"))) ->append(Menu::factory("submenu") ->id("statistics_menu") ->label(t("Statistics"))) diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php index 20dfeb04..a342b4bd 100644 --- a/modules/gallery/helpers/gallery_theme.php +++ b/modules/gallery/helpers/gallery_theme.php @@ -37,6 +37,11 @@ class gallery_theme_Core { } } + if (count(locales::installed())) { + // Needed by the languages block + $theme->script("jquery.cookie.js"); + } + if ($session->get("l10n_mode", false)) { $theme->css("l10n_client.css"); $theme->script("jquery.cookie.js"); @@ -46,6 +51,14 @@ class gallery_theme_Core { return $buf; } + static function header_top($theme) { + if ($theme->page_type != "login") { + $view = new View("login.html"); + $view->user = user::active(); + return $view->render(); + } + } + static function admin_head($theme) { $theme->script("gallery.panel.js"); $session = Session::instance(); diff --git a/modules/gallery/helpers/locales.php b/modules/gallery/helpers/locales.php index ab7f7526..faec7816 100644 --- a/modules/gallery/helpers/locales.php +++ b/modules/gallery/helpers/locales.php @@ -136,6 +136,23 @@ class locales_Core { return in_array($language, array("he", "fa", "ar")); } + static function set_request_locale() { + // 1. Check the session specific preference (cookie) + $locale = user::cookie_locale(); + // 2. Check the user's preference + if (!$locale) { + $locale = user::active()->locale; + } + // 3. Check the browser's / OS' preference + if (!$locale) { + $locale = self::locale_from_http_request(); + } + // If we have any preference, override the site's default locale + if ($locale) { + I18n::instance()->locale($locale); + } + } + /** * Returns the best match comparing the HTTP accept-language header * with the installed locales. diff --git a/modules/gallery/views/admin_users.html.php b/modules/gallery/views/admin_users.html.php new file mode 100644 index 00000000..28daff29 --- /dev/null +++ b/modules/gallery/views/admin_users.html.php @@ -0,0 +1,128 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<script type="text/javascript"> + var add_user_to_group_url = "<?= url::site("admin/users/add_user_to_group/__USERID__/__GROUPID__?csrf=$csrf") ?>"; + $(document).ready(function(){ + $("#g-user-admin-list .core-info").draggable({ + helper: "clone" + }); + $("#g-group-admin .g-group").droppable({ + accept: ".core-info", + hoverClass: "g-selected", + drop: function(ev, ui) { + var user_id = $(ui.draggable).attr("id").replace("user-", ""); + var group_id = $(this).attr("id").replace("group-", ""); + $.get(add_user_to_group_url.replace("__USERID__", user_id).replace("__GROUPID__", group_id), + {}, + function() { + reload_group(group_id); + }); + } + }); + $("#group-1").droppable("destroy"); + $("#group-2").droppable("destroy"); + }); + + var reload_group = function(group_id) { + var reload_group_url = "<?= url::site("admin/users/group/__GROUPID__") ?>"; + $.get(reload_group_url.replace("__GROUPID__", group_id), + {}, + function(data) { + $("#group-" + group_id).html(data); + $("#group-" + group_id + " .g-dialog-link").gallery_dialog(); + }); + } + + var remove_user = function(user_id, group_id) { + var remove_user_url = "<?= url::site("admin/users/remove_user_from_group/__USERID__/__GROUPID__?csrf=$csrf") ?>"; + $.get(remove_user_url.replace("__USERID__", user_id).replace("__GROUPID__", group_id), + {}, + function() { + reload_group(group_id); + }); + } +</script> +<div class="g-block"> + <a href="<?= url::site("admin/users/add_user_form") ?>" + class="g-dialog-link g-button g-right ui-icon-left ui-state-default ui-corner-all" + title="<?= t("Create a new user")->for_html_attr() ?>"> + <span class="ui-icon ui-icon-circle-plus"></span> + <?= t("Add a new user") ?> + </a> + + <h2> + <?= t("User Admin") ?> + </h2> + + <div class="g-block-content"> + <table id="g-user-admin-list"> + <tr> + <th><?= t("Username") ?></th> + <th><?= t("Full name") ?></th> + <th><?= t("Email") ?></th> + <th><?= t("Last login") ?></th> + <th><?= t("Actions") ?></th> + </tr> + + <? foreach ($users as $i => $user): ?> + <tr id="g-user-<?= $user->id ?>" class="<?= text::alternate("g-odd", "g-even") ?> user <?= $user->admin ? "admin" : "" ?>"> + <td id="user-<?= $user->id ?>" class="core-info g-draggable"> + <img src="<?= $user->avatar_url(20, $theme->url("images/avatar.jpg", true)) ?>" + title="<?= t("Drag user onto group below to add as a new member")->for_html_attr() ?>" + alt="<?= html::clean_attribute($user->name) ?>" + width="20" + height="20" /> + <?= html::clean($user->name) ?> + </td> + <td> + <?= html::clean($user->full_name) ?> + </td> + <td> + <?= html::clean($user->email) ?> + </td> + <td> + <?= ($user->last_login == 0) ? "" : gallery::date($user->last_login) ?> + </td> + <td class="g-actions"> + <a href="<?= url::site("admin/users/edit_user_form/$user->id") ?>" + open_text="<?= t("close") ?>" + class="g-panel-link g-button ui-state-default ui-corner-all ui-icon-left"> + <span class="ui-icon ui-icon-pencil"></span><span class="g-button-text"><?= t("edit") ?></span></a> + <? if (user::active()->id != $user->id && !$user->guest): ?> + <a href="<?= url::site("admin/users/delete_user_form/$user->id") ?>" + class="g-dialog-link g-button ui-state-default ui-corner-all ui-icon-left"> + <span class="ui-icon ui-icon-trash"></span><?= t("delete") ?></a> + <? else: ?> + <span title="<?= t("This user cannot be deleted")->for_html_attr() ?>" + class="g-button ui-state-disabled ui-corner-all ui-icon-left"> + <span class="ui-icon ui-icon-trash"></span><?= t("delete") ?></span> + <? endif ?> + </td> + </tr> + <? endforeach ?> + </table> + </div> +</div> + +<div id="g-group-admin" class="g-block"> + <a href="<?= url::site("admin/users/add_group_form") ?>" + class="g-dialog-link g-button g-right ui-icon-left ui-state-default ui-corner-all" + title="<?= t("Create a new group")->for_html_attr() ?>"> + <span class="ui-icon ui-icon-circle-plus"></span> + <?= t("Add a new group") ?> + </a> + + <h2> + <?= t("Group Admin") ?> + </h2> + + <div class="g-block-content"> + <ul> + <? foreach ($groups as $i => $group): ?> + <li id="group-<?= $group->id ?>" class="g-group <?= ($group->special ? "g-default-group" : "") ?>" /> + <? $v = new View("admin_users_group.html"); $v->group = $group; ?> + <?= $v ?> + </li> + <? endforeach ?> + </ul> + </div> +</div> diff --git a/modules/gallery/views/admin_users_group.html.php b/modules/gallery/views/admin_users_group.html.php new file mode 100644 index 00000000..db3645a0 --- /dev/null +++ b/modules/gallery/views/admin_users_group.html.php @@ -0,0 +1,38 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<h4> + <?= html::clean($group->name) ?> + <? if (!$group->special): ?> + <a href="<?= url::site("admin/users/delete_group_form/$group->id") ?>" + title="<?= t("Delete the %name group", array("name" => $group->name))->for_html_attr() ?>" + class="g-dialog-link g-button ui-state-default ui-corner-all"> + <span class="ui-icon ui-icon-trash"><?= t("delete") ?></span></a> + <? else: ?> + <a title="<?= t("This default group cannot be deleted")->for_html_attr() ?>" + class="g-dialog-link g-button ui-state-disabled ui-corner-all ui-icon-left"> + <span class="ui-icon ui-icon-trash"><?= t("delete") ?></span></a> + <? endif ?> +</h4> + +<? if ($group->users->count() > 0): ?> +<ul> + <? foreach ($group->users as $i => $user): ?> + <li class="g-user"> + <?= html::clean($user->name) ?> + <? if (!$group->special): ?> + <a href="javascript:remove_user(<?= $user->id ?>, <?= $group->id ?>)" + class="g-button ui-state-default ui-corner-all ui-icon-left" + title="<?= t("Remove %user from %group group", + array("user" => $user->name, "group" => $group->name))->for_html_attr() ?>"> + <span class="ui-icon ui-icon-closethick"><?= t("remove") ?></span> + </a> + <? endif ?> + </li> + <? endforeach ?> +</ul> +<? else: ?> +<div> + <p> + <?= t("Drag & drop users from the User Admin above into this group box to add group members.") ?> + </p> +</div> +<? endif ?> diff --git a/modules/gallery/views/login.html.php b/modules/gallery/views/login.html.php new file mode 100644 index 00000000..049ba043 --- /dev/null +++ b/modules/gallery/views/login.html.php @@ -0,0 +1,22 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<ul id="g-login-menu"> + <? if ($user->guest): ?> + <li class="first"> + <a href="<?= url::site("login/ajax") ?>" + title="<?= t("Login to Gallery")->for_html_attr() ?>" + id="g-login-link"><?= t("Login") ?></a> + </li> + <? else: ?> + <li class="first"> + <?= t('Logged in as %name', array('name' => html::mark_clean( + '<a href="' . url::site("form/edit/users/{$user->id}") . + '" title="' . t("Edit Your Profile")->for_html_attr() . + '" id="g-user-profile-link" class="g-dialog-link">' . + html::clean($user->display_name()) . '</a>'))) ?> + </li> + <li> + <a href="<?= url::site("logout?csrf=$csrf&continue=" . urlencode(url::current(true))) ?>" + id="g-logout-link"><?= t("Logout") ?></a> + </li> + <? endif ?> +</ul> diff --git a/modules/gallery/views/login_ajax.html.php b/modules/gallery/views/login_ajax.html.php new file mode 100644 index 00000000..d3364b46 --- /dev/null +++ b/modules/gallery/views/login_ajax.html.php @@ -0,0 +1,43 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<script type="text/javascript"> + $("#g-login-form").ready(function() { + $("#g-password-reset").click(function() { + $.ajax({ + url: "<?= url::site("password/reset") ?>", + success: function(data) { + $("#g-login").html(data); + $("#ui-dialog-title-g-dialog").html(<?= t("Reset Password")->for_js() ?>); + $(".submit").addClass("g-button ui-state-default ui-corner-all"); + $(".submit").gallery_hover_init(); + ajaxify_login_reset_form(); + } + }); + }); + }); + + function ajaxify_login_reset_form() { + $("#g-login form").ajaxForm({ + dataType: "json", + success: function(data) { + if (data.form) { + $("#g-login form").replaceWith(data.form); + ajaxify_login_reset_form(); + } + if (data.result == "success") { + $("#g-dialog").dialog("close"); + window.location.reload(); + } + } + }); + }; +</script> +<div id="g-login"> + <ul> + <li id="g-login-form"> + <?= $form ?> + </li> + <li> + <a href="#" id="g-password-reset" class="g-right g-txt-small"><?= t("Forgot Your Password?") ?></a> + </li> + </ul> +</div> diff --git a/modules/gallery/views/reset_password.html.php b/modules/gallery/views/reset_password.html.php new file mode 100644 index 00000000..92ca4917 --- /dev/null +++ b/modules/gallery/views/reset_password.html.php @@ -0,0 +1,17 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<html> + <head> + <title><?= t("Password Reset Request") ?> </title> + </head> + <body> + <h2><?= t("Password Reset Request") ?> </h2> + <p> + <?= t("Hello, %name,", array("name" => $user->full_name ? $user->full_name : $user->name)) ?> + </p> + <p> + <?= t("We received a request to reset your password for <a href=\"%site_url\">%site_url</a>. If you made this request, you can confirm it by <a href=\"%confirm_url\">clicking this link</a>. If you didn't request this password reset, it's ok to ignore this mail.", + array("site_url" => html::mark_clean(url::base(false, "http")), + "confirm_url" => $confirm_url)) ?> + </p> + </body> +</html> diff --git a/modules/gallery/views/user_languages_block.html.php b/modules/gallery/views/user_languages_block.html.php new file mode 100644 index 00000000..89185967 --- /dev/null +++ b/modules/gallery/views/user_languages_block.html.php @@ -0,0 +1,19 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<?= form::dropdown("g-select-session-locale", $installed_locales, $selected) ?> +<script type="text/javascript"> + $("#g-select-session-locale").change(function() { + var old_locale_preference = <?= html::js_string($selected) ?>; + var locale = $(this).val(); + if (old_locale_preference == locale) { + return; + } + + var expires = -1; + if (locale) { + expires = 365; + } + $.cookie("g_locale", locale, {"expires": expires, "path": "/"}); + window.location.reload(true); + }); +</script> + |