|
|
|
@ -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);
|
|
|
|
|
|
|
|
|
|