diff --git a/TODO.md b/TODO.md index 59646d6..cb4fb3d 100644 --- a/TODO.md +++ b/TODO.md @@ -23,11 +23,12 @@ ### Customer - [x] Tampilan Depan Customer (banner, info, voucher, saldo, coin) - mobile page -- [ ] Register Customer (wajib data lengkap) -- [ ] Register Customer Gmail -- [ ] Login Customer -- [ ] Login Customer Gmail -- [ ] Customer Edit Profile +- [x] Register Customer (wajib data lengkap) +- [x] Register Customer Gmail +- [x] Login Customer +- [x] Login Customer Gmail +- [x] Customer Edit Profile +- [ ] Register Refferal - [ ] Customer Deposit Manual - [ ] Customer Deposit Payment Gateway - [ ] Customer Purchase Voucher diff --git a/app/Http/Controllers/Customer/AuthController.php b/app/Http/Controllers/Customer/AuthController.php index 123f1a9..2204fe3 100644 --- a/app/Http/Controllers/Customer/AuthController.php +++ b/app/Http/Controllers/Customer/AuthController.php @@ -4,8 +4,12 @@ namespace App\Http\Controllers\Customer; use App\Http\Controllers\Controller; use App\Models\Customer; +use App\Models\CustomerLevel; +use App\Models\CustomerLevelHistory; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\DB; +use Illuminate\Support\Str; use Laravel\Socialite\Facades\Socialite; use SocialiteProviders\Manager\Config; @@ -50,15 +54,24 @@ class AuthController extends Controller $user = Socialite::driver('google')->user(); $customer = Customer::where('google_id', $user->id)->first(); if ($customer == null) { + DB::beginTransaction(); + $basic = CustomerLevel::where('key', CustomerLevel::BASIC)->first(); $customer = Customer::create([ 'fullname' => $user->name, 'name' => $user->nickname, 'email' => $user->email, - 'username' => $user->id, + 'username' => Str::random(10), 'google_id' => $user->id, - 'image' => 'GOOGLE-' . $user->avatar, 'google_oauth_response' => json_encode($user), + 'customer_level_id' => $basic->id, ]); + + CustomerLevelHistory::create([ + 'customer_id' => $customer->id, + 'customer_level_id' => $basic->id, + 'date_time' => now(), + ]); + DB::commit(); } Auth::guard('customer')->loginUsingId($customer->id); @@ -82,6 +95,8 @@ class AuthController extends Controller 'password' => 'string|required|min:8|confirmed', ]); + DB::beginTransaction(); + $basic = CustomerLevel::where('key', CustomerLevel::BASIC)->first(); $customer = Customer::create([ 'fullname' => $request->fullname, 'name' => $request->name, @@ -89,7 +104,14 @@ class AuthController extends Controller 'phone' => $request->phone, 'username' => $request->username, 'password' => bcrypt($request->password), + 'customer_level_id' => $basic->id, + ]); + CustomerLevelHistory::create([ + 'customer_id' => $customer->id, + 'customer_level_id' => $basic->id, + 'date_time' => now(), ]); + DB::commit(); Auth::guard('customer')->loginUsingId($customer->id); diff --git a/app/Http/Controllers/Customer/ProfileController.php b/app/Http/Controllers/Customer/ProfileController.php index 8722c14..99e3966 100644 --- a/app/Http/Controllers/Customer/ProfileController.php +++ b/app/Http/Controllers/Customer/ProfileController.php @@ -34,7 +34,11 @@ class ProfileController extends Controller if ($request->hasFile('image')) { $file = $request->file('image'); $file->store('uploads', 'public'); - $customer->image = $file->hashName(); + $customer->image = $file->hashName('uploads'); + } + + if ($request->password != null) { + $customer->password = bcrypt($request->password); } $customer->update([ @@ -43,8 +47,11 @@ class ProfileController extends Controller 'address' => $request->address, 'phone' => $request->phone, 'username' => $request->username, - 'password' => bcrypt($request->password), 'image' => $customer->image, + 'password' => $customer->password ]); + + redirect()->route('customer.profile.show') + ->with('message', ['type' => 'success', 'message' => 'profile updateded']); } } diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index a9fb04a..07492de 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -14,8 +14,8 @@ class Authenticate extends Middleware */ protected function redirectTo($request) { - if (! $request->expectsJson()) { - return route('admin.login'); + if (!$request->expectsJson()) { + return route('customer.login'); } } } diff --git a/app/Http/Middleware/HandleInertiaCustomerRequests.php b/app/Http/Middleware/HandleInertiaCustomerRequests.php index d4ab321..9579dbd 100644 --- a/app/Http/Middleware/HandleInertiaCustomerRequests.php +++ b/app/Http/Middleware/HandleInertiaCustomerRequests.php @@ -31,7 +31,7 @@ class HandleInertiaCustomerRequests extends Middleware { return array_merge(parent::share($request), [ 'auth' => [ - 'user' => auth('customer')->user(), + 'user' => auth('customer')->user()->load(['level']), ], 'flash' => [ 'message' => fn () => $request->session()->get('message') ?? ['type' => null, 'message' => null], diff --git a/app/Models/Customer.php b/app/Models/Customer.php index 08557f3..617528b 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -39,25 +39,46 @@ class Customer extends Authenticatable protected $appends = [ 'image_url', + 'display_deposit', + 'display_coin', ]; public function imageUrl(): Attribute { return Attribute::make( get: function () { - if ($this->google_id != null) { - $image = explode('-', $this->images); - if ($image[0] == "IMAGE") { - return $image[1]; - } + if ($this->google_id != null && $this->image == null) { + $user = json_decode($this->google_oauth_response); + return $user?->avatar; } if ($this->image != null) { - return $this->asset($this->image); + return asset($this->image); } return asset('sample/avatar.svg'); } ); } + + + public function displayDeposit(): Attribute + { + return Attribute::make(get: function () { + return number_format($this->deposit_balance, 0, ',', '.'); + }); + } + + + public function displayCoin(): Attribute + { + return Attribute::make(get: function () { + return number_format($this->coin_balance, 0, ',', '.'); + }); + } + + public function level() + { + return $this->belongsTo(CustomerLevel::class, 'customer_level_id'); + } } diff --git a/config/filesystems.php b/config/filesystems.php index e9d9dbd..f676a1d 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -38,8 +38,8 @@ return [ 'public' => [ 'driver' => 'local', - 'root' => storage_path('app/public'), - 'url' => env('APP_URL').'/storage', + 'root' => base_path('public'), + 'url' => env('APP_URL') . '/upload', 'visibility' => 'public', 'throw' => false, ], diff --git a/public/uploads/4tdHUpx78fokdCMK8uZZfBO5ARXzllmhvSUv1OqF.png b/public/uploads/4tdHUpx78fokdCMK8uZZfBO5ARXzllmhvSUv1OqF.png new file mode 100644 index 0000000..b36f112 Binary files /dev/null and b/public/uploads/4tdHUpx78fokdCMK8uZZfBO5ARXzllmhvSUv1OqF.png differ diff --git a/public/uploads/SSc8CDMHsShkIUFWol8WrYSu7coHDD2rWHPXS9z7.png b/public/uploads/SSc8CDMHsShkIUFWol8WrYSu7coHDD2rWHPXS9z7.png new file mode 100644 index 0000000..b36f112 Binary files /dev/null and b/public/uploads/SSc8CDMHsShkIUFWol8WrYSu7coHDD2rWHPXS9z7.png differ diff --git a/public/uploads/XM0gJaggvM5SrW1xBLomgn0vmOkCgUbQm3DUUE1m.png b/public/uploads/XM0gJaggvM5SrW1xBLomgn0vmOkCgUbQm3DUUE1m.png new file mode 100644 index 0000000..ac64794 Binary files /dev/null and b/public/uploads/XM0gJaggvM5SrW1xBLomgn0vmOkCgUbQm3DUUE1m.png differ diff --git a/resources/js/Components/Alert.jsx b/resources/js/Components/Alert.jsx index 9d709de..8ea9705 100644 --- a/resources/js/Components/Alert.jsx +++ b/resources/js/Components/Alert.jsx @@ -20,7 +20,7 @@ export default function Alert({ type = '', children }) { if (type === 'success') { return (