diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index eac4897..8b858ff 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -1,6 +1,7 @@ ':attribute harus diisi.', 'email' => ':attribute harus berupa email yang valid.', 'min' => 'panjang :attribute minimal :min karakter.', - ]); + ]); if ($validator->fails()) { - return response()->json([ - 'error' => true, - 'message' => Str::ucfirst($validator->errors()->first()), - 'data' => null - ]); + return redirect('user-profile') + ->withErrors($validator) + ->withInput(); } $user = User::findOrFail(Auth::user()->id); @@ -46,41 +45,51 @@ public function update_profile(Request $request) public function updatePassword(Request $request) { - $user = Auth::user(); - $request->validate([ - 'password' => 'required|confirmed|min:5', + $validator = Validator::make($request->all(), [ + 'password' => 'required|min:5|max:255', + 'new_password' => 'required|min:5|max:255', + ], [ + 'required' => ':attribute harus diisi.', + 'min' => 'panjang :attribute minimal :min karakter.', ]); - $user->password = bcrypt($request->input('new_password')); - $user->save(); + if ($validator->fails()) { + return redirect('user-profile') + ->withErrors($validator) + ->withInput(); + } - return redirect()->back()->with('success', 'Password updated successfully.'); - - // $status = Password::reset( - // $request->only('email', 'password', 'password_confirmation', 'token'), - // function ($user, $password) { - // $user->forceFill([ - // 'password' => bcrypt($password), - // 'remember_token' => Str::random(60), - // ])->save(); - // // Hapus token "remember me" setelah reset password - // $user->tokens()->delete(); - // } - // ); - - // return $status == Password::PASSWORD_RESET - // ? redirect('/login')->with(['status' => __($status)]) - // : back()->withErrors(['email' => [__($status)]]); - - // $user = Auth::user(); - - // $request->validate([ - // 'new_password' => 'required|string|min:8|confirmed', - // ]); - - // $user->password = bcrypt($request->input('new_password')); - // $user->save(); - - // return redirect()->back()->with('success', 'Password updated successfully.'); + $user = User::findOrFail(Auth::user()->id); + $user->update([ + 'password' => $request->new_password, + ]); + return redirect('user-profile')->with('success', 'Password Berhasil Diperbarui!'); } + + public function index() + { + $user = Auth::user(); + return view('user-profile', compact('user')); + } + + public function updateProfilePicture(Request $request) + { + $request->validate([ + 'profile_picture' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048', + ]); + + // Process the uploaded file and update the user's profile picture + $user = Auth::user(); + + // Store the uploaded file and update the user's profile picture + if ($request->hasFile('profile_picture')) { + $imagePath = $request->file('profile_picture')->store('profile_pictures', 'public'); + $user->profile_picture = $imagePath; + $user->save(); + } + + // Redirect back or return a response + return redirect()->route('user-profile')->with('success', 'Profile picture updated successfully.'); + } + } diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 416f11e..e993bd8 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -19,6 +19,7 @@ public function up(): void $table->timestamp('email_verified_at')->nullable(); $table->string('password'); $table->string('role'); + $table->string('profile_picture')->nullable(); $table->rememberToken(); $table->timestamps(); }); diff --git a/database/migrations/2023_12_26_053623_create_criterias_table.php b/database/migrations/2023_12_26_053623_create_criterias_table.php index d524912..2479ebc 100644 --- a/database/migrations/2023_12_26_053623_create_criterias_table.php +++ b/database/migrations/2023_12_26_053623_create_criterias_table.php @@ -15,7 +15,7 @@ public function up(): void $table->id(); $table->string('nama'); $table->string('prioritas'); - $table->string('bobot'); + $table->string('bobot')->nullable(); $table->timestamps(); }); } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index a9f4519..6335943 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -3,6 +3,9 @@ namespace Database\Seeders; // use Illuminate\Database\Console\Seeds\WithoutModelEvents; + +use App\Models\Criteria; +use App\Models\User; use Illuminate\Database\Seeder; class DatabaseSeeder extends Seeder @@ -12,11 +15,24 @@ class DatabaseSeeder extends Seeder */ public function run(): void { - // \App\Models\User::factory(10)->create(); + User::create([ + 'name' => 'Ananda Zakia Syahfitri', + 'username' => 'zakia', + 'email' => 'anandazakia7@gmail.com', + 'password' => bcrypt('12345') + ]); + + User::factory(2)->create(); + + Criteria::create([ + 'nama' => 'Minat', + 'prioritas' => '1', + ]); + + Criteria::create([ + 'nama' => 'Bakat', + 'prioritas' => '2', + ]); - // \App\Models\User::factory()->create([ - // 'name' => 'Test User', - // 'email' => 'test@example.com', - // ]); } } diff --git a/public/vendors/images/user.png b/public/vendors/images/user.png new file mode 100644 index 0000000..2b8b658 Binary files /dev/null and b/public/vendors/images/user.png differ diff --git a/resources/views/layout/navbar.blade.php b/resources/views/layout/navbar.blade.php index 70ca413..5eedba6 100644 --- a/resources/views/layout/navbar.blade.php +++ b/resources/views/layout/navbar.blade.php @@ -43,7 +43,11 @@