mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-10-31 05:06:51 +01:00 
			
		
		
		
	 ad1a9cd33f
			
		
	
	
		ad1a9cd33f
		
			
		
	
	
	
	
		
			
			* Fix these * Update phpstan * Transform these into their identifiers instead * Fix custom rule * License is wrong * Update these * Pint fixes * Fix this * Consolidate these * Never supported PHP 7 * Better evaluation * Fixes * Don’t need ignore * Replace trait with service * Subusers are simply the many to many relationship between Servers and Users * Adjust to remove ignores * Use new query builder instead! * wip * Update composer * Quick fixes * Use realtime facade * Small fixes * Convert to static to avoid new * Update to statics * Don’t modify protected properties directly * Run pint * Change to correct method * Give up and use the facade * Make sure this route is available * Filament hasn’t been loaded yet * This can be readonly * Typehint * These are no longer used * Quick fixes * Need doc block help * Always true * We use caddy with docker * Pint * Fix phpstan issues * Remove unused import --------- Co-authored-by: MartinOscar <40749467+RMartinOscar@users.noreply.github.com>
		
			
				
	
	
		
			76 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Http\Controllers\Api\Client;
 | |
| 
 | |
| use Illuminate\Auth\SessionGuard;
 | |
| use Illuminate\Http\Request;
 | |
| use Illuminate\Http\Response;
 | |
| use Illuminate\Auth\AuthManager;
 | |
| use Illuminate\Http\JsonResponse;
 | |
| use App\Facades\Activity;
 | |
| use App\Services\Users\UserUpdateService;
 | |
| use App\Http\Requests\Api\Client\Account\UpdateEmailRequest;
 | |
| use App\Http\Requests\Api\Client\Account\UpdatePasswordRequest;
 | |
| use App\Transformers\Api\Client\UserTransformer;
 | |
| 
 | |
| class AccountController extends ClientApiController
 | |
| {
 | |
|     /**
 | |
|      * AccountController constructor.
 | |
|      */
 | |
|     public function __construct(private AuthManager $manager, private UserUpdateService $updateService)
 | |
|     {
 | |
|         parent::__construct();
 | |
|     }
 | |
| 
 | |
|     public function index(Request $request): array
 | |
|     {
 | |
|         return $this->fractal->item($request->user())
 | |
|             ->transformWith($this->getTransformer(UserTransformer::class))
 | |
|             ->toArray();
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Update the authenticated user's email address.
 | |
|      */
 | |
|     public function updateEmail(UpdateEmailRequest $request): JsonResponse
 | |
|     {
 | |
|         $original = $request->user()->email;
 | |
|         $this->updateService->handle($request->user(), $request->validated());
 | |
| 
 | |
|         if ($original !== $request->input('email')) {
 | |
|             Activity::event('user:account.email-changed')
 | |
|                 ->property(['old' => $original, 'new' => $request->input('email')])
 | |
|                 ->log();
 | |
|         }
 | |
| 
 | |
|         return new JsonResponse([], Response::HTTP_NO_CONTENT);
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Update the authenticated user's password. All existing sessions will be logged
 | |
|      * out immediately.
 | |
|      *
 | |
|      * @throws \Throwable
 | |
|      */
 | |
|     public function updatePassword(UpdatePasswordRequest $request): JsonResponse
 | |
|     {
 | |
|         $user = $this->updateService->handle($request->user(), $request->validated());
 | |
| 
 | |
|         $guard = $this->manager->guard();
 | |
|         // If you do not update the user in the session you'll end up working with a
 | |
|         // cached copy of the user that does not include the updated password. Do this
 | |
|         // to correctly store the new user details in the guard and allow the logout
 | |
|         // other devices functionality to work.
 | |
|         $guard->setUser($user);
 | |
| 
 | |
|         if ($guard instanceof SessionGuard) {
 | |
|             $guard->logoutOtherDevices($request->input('password'));
 | |
|         }
 | |
| 
 | |
|         Activity::event('user:account.password-changed')->log();
 | |
| 
 | |
|         return new JsonResponse([], Response::HTTP_NO_CONTENT);
 | |
|     }
 | |
| }
 |