* Fix api of users.

This commit is contained in:
zhujinyong
2021-12-02 15:46:24 +08:00
parent 54c761da36
commit ddcdaf4319
2 changed files with 26 additions and 4 deletions
+1 -1
View File
@@ -59,7 +59,7 @@ class buildsEntry extends entry
$control = $this->loadController('build', 'create');
$this->requireFields('execution,product,name,builder,date');
$control->create(0,0,$projectID);
$control->create(0, 0, $projectID);
$data = $this->getData();
if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
+25 -3
View File
@@ -14,7 +14,7 @@ class userEntry extends Entry
/**
* GET method.
*
* @param int $userID
* @param int|string $userID
* @access public
* @return void
*/
@@ -23,6 +23,13 @@ class userEntry extends Entry
/* Get my info defaultly. */
if(!$userID) return $this->getInfo($this->param('fields', ''));
if(!is_numeric($userID))
{
$user = $this->loadModel('user')->getById($userID, 'account');
if(!$user) return $this->send404();
$userID = $user->id;
}
/* Get user by id. */
$control = $this->loadController('user', 'profile');
$control->profile($userID);
@@ -349,17 +356,25 @@ class userEntry extends Entry
/**
* PUT method.
*
* @param int $userID
* @param int|string $userID
* @access public
* @return void
*/
public function put($userID)
{
if(!is_numeric($userID))
{
$user = $this->loadModel('user')->getById($userID, 'account');
if(!$user) return $this->send404();
$userID = $user->id;
}
$oldUser = $this->loadModel('user')->getByID($userID, 'id');
/* Set $_POST variables. */
$fields = 'dept,realname,email,commiter,gender';
$this->batchSetPost($fields, $oldUser);
$this->setPost('account', $oldUser->account);
if($this->request('gender') and !in_array($this->request('gender'), array('f', 'm'))) return $this->sendError(400, "The value of gendar must be 'f' or 'm'");
@@ -380,12 +395,19 @@ class userEntry extends Entry
/**
* DELETE method.
*
* @param int $userID
* @param int|string $userID
* @access public
* @return void
*/
public function delete($userID)
{
if(!is_numeric($userID))
{
$user = $this->loadModel('user')->getById($userID, 'account');
if(!$user) return $this->send404();
$userID = $user->id;
}
$this->setPost('verifyPassword', md5($this->app->user->password . $this->app->session->rand));
$control = $this->loadController('user', 'delete');