Support custom user id though API, closes #115

This commit is contained in:
Dane Everitt 2016-10-06 22:36:59 -04:00
parent c347a6756c
commit 9d10c2a757
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 26 additions and 17 deletions

View file

@ -8,9 +8,12 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
### Added
* 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 setting custom `user_id` when using the API to create users.
### Changed
* 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
* 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)

View file

@ -62,8 +62,7 @@ class UserController extends BaseController
*/
public function list(Request $request)
{
$users = Models\User::paginate(50);
return $this->response->paginator($users, new UserTransformer);
return Models\User::all()->toArray();
}
/**
@ -95,7 +94,12 @@ class UserController extends BaseController
if (!$query->first()) {
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) {
throw $ex;
} catch (\Exception $ex) {
@ -113,25 +117,18 @@ class UserController extends BaseController
* @Request({
* "email": "foo@example.com",
* "password": "foopassword",
* "admin": false
* "admin": false,
* "custom_id": 123
* }, headers={"Authorization": "Bearer <token>"}),
* @Response(201),
* @Response(422, body={
* "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
* })
* @Response(422)
* })
*/
public function create(Request $request)
{
try {
$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', [
'id' => $create
]));

View file

@ -52,18 +52,22 @@ class UserRepository
*
* @param string $email
* @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
*/
public function create($email, $password = null, $admin = false)
public function create($email, $password = null, $admin = false, $token = null)
{
$validator = Validator::make([
'email' => $email,
'password' => $password,
'root_admin' => $admin
'root_admin' => $admin,
'custom_id' => $token,
], [
'email' => 'required|email|unique:users,email',
'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.
@ -78,6 +82,11 @@ class UserRepository
$user = new Models\User;
$uuid = new UuidService;
// Support for API Services
if (!is_null($token)) {
$user->id = $token;
}
$user->uuid = $uuid->generate('users', 'uuid');
$user->email = $email;
$user->password = Hash::make((is_null($password)) ? str_random(30) : $password);