diff --git a/app/Http/Controllers/Auth/ProfileController.php b/app/Http/Controllers/Auth/ProfileController.php index eaf7f4b..ca38cfa 100644 --- a/app/Http/Controllers/Auth/ProfileController.php +++ b/app/Http/Controllers/Auth/ProfileController.php @@ -2,16 +2,122 @@ namespace App\Http\Controllers\Auth; +use App\Helpers\AutoNumbering; use App\Http\Controllers\Controller; +use App\Models\Customer; +use Exception; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Storage; +use Intervention\Image\Drivers\Imagick\Driver; +use Intervention\Image\ImageManager; class ProfileController extends Controller { public function index(Request $request) { - if (!auth()->check()) { + if (! auth()->check()) { return redirect()->route('login'); } + return view('account.info'); } + + public function update(Request $request) + { + try { + + $request->validate([ + 'name' => 'required|string|max:255', + 'birth_date' => 'nullable|date', + 'email' => 'required|email|max:255', + 'phone' => 'required|string|max:255', + 'photo' => 'required|image|mimes:jpg,jpeg,png,webp|max:2048', + ]); + + $user = auth()->user(); + $user->name = $request->name; + $user->email = $request->email; + $user->phone = $request->phone; + + // Handle avatar upload + if ($request->hasFile('photo')) { + $ext = $request->file('photo')->extension(); + $filename = $request->file('photo')->storeAs("profile", $user->id.".".$ext, "public"); + $user->photo = $filename; + } + + $user->save(); + + $customer = $user->customer; + if ($user->customer == null) { + $customer = new Customer; + + $autoNumbering = new AutoNumbering([ + 'type' => 'CUST', + 'prefix' => 'CAPP', + 'location_id' => 0, + 'pad' => 9, + ]); + do { + $number = $autoNumbering->getCurrent(); + $count = Customer::where('number', $number)->count(); + } while ($count > 0); + + $customer->number = $number; + $customer->user_id = $user->id; + + } + + if ($request->name){ + $customer->name = $request->name; + } + + if ($request->email) { + $customer->email = $request->email; + } + + if ($request->phone) { + $customer->phone = $request->phone; + } + + if ($request->birth_date != null) { + $customer->date_of_birth = $request->birth_date; + } + + $customer->save(); + + return back()->with('success', 'Profile updated successfully!'); + } catch (Exception $e) { + Log::error($e); + return back()->with('error', $e->getMessage()); + } + } + + + public function updatePassword(Request $request) + { + try { + + $request->validate([ + 'current_password' => 'required|string', + 'password' => 'required|string|min:8|confirmed', + ]); + + $user = auth()->user(); + + // Verify current password + if (!Hash::check($request->current_password, $user->password)) { + return back()->with('error', 'Current password is incorrect.'); + } + + $user->password = bcrypt($request->password); + $user->save(); + + return back()->with('success', 'Password updated successfully!'); + } catch (Exception $e) { + return back()->with('error', $e->getMessage()); + } + } } diff --git a/app/Models/User.php b/app/Models/User.php index 22dca43..952651f 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -25,7 +25,7 @@ class User extends Authenticatable 'photo', 'fcm_token', 'phone', - 'phone_verified_at' + 'phone_verified_at', ]; /** @@ -50,4 +50,10 @@ class User extends Authenticatable 'password' => 'hashed', ]; } + + + public function customer() + { + return $this->hasOne(Customer::class); + } } diff --git a/lang/en/account_info.php b/lang/en/account_info.php new file mode 100644 index 0000000..73e8dca --- /dev/null +++ b/lang/en/account_info.php @@ -0,0 +1,39 @@ + 'Account - Personal Info', + 'personal_info' => 'Personal info', + 'basic_info' => 'Basic info', + 'edit' => 'Edit', + 'name' => 'Name', + 'date_of_birth' => 'Date of birth', + 'choose_date' => 'Choose date', + 'please_enter_first_name' => 'Please enter your first name!', + 'save_changes' => 'Save changes', + 'close' => 'Close', + 'contact' => 'Contact', + 'email_address' => 'Email address', + 'please_enter_valid_email' => 'Please enter a valid email address!', + 'phone_number' => 'Phone number', + 'please_enter_phone_number' => 'Please enter your phone number!', + 'password' => 'Password', + 'current_password' => 'Current password', + 'enter_current_password' => 'Enter your current password', + 'new_password' => 'New password', + 'create_new_password' => 'Create new password', + 'delete_account' => 'Delete account', + 'delete_account_description' => 'When you delete your account, your public profile will be deactivated immediately. If you change your mind before the 14 days are up, sign in with your email and password, and we\'ll send you a link to reactivate your account.', + 'not_set' => 'Not Set', + 'verified' => 'Verified', + 'date_format' => 'j F Y', + 'language' => 'Language', + 'select_language' => 'Select language', + 'english' => 'English', + 'french' => 'Français', + 'german' => 'Deutsch', + 'italian' => 'Italiano', + 'confirm_password' => 'Confirm password', + 'confirm_new_password' => 'Confirm new password', + 'profile_photo' => 'Profile Photo', + 'photo_requirements' => 'Recommended: Square image, at least 200x200px', +]; \ No newline at end of file diff --git a/lang/en/account_sidebar.php b/lang/en/account_sidebar.php new file mode 100644 index 0000000..89d0082 --- /dev/null +++ b/lang/en/account_sidebar.php @@ -0,0 +1,17 @@ + 'Points', + 'orders' => 'Orders', + 'wishlist' => 'Wishlist', + 'payment_methods' => 'Payment methods', + 'my_reviews' => 'My reviews', + 'manage_account' => 'Manage account', + 'personal_info' => 'Personal info', + 'addresses' => 'Addresses', + 'notifications' => 'Notifications', + 'customer_service' => 'Customer service', + 'help_center' => 'Help center', + 'terms_and_conditions' => 'Terms and conditions', + 'log_out' => 'Log out', +]; \ No newline at end of file diff --git a/lang/en/locale.php b/lang/en/locale.php new file mode 100644 index 0000000..227aac5 --- /dev/null +++ b/lang/en/locale.php @@ -0,0 +1,6 @@ + 'English', + 'id' => 'Indonesia', +]; \ No newline at end of file diff --git a/lang/id/account_info.php b/lang/id/account_info.php new file mode 100644 index 0000000..007050c --- /dev/null +++ b/lang/id/account_info.php @@ -0,0 +1,39 @@ + 'Akun - Info Pribadi', + 'personal_info' => 'Info Pribadi', + 'basic_info' => 'Info Dasar', + 'edit' => 'Edit', + 'name' => 'Nama', + 'date_of_birth' => 'Tanggal Lahir', + 'choose_date' => 'Pilih Tanggal', + 'please_enter_first_name' => 'Silakan masukkan nama depan Anda!', + 'save_changes' => 'Simpan Perubahan', + 'close' => 'Tutup', + 'contact' => 'Kontak', + 'email_address' => 'Alamat Email', + 'please_enter_valid_email' => 'Silakan masukkan alamat email yang valid!', + 'phone_number' => 'Nomor Telepon', + 'please_enter_phone_number' => 'Silakan masukkan nomor telepon Anda!', + 'password' => 'Kata Sandi', + 'current_password' => 'Kata Sandi Saat Ini', + 'enter_current_password' => 'Masukkan kata sandi saat ini', + 'new_password' => 'Kata Sandi Baru', + 'create_new_password' => 'Buat kata sandi baru', + 'delete_account' => 'Hapus Akun', + 'delete_account_description' => 'Ketika Anda menghapus akun, profil publik Anda akan dinonaktifkan segera. Jika Anda berubah pikiran sebelum 14 hari berakhir, masuk dengan email dan kata sandi Anda, dan kami akan mengirimkan tautan untuk mengaktifkan kembali akun Anda.', + 'not_set' => 'Belum Diatur', + 'verified' => 'Terverifikasi', + 'date_format' => 'j F Y', + 'language' => 'Bahasa', + 'select_language' => 'Pilih Bahasa', + 'english' => 'Inggris', + 'french' => 'Prancis', + 'german' => 'Jerman', + 'italian' => 'Italia', + 'confirm_password' => 'Konfirmasi Kata Sandi', + 'confirm_new_password' => 'Konfirmasi Kata Sandi Baru', + 'profile_photo' => 'Foto Profil', + 'photo_requirements' => 'Direkomendasikan: Gambar persegi, minimal 200x200px', +]; \ No newline at end of file diff --git a/lang/id/account_sidebar.php b/lang/id/account_sidebar.php new file mode 100644 index 0000000..b9e0ded --- /dev/null +++ b/lang/id/account_sidebar.php @@ -0,0 +1,17 @@ + 'Poin', + 'orders' => 'Pesanan', + 'wishlist' => 'Daftar Keinginan', + 'payment_methods' => 'Metode Pembayaran', + 'my_reviews' => 'Ulasan Saya', + 'manage_account' => 'Kelola Akun', + 'personal_info' => 'Info Pribadi', + 'addresses' => 'Alamat', + 'notifications' => 'Notifikasi', + 'customer_service' => 'Layanan Pelanggan', + 'help_center' => 'Pusat Bantuan', + 'terms_and_conditions' => 'Syarat dan Ketentuan', + 'log_out' => 'Keluar', +]; diff --git a/lang/id/locale.php b/lang/id/locale.php new file mode 100644 index 0000000..227aac5 --- /dev/null +++ b/lang/id/locale.php @@ -0,0 +1,6 @@ + 'English', + 'id' => 'Indonesia', +]; \ No newline at end of file diff --git a/public/img/photo-placeholder.png b/public/img/photo-placeholder.png new file mode 100644 index 0000000..2344659 Binary files /dev/null and b/public/img/photo-placeholder.png differ diff --git a/resources/views/account/info.blade.php b/resources/views/account/info.blade.php index f87b29e..a39f976 100644 --- a/resources/views/account/info.blade.php +++ b/resources/views/account/info.blade.php @@ -1,76 +1,128 @@ -@extends('layouts.account', ['title' => 'Account - Personal Info']) +@extends('layouts.account', ['title' => __('account_info.page_title')]) @section('content')
-

Personal info

+

{{ __('account_info.personal_info') }}

-
+
  • {{ auth()->user()->name }}
  • {{ auth()->user()->email }}
  • {{--
  • English
  • --}}
-
-
+ +
+ + @csrf + + @if(session('error')) + + @endif + +
+ +
+
+
+ @if(auth()->user()->photo) + {{ auth()->user()->name }} + @else + {{ auth()->user()->name }} + @endif +
+ + +
+
+

{{ __('account_info.photo_requirements') }}

+

JPG, PNG or GIF (Max 2MB)

+
+
+
+
- +
- -
Please enter your first name!
+
{{ __('account_info.please_enter_first_name') }}
- + +
+ +
{{ __('account_info.please_enter_valid_email') }}
+
+
+ +
+ +
+ +
{{ __('account_info.please_enter_phone_number') }}
+
+
+ +
+
user()->birth_date)) : '' }}" - }' - id="birthdate" placeholder="Choose date" type="text" /> + "dateFormat": "Y-m-d", + "defaultDate": "{{ auth()->user()->customer->date_of_birth != null ? date('Y-m-d', strtotime(auth()->user()->customer->date_of_birth)) : '' }}" + }' + placeholder="{{ __('account_info.choose_date') }}" type="text" />
{{--
- + -
Please enter a valid email address!
-
-
-
- -
- -
Please enter your phone number!
-
-
+
- + + type="button">{{ __('account_info.close') }}
-
+
--}} -
+ {{--
-
+
  • **************
-
-
+
+ + @csrf + @method('PUT') + + @if(session('error')) + + @endif + + @if(session('success')) + + @endif +
- +
- +
- +
- + +
+
+
+ +
+
- + + type="button">{{ __('account_info.close') }}
-
+
--}} -
-

Delete account

-

When you delete your account, your public profile will be deactivated - immediately. If you change your mind before the 14 days are up, sign in with your email and - password, and we'll send you a link to reactivate your account.

- Delete account -
+ {{--
+

{{ __('account_info.delete_account') }}

+

{{ __('account_info.delete_account_description') }}

+ {{ __('account_info.delete_account') }} +
--}}
@endsection @section('scripts') + @endsection diff --git a/resources/views/components/language-selector-sidebar.blade.php b/resources/views/components/language-selector-sidebar.blade.php index 1b05458..dd20a09 100644 --- a/resources/views/components/language-selector-sidebar.blade.php +++ b/resources/views/components/language-selector-sidebar.blade.php @@ -1,8 +1,8 @@ @@ -513,22 +525,26 @@
@@ -687,7 +706,8 @@
  • Ceiling & + href="{{ route('second', ['shop', 'catalog-electronics']) }}">Ceiling + & In-Wall Speakers
  • @@ -712,11 +732,13 @@
  • Sound Bars + href="{{ route('second', ['shop', 'catalog-electronics']) }}">Sound + Bars
  • Surround Sound + href="{{ route('second', ['shop', 'catalog-electronics']) }}">Surround + Sound Systems
  • @@ -724,7 +746,8 @@
    Home Audio + href="{{ route('second', ['shop', 'catalog-electronics']) }}">Home + Audio
    @@ -801,13 +829,15 @@
    @@ -969,7 +1007,8 @@
    By type + href="{{ route('second', ['shop', 'catalog-electronics']) }}">By + type
    @@ -1118,12 +1163,14 @@ - + --}} @@ -2219,3 +2373,26 @@ + diff --git a/routes/web.php b/routes/web.php index 3c915f4..c32a1e8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -69,4 +69,5 @@ Route::group(['prefix' => '/login/google'], function () { }); Route::get('/profile', [ProfileController::class, 'index'])->name('profile'); - +Route::post('/profile', [ProfileController::class, 'update'])->name('profile.update'); +Route::put('/profile/password', [ProfileController::class, 'updatePassword'])->name('profile.password.update');