2015-12-14 03:22:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Repositories;
|
|
|
|
|
|
|
|
use Hash;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\User;
|
|
|
|
use Pterodactyl\Services\UuidService;
|
|
|
|
|
|
|
|
class UserRepository
|
|
|
|
{
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a user on the panel. Returns the created user's ID.
|
2015-12-15 20:08:41 +00:00
|
|
|
*
|
2015-12-14 03:22:16 +00:00
|
|
|
* @param string $email
|
|
|
|
* @param string $password An unhashed version of the user's password.
|
2016-01-02 20:08:33 +00:00
|
|
|
* @return bool|integer
|
2015-12-14 03:22:16 +00:00
|
|
|
*/
|
2016-01-02 20:08:33 +00:00
|
|
|
public function create($email, $password)
|
2015-12-14 03:22:16 +00:00
|
|
|
{
|
|
|
|
$user = new User;
|
|
|
|
$uuid = new UuidService;
|
|
|
|
|
2015-12-15 20:08:41 +00:00
|
|
|
$user->uuid = $uuid->generate('users', 'uuid');
|
2015-12-14 03:22:16 +00:00
|
|
|
$user->email = $email;
|
|
|
|
$user->password = Hash::make($password);
|
|
|
|
|
2016-01-02 20:08:33 +00:00
|
|
|
return ($user->save()) ? $user->id : false;
|
2015-12-14 03:22:16 +00:00
|
|
|
}
|
|
|
|
|
2016-01-02 05:25:41 +00:00
|
|
|
/**
|
2016-01-02 20:08:33 +00:00
|
|
|
* Updates a user on the panel.
|
2016-01-02 05:25:41 +00:00
|
|
|
*
|
2016-01-02 20:08:33 +00:00
|
|
|
* @param integer $id
|
|
|
|
* @param array $user An array of columns and their associated values to update for the user.
|
2016-01-02 05:25:41 +00:00
|
|
|
* @return boolean
|
|
|
|
*/
|
2016-01-02 20:08:33 +00:00
|
|
|
public function update($id, array $user)
|
2016-01-02 05:25:41 +00:00
|
|
|
{
|
|
|
|
if(array_key_exists('password', $user)) {
|
2016-01-02 20:08:33 +00:00
|
|
|
$user['password'] = Hash::make($user['password']);
|
|
|
|
}
|
2016-01-02 05:25:41 +00:00
|
|
|
|
2016-01-02 20:08:33 +00:00
|
|
|
return User::find($id)->update($user);
|
2016-01-02 05:25:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-01-02 20:08:33 +00:00
|
|
|
* Deletes a user on the panel, returns the number of records deleted.
|
2016-01-02 05:25:41 +00:00
|
|
|
*
|
2016-01-02 20:08:33 +00:00
|
|
|
* @param integer $id
|
|
|
|
* @return integer
|
2016-01-02 05:25:41 +00:00
|
|
|
*/
|
|
|
|
public function delete($id)
|
|
|
|
{
|
2016-01-02 20:08:33 +00:00
|
|
|
return User::destroy($id);
|
2016-01-02 05:25:41 +00:00
|
|
|
}
|
|
|
|
|
2015-12-14 03:22:16 +00:00
|
|
|
}
|