Skip to content

Commit bf80053

Browse files
committed
feat: add is completed flag for filling profile
1 parent aadd261 commit bf80053

File tree

7 files changed

+56
-4
lines changed

7 files changed

+56
-4
lines changed

app/Http/Controllers/AuthController.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@
1111
use Exception;
1212
use Illuminate\Http\JsonResponse;
1313
use Illuminate\Http\Request;
14+
use Illuminate\Support\Facades\Auth;
1415
use Illuminate\Support\Facades\Hash;
1516
use Illuminate\Support\Facades\Log;
1617
use Illuminate\Validation\ValidationException;
1718
use Symfony\Component\HttpFoundation\Response;
1819

1920
class AuthController extends Controller
2021
{
21-
public function __construct(protected UserService $userService, protected CreditCardService $creditCardService) {}
22+
public function __construct(protected UserService $userService, protected CreditCardService $creditCardService)
23+
{
24+
}
2225

2326
public function register(Request $request): JsonResponse
2427
{
@@ -41,7 +44,7 @@ public function register(Request $request): JsonResponse
4144
'user' => $user,
4245
], Response::HTTP_CREATED);
4346
} catch (Exception $e) {
44-
Log::error('User creation failed: '.$e->getMessage());
47+
Log::error('User creation failed: ' . $e->getMessage());
4548

4649
return response()->json([
4750
'success' => false,
@@ -57,7 +60,7 @@ public function login(LoginRequest $request): JsonResponse
5760

5861
$user = User::with(['roles:id,name'])->where('email', $credentials['email'])->first();
5962

60-
if (! $user || ! Hash::check($credentials['password'], $user->password)) {
63+
if (!$user || !Hash::check($credentials['password'], $user->password)) {
6164

6265
throw ValidationException::withMessages([
6366
'email' => ['The provided credentials are incorrect.'],
@@ -94,4 +97,11 @@ public function update(UpdateUserRequest $request, User $user): UserResource
9497
return new UserResource($this->userService->update($request->updateUser(), $user));
9598

9699
}
100+
101+
public function fillProfile(UpdateUserRequest $request)
102+
{
103+
$user = Auth::user();
104+
return new UserResource($this->userService->fillProfile($user, $request->updateUser()));
105+
106+
}
97107
}

app/Http/Controllers/GoogleAuthController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,16 @@ public function handleGoogleCallback()
3737

3838
$frontendUrl = config('app.frontend_url');
3939

40+
$profileCompleted = $authUser->profile_completed;
41+
4042
EncryptCookies::except('auth_token');
4143
EncryptCookies::except('roles');
44+
EncryptCookies::except('is_completed');
4245

43-
return redirect("{$frontendUrl}/api/login/google")->withCookie(cookie('auth_token', $token, 0, '/', null, false, true))->withCookie(cookie('roles', json_encode($roles, JSON_UNESCAPED_SLASHES), 0, '/', null, false, true));
46+
return redirect("{$frontendUrl}/api/login/google")
47+
->withCookie(cookie('auth_token', $token, 0, '/', null, false, true))
48+
->withCookie(cookie('roles', json_encode($roles, JSON_UNESCAPED_SLASHES), 0, '/', null, false, true))
49+
->withCookie(cookie('is_completed', $profileCompleted ? 'true' : 'false', 0, '/', null, false, true)); // ✅ Set cookie
4450

4551
} catch (Exception $e) {
4652
return response()->json([

app/Http/Resources/UserResource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function toArray(Request $request): array
2727
'street' => $this->street,
2828
'house_number' => $this->house_number,
2929
'roles' => $this->roles->pluck('name'), // Extracts only role names
30+
'is_completed' => $this->profile_completed,
3031
'created_at' => $this->created_at,
3132
'updated_at' => $this->updated_at,
3233
];

app/Models/User.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class User extends Authenticatable
3636
'zip_code',
3737
'street',
3838
'house_number',
39+
'profile_completed'
3940

4041
];
4142

app/Services/UserService.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@ public function update(array $data, User $user): User
2020

2121
return $user;
2222
}
23+
24+
public function fillProfile(User $user, array $data): User
25+
{
26+
$user->update(array_merge($data, ['profile_completed' => true]));
27+
return $user;
28+
}
2329
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration {
8+
/**
9+
* Run the migrations.
10+
*/
11+
public function up(): void
12+
{
13+
Schema::table('users', function (Blueprint $table) {
14+
$table->boolean('profile_completed')->default(false);
15+
});
16+
}
17+
18+
/**
19+
* Reverse the migrations.
20+
*/
21+
public function down(): void
22+
{
23+
Schema::table('users', function (Blueprint $table) {
24+
$table->dropColumn('profile_completed');
25+
});
26+
}
27+
};

routes/api/api.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Route::controller(AuthController::class)->group(function () {
1515
Route::get('user/{user}', 'show');
1616
Route::put('user/{user}', 'update');
17+
Route::put('user/profile', 'fillProfile');
1718
});
1819

1920
Route::controller(CreditCardController::class)->group(function () {

0 commit comments

Comments
 (0)