⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.94
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
Server Software:
Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.11
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
id
/
crm.dev-unit.com
/
app
/
Repositories
/
View File Name :
UserRepository.php
<?php namespace App\Repositories; use App\Models\Setting; use App\Models\User; use Auth; use Exception; use Hash; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; /** * Class UserRepository * * @version April 28, 2020, 11:09 am UTC */ class UserRepository extends BaseRepository { /** * @var array */ protected $fieldSearchable = [ 'name', 'email', 'phone', ]; /** * Return searchable fields * * @return array */ public function getFieldsSearchable() { return $this->fieldSearchable; } /** * Configure the Model **/ public function model() { return User::class; } /** * @param array $input * @return bool */ public function profileUpdate($input) { /** @var User $user */ $user = $this->find(Auth::id()); try { if (isset($input['image']) && ! empty($input['image'])) { $this->updateProfileImage($user, $input['image']); } $input['phone'] = preparePhoneNumber($input, 'phone'); $user->update($input); return true; } catch (Exception $e) { throw new UnprocessableEntityHttpException($e->getMessage()); } } /** * @param User $user * @param $image * @return Setting */ public function updateProfileImage($user, $image) { $user->clearMediaCollection(User::COLLECTION_PROFILE_PICTURES); $mediaId = $user->addMedia($image) ->toMediaCollection(User::COLLECTION_PROFILE_PICTURES, config('app.media_disc'))->id; return $mediaId; } /** * @param array $input * @return bool */ public function changePassword($input) { try { /** @var User $user */ $user = Auth::user(); if (! Hash::check($input['password_current'], $user->password)) { throw new UnprocessableEntityHttpException('Current password is invalid.'); } $input['password'] = Hash::make($input['password']); $user->update($input); return true; } catch (Exception $e) { throw new UnprocessableEntityHttpException($e->getMessage()); } } }