2FAuth/app/Http/Controllers/Auth/UserController.php

51 lines
1.4 KiB
PHP
Raw Normal View History

<?php
2022-03-15 14:47:07 +01:00
namespace App\Http\Controllers\Auth;
2022-03-15 14:47:07 +01:00
use App\Http\Requests\UserUpdateRequest;
use App\Api\v1\Resources\UserResource;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use App\Exceptions\UnsupportedWithReverseProxyException;
class UserController extends Controller
{
/**
* Create a new controller instance.
*/
public function __construct()
{
$authGuard = config('auth.defaults.guard');
if ($authGuard === 'reverse-proxy-guard') {
throw new UnsupportedWithReverseProxyException();
}
}
/**
* Update the user's profile information.
*
2021-11-26 11:18:58 +01:00
* @param \App\Api\v1\Requests\UserUpdateRequest $request
* @return \App\Api\v1\Resources\UserResource
*/
public function update(UserUpdateRequest $request)
{
$user = $request->user();
$validated = $request->validated();
if (!Hash::check( $request->password, Auth::user()->password) ) {
return response()->json(['message' => __('errors.wrong_current_password')], 400);
}
if (!config('2fauth.config.isDemoApp') ) {
tap($user)->update([
'name' => $validated['name'],
'email' => $validated['email'],
]);
}
return new UserResource($user);
}
}