2021-10-01 13:40:37 +02:00
|
|
|
<?php
|
|
|
|
|
2021-11-07 21:57:22 +01:00
|
|
|
namespace App\Api\v1\Controllers\Auth;
|
2021-10-01 13:40:37 +02:00
|
|
|
|
2021-12-02 13:15:53 +01:00
|
|
|
use App\Models\User;
|
2021-11-07 21:57:22 +01:00
|
|
|
use App\Api\v1\Requests\UserUpdateRequest;
|
|
|
|
use App\Api\v1\Resources\UserResource;
|
2021-10-01 13:40:37 +02:00
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
|
|
|
|
class UserController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Get detailed information about a user
|
|
|
|
*
|
2021-11-26 11:18:58 +01:00
|
|
|
* @return \App\Api\v1\Resources\UserResource
|
2021-10-01 13:40:37 +02:00
|
|
|
*/
|
|
|
|
public function show()
|
|
|
|
{
|
|
|
|
$user = User::first();
|
|
|
|
|
|
|
|
return $user
|
|
|
|
? new UserResource($user)
|
|
|
|
: response()->json(['name' => null], 200);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2021-10-01 13:40:37 +02:00
|
|
|
*/
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|