mirror of
https://github.com/Pathduck/gallery3.git
synced 2026-05-11 07:19:06 -04:00
1) create common update function so processing consistent between the user edit and admin edit. 2) created common private helper function to build the user edit form the same way. So a user can now change their user name if the new one doesn't exist.
53 lines
1.7 KiB
PHP
53 lines
1.7 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 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) {
|
|
$valid = user::update($user, $form);
|
|
}
|
|
|
|
if ($valid) {
|
|
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);
|
|
}
|
|
}
|