mirror of
https://github.com/pterodactyl/panel.git
synced 2024-11-23 01:22:30 +01:00
Support custom user id though API, closes #115
This commit is contained in:
parent
c347a6756c
commit
9d10c2a757
@ -8,9 +8,12 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
|
|||||||
### Added
|
### Added
|
||||||
* Added support for file copying through the file manager. [#127](https://github.com/Pterodactyl/Panel/issues/127)
|
* Added support for file copying through the file manager. [#127](https://github.com/Pterodactyl/Panel/issues/127)
|
||||||
* Added support for creating new files and folders directly from the right-click dropdown menu.
|
* Added support for creating new files and folders directly from the right-click dropdown menu.
|
||||||
|
* Added support for setting custom `user_id` when using the API to create users.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
* Support for sub-folders within the `getJavascript()` route for servers.
|
* Support for sub-folders within the `getJavascript()` route for servers.
|
||||||
|
* API route for [`/api/users`](https://pterodactyl.readme.io/v0.5.0/reference#users) now returns a non-paginated result set, and is a single array.
|
||||||
|
* API route for [`/api/users/:id`](https://pterodactyl.readme.io/v0.5.0/reference#single-user) now returns a single array including an array of all servers the user is set as the owner of.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
* File manager would do multiple up-down-up-down loading actions if you escaped renaming a file. Fixed the binding issue. [#122](https://github.com/Pterodactyl/Panel/issues/122)
|
* File manager would do multiple up-down-up-down loading actions if you escaped renaming a file. Fixed the binding issue. [#122](https://github.com/Pterodactyl/Panel/issues/122)
|
||||||
|
@ -62,8 +62,7 @@ class UserController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function list(Request $request)
|
public function list(Request $request)
|
||||||
{
|
{
|
||||||
$users = Models\User::paginate(50);
|
return Models\User::all()->toArray();
|
||||||
return $this->response->paginator($users, new UserTransformer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,7 +94,12 @@ class UserController extends BaseController
|
|||||||
if (!$query->first()) {
|
if (!$query->first()) {
|
||||||
throw new NotFoundHttpException('No user by that ID was found.');
|
throw new NotFoundHttpException('No user by that ID was found.');
|
||||||
}
|
}
|
||||||
return $query->first();
|
|
||||||
|
$user = $query->first();
|
||||||
|
$userArray = $user->toArray();
|
||||||
|
$userArray['servers'] = Models\Server::select('id', 'uuid', 'node', 'suspended')->where('owner', $user->id)->get();
|
||||||
|
|
||||||
|
return $userArray;
|
||||||
} catch (NotFoundHttpException $ex) {
|
} catch (NotFoundHttpException $ex) {
|
||||||
throw $ex;
|
throw $ex;
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
@ -113,25 +117,18 @@ class UserController extends BaseController
|
|||||||
* @Request({
|
* @Request({
|
||||||
* "email": "foo@example.com",
|
* "email": "foo@example.com",
|
||||||
* "password": "foopassword",
|
* "password": "foopassword",
|
||||||
* "admin": false
|
* "admin": false,
|
||||||
|
* "custom_id": 123
|
||||||
* }, headers={"Authorization": "Bearer <token>"}),
|
* }, headers={"Authorization": "Bearer <token>"}),
|
||||||
* @Response(201),
|
* @Response(201),
|
||||||
* @Response(422, body={
|
* @Response(422)
|
||||||
* "message": "A validation error occured.",
|
|
||||||
* "errors": {
|
|
||||||
* "email": {"The email field is required."},
|
|
||||||
* "password": {"The password field is required."},
|
|
||||||
* "admin": {"The admin field is required."}
|
|
||||||
* },
|
|
||||||
* "status_code": 422
|
|
||||||
* })
|
|
||||||
* })
|
* })
|
||||||
*/
|
*/
|
||||||
public function create(Request $request)
|
public function create(Request $request)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$user = new UserRepository;
|
$user = new UserRepository;
|
||||||
$create = $user->create($request->input('email'), $request->input('password'), $request->input('admin'));
|
$create = $user->create($request->input('email'), $request->input('password'), $request->input('admin'), $request->input('custom_id'));
|
||||||
return $this->response->created(route('api.users.view', [
|
return $this->response->created(route('api.users.view', [
|
||||||
'id' => $create
|
'id' => $create
|
||||||
]));
|
]));
|
||||||
|
@ -52,18 +52,22 @@ class UserRepository
|
|||||||
*
|
*
|
||||||
* @param string $email
|
* @param string $email
|
||||||
* @param string|null $password An unhashed version of the user's password.
|
* @param string|null $password An unhashed version of the user's password.
|
||||||
|
* @param bool $admin Boolean value if user should be an admin or not.
|
||||||
|
* @param int $token A custom user ID.
|
||||||
* @return bool|integer
|
* @return bool|integer
|
||||||
*/
|
*/
|
||||||
public function create($email, $password = null, $admin = false)
|
public function create($email, $password = null, $admin = false, $token = null)
|
||||||
{
|
{
|
||||||
$validator = Validator::make([
|
$validator = Validator::make([
|
||||||
'email' => $email,
|
'email' => $email,
|
||||||
'password' => $password,
|
'password' => $password,
|
||||||
'root_admin' => $admin
|
'root_admin' => $admin,
|
||||||
|
'custom_id' => $token,
|
||||||
], [
|
], [
|
||||||
'email' => 'required|email|unique:users,email',
|
'email' => 'required|email|unique:users,email',
|
||||||
'password' => 'nullable|regex:((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,})',
|
'password' => 'nullable|regex:((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,})',
|
||||||
'root_admin' => 'required|boolean'
|
'root_admin' => 'required|boolean',
|
||||||
|
'custom_id' => 'nullable|unique:users,id',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Run validator, throw catchable and displayable exception if it fails.
|
// Run validator, throw catchable and displayable exception if it fails.
|
||||||
@ -78,6 +82,11 @@ class UserRepository
|
|||||||
$user = new Models\User;
|
$user = new Models\User;
|
||||||
$uuid = new UuidService;
|
$uuid = new UuidService;
|
||||||
|
|
||||||
|
// Support for API Services
|
||||||
|
if (!is_null($token)) {
|
||||||
|
$user->id = $token;
|
||||||
|
}
|
||||||
|
|
||||||
$user->uuid = $uuid->generate('users', 'uuid');
|
$user->uuid = $uuid->generate('users', 'uuid');
|
||||||
$user->email = $email;
|
$user->email = $email;
|
||||||
$user->password = Hash::make((is_null($password)) ? str_random(30) : $password);
|
$user->password = Hash::make((is_null($password)) ? str_random(30) : $password);
|
||||||
|
Loading…
Reference in New Issue
Block a user