mirror of
https://github.com/Pathduck/gallery3.git
synced 2026-05-20 03:19:13 -04:00
communicate. Almost all controllers now use JSON to speak to the theme when we're dealing with form processing. This means tht we only send the form back and forth, but we use a JSON protocol to tell the browser success/error status as well as the location of any newly created resources, or where the browser should redirect the user. Lots of small changes: 1) Admin -> Edit Profile is gone. Instead I fixed the "Modify Profile" link in the top right corner to be a modal dialog 2) We use json_encode everywhere. No more Atom/XML for now. We can bring those back later, though. For now there's a lot of code duplication but that'll be easy to clean up. 3) REST_Controller is no longer abstract. All methods its subclasses should create throw exceptions, which means that subclasses don't have to implement stubs for those methods. 4) New pattern: helper method get_add_form calls take an Item_Model, not an id since we have to load the Item_Model in the controller anyway to check permissions. 5) User/Groups REST resources are separate from User/Group in the site admin. They do different things, we should avoid confusing overlap.
85 lines
2.8 KiB
PHP
85 lines
2.8 KiB
PHP
<?php defined("SYSPATH") or die("No direct script access.");
|
|
/**
|
|
* Gallery - a web based photo album viewer and editor
|
|
* Copyright (C) 2000-2008 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 Controller {
|
|
public function index() {
|
|
$view = new Admin_View("admin.html");
|
|
$view->content = new View("admin_users.html");
|
|
$view->content->users = ORM::factory("user")->orderby("name")->find_all();
|
|
$view->content->groups = ORM::factory("group")->orderby("name")->find_all();
|
|
print $view;
|
|
}
|
|
|
|
public function create() {
|
|
$form = user::get_add_form();
|
|
if ($form->validate()) {
|
|
$user = user::create($form->add_user->inputs["name"]->value,
|
|
$form->add_user->full_name->value, $form->add_user->password->value);
|
|
$user->email = $form->add_user->email->value;
|
|
$user->save();
|
|
log::add(sprintf(_("Created user %s"), $user->name));
|
|
message::add(sprintf(_("Created user %s"), $user->name));
|
|
url::redirect("admin/users");
|
|
}
|
|
|
|
print $form;
|
|
}
|
|
|
|
public function delete($id) {
|
|
$user = ORM::factory("user", $id);
|
|
if (!$user->loaded) {
|
|
kohana::show_404();
|
|
}
|
|
|
|
$form = user::get_delete_form($user);
|
|
if ($form->validate()) {
|
|
$name = $user->name;
|
|
$user->delete();
|
|
|
|
log::add(sprintf(_("Deleted user %s"), $name));
|
|
message::add(sprintf(_("Deleted user %s"), $name));
|
|
url::redirect("admin/users");
|
|
}
|
|
|
|
print $form;
|
|
}
|
|
|
|
public function edit($id) {
|
|
$user = ORM::factory("user", $id);
|
|
if (!$user->loaded) {
|
|
kohana::show_404();
|
|
}
|
|
|
|
$form = user::get_edit_form($user, "admin/users/edit/$id");
|
|
if (request::method() =="post" && $form->validate()) {
|
|
$user->name = $form->edit_user->uname->value;
|
|
$user->full_name = $form->edit_user->full_name->value;
|
|
$user->password = $form->edit_user->password->value;
|
|
$user->email = $form->edit_user->email->value;
|
|
$user->save();
|
|
message::add(sprintf(_("Changed user %s"), $user->name));
|
|
url::redirect("admin/users/edit/$id");
|
|
}
|
|
|
|
$view = new Admin_View("admin.html");
|
|
$view->content = $form;
|
|
print $view;
|
|
}
|
|
}
|