Files
pterodactyl-panel/app/Repositories/UserRepository.php
T

65 lines
1.4 KiB
PHP
Raw Normal View History

<?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 15:08:41 -05:00
*
* @param string $email
* @param string $password An unhashed version of the user's password.
2016-01-02 15:08:33 -05:00
* @return bool|integer
*/
2016-01-02 15:08:33 -05:00
public function create($email, $password)
{
$user = new User;
$uuid = new UuidService;
2015-12-15 15:08:41 -05:00
$user->uuid = $uuid->generate('users', 'uuid');
$user->email = $email;
$user->password = Hash::make($password);
2016-01-02 15:08:33 -05:00
return ($user->save()) ? $user->id : false;
}
2016-01-01 23:25:41 -06:00
/**
2016-01-02 15:08:33 -05:00
* Updates a user on the panel.
2016-01-01 23:25:41 -06:00
*
2016-01-02 15:08:33 -05:00
* @param integer $id
* @param array $user An array of columns and their associated values to update for the user.
2016-01-01 23:25:41 -06:00
* @return boolean
*/
2016-01-02 15:08:33 -05:00
public function update($id, array $user)
2016-01-01 23:25:41 -06:00
{
if(array_key_exists('password', $user)) {
2016-01-02 15:08:33 -05:00
$user['password'] = Hash::make($user['password']);
}
2016-01-01 23:25:41 -06:00
2016-01-02 15:08:33 -05:00
return User::find($id)->update($user);
2016-01-01 23:25:41 -06:00
}
/**
2016-01-02 15:08:33 -05:00
* Deletes a user on the panel, returns the number of records deleted.
2016-01-01 23:25:41 -06:00
*
2016-01-02 15:08:33 -05:00
* @param integer $id
* @return integer
2016-01-01 23:25:41 -06:00
*/
public function delete($id)
{
2016-01-02 15:08:33 -05:00
return User::destroy($id);
2016-01-01 23:25:41 -06:00
}
}