PATH:
home
/
lab2454c
/
.trash
/
core
/
app
/
Http
/
Controllers
<?php namespace App\Http\Controllers; use App\Lib\GoogleAuthenticator; use App\Models\AdminNotification; use App\Models\GeneralSetting; use App\Models\Order; use App\Models\Product; use App\Models\ProductReport; use App\Models\Transaction; use App\Models\WithdrawMethod; use App\Models\Withdrawal; use App\Models\Subcategory; use App\Rules\FileTypeValidate; use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; use Illuminate\Validation\Rules\Password; class UserController extends Controller { public function __construct() { $this->activeTemplate = activeTemplate(); } public function home() { $user = Auth::user(); $pageTitle = 'Dashboard'; $emptyMessage = "No data found"; $amount['deposit'] = auth()->user()->deposits()->sum('amount'); $amount['withdraw'] = auth()->user()->withdrawals()->sum('amount'); $transactions = Transaction::where('user_id', $user->id)->orderBy('id', 'DESC')->limit(8)->get(); $transactionCount = Transaction::where('user_id', $user->id)->count(); $product['all'] = Product::where('user_id', $user->id)->count(); $product['sold'] = Order::whereHas('product', function($q) use ($user){ $q->where('user_id', $user->id); })->where('status', 1)->count(); return view($this->activeTemplate . 'user.dashboard', compact('pageTitle', 'transactions', 'emptyMessage', 'user', 'amount', 'product', 'transactionCount')); } public function transactionHistory() { $pageTitle = 'Transaction History'; $emptyMessage = 'No data found'; $transactions = auth()->user()->transactions()->orderBy('id','desc')->paginate(getPaginate()); return view($this->activeTemplate.'user.transaction', compact('pageTitle', 'emptyMessage', 'transactions')); } public function profile() { $pageTitle = "Profile Setting"; $user = Auth::user(); return view($this->activeTemplate. 'user.profile_setting', compact('pageTitle','user')); } public function submitProfile(Request $request) { $user = Auth::user(); $request->validate([ 'firstname' => 'required|string|max:50', 'lastname' => 'required|string|max:50', 'mobile' => 'required|max:50|unique:users,mobile,'.$user->id, 'email' => 'required|max:50|unique:users,email,'.$user->id, 'address' => 'sometimes|required|max:80', 'state' => 'sometimes|required|max:80', 'zip' => 'sometimes|required|max:40', 'city' => 'sometimes|required|max:50', 'image' => ['image',new FileTypeValidate(['jpg','jpeg','png'])] ],[ 'firstname.required'=>'First name field is required', 'lastname.required'=>'Last name field is required' ]); $in['firstname'] = $request->firstname; $in['lastname'] = $request->lastname; $in['address'] = [ 'address' => $request->address, 'state' => $request->state, 'zip' => $request->zip, 'country' => @$user->address->country, 'city' => $request->city, ]; if ($request->hasFile('image')) { $location = imagePath()['profile']['user']['path']; $size = imagePath()['profile']['user']['size']; $filename = uploadImage($request->image, $location, $size, $user->image); $in['image'] = $filename; } $user->fill($in)->save(); $notify[] = ['success', 'Profile updated successfully.']; return back()->withNotify($notify); } public function changePassword() { $pageTitle = 'Change password'; return view($this->activeTemplate . 'user.password', compact('pageTitle')); } public function submitPassword(Request $request) { $password_validation = Password::min(6); $general = GeneralSetting::first(); if ($general->secure_password) { $password_validation = $password_validation->mixedCase()->numbers()->symbols()->uncompromised(); } $this->validate($request, [ 'current_password' => 'required', 'password' => ['required','confirmed',$password_validation] ]); try { $user = auth()->user(); if (Hash::check($request->current_password, $user->password)) { $password = Hash::make($request->password); $user->password = $password; $user->save(); $notify[] = ['success', 'Password changes successfully.']; return back()->withNotify($notify); } else { $notify[] = ['error', 'The password doesn\'t match!']; return back()->withNotify($notify); } } catch (\PDOException $e) { $notify[] = ['error', $e->getMessage()]; return back()->withNotify($notify); } } /* * Deposit History */ public function depositHistory() { $pageTitle = 'Deposit History'; $emptyMessage = 'No data found.'; $logs = auth()->user()->deposits()->with(['gateway'])->orderBy('id','desc')->paginate(getPaginate()); return view($this->activeTemplate.'user.deposit_history', compact('pageTitle', 'emptyMessage', 'logs')); } /* * Withdraw Operation */ public function withdrawMoney() { $pageTitle = 'Withdraw Money'; $withdrawMethod = WithdrawMethod::where('status',1)->get(); return view($this->activeTemplate.'user.withdraw.methods', compact('pageTitle','withdrawMethod')); } public function withdrawStore(Request $request) { $this->validate($request, [ 'method_code' => 'required', 'amount' => 'required|numeric' ]); $method = WithdrawMethod::where('id', $request->method_code)->where('status', 1)->firstOrFail(); $user = auth()->user(); if ($request->amount < $method->min_limit) { $notify[] = ['error', 'Your requested amount is smaller than minimum amount.']; return back()->withNotify($notify); } if ($request->amount > $method->max_limit) { $notify[] = ['error', 'Your requested amount is larger than maximum amount.']; return back()->withNotify($notify); } if ($request->amount > $user->balance) { $notify[] = ['error', 'You do not have sufficient balance for withdraw.']; return back()->withNotify($notify); } $charge = $method->fixed_charge + ($request->amount * $method->percent_charge / 100); $afterCharge = $request->amount - $charge; $finalAmount = $afterCharge * $method->rate; $withdraw = new Withdrawal(); $withdraw->method_id = $method->id; // wallet method ID $withdraw->user_id = $user->id; $withdraw->amount = $request->amount; $withdraw->currency = $method->currency; $withdraw->rate = $method->rate; $withdraw->charge = $charge; $withdraw->final_amount = $finalAmount; $withdraw->after_charge = $afterCharge; $withdraw->trx = getTrx(); $withdraw->save(); session()->put('wtrx', $withdraw->trx); return redirect()->route('user.withdraw.preview'); } public function withdrawPreview() { $withdraw = Withdrawal::with('method','user')->where('trx', session()->get('wtrx'))->where('status', 0)->orderBy('id','desc')->firstOrFail(); $pageTitle = 'Withdraw Preview'; return view($this->activeTemplate . 'user.withdraw.preview', compact('pageTitle','withdraw')); } public function withdrawSubmit(Request $request) { $general = GeneralSetting::first(); $withdraw = Withdrawal::with('method','user')->where('trx', session()->get('wtrx'))->where('status', 0)->orderBy('id','desc')->firstOrFail(); $rules = []; $inputField = []; if ($withdraw->method->user_data != null) { foreach ($withdraw->method->user_data as $key => $cus) { $rules[$key] = [$cus->validation]; if ($cus->type == 'file') { array_push($rules[$key], 'image'); array_push($rules[$key], new FileTypeValidate(['jpg','jpeg','png'])); array_push($rules[$key], 'max:2048'); } if ($cus->type == 'text') { array_push($rules[$key], 'max:191'); } if ($cus->type == 'textarea') { array_push($rules[$key], 'max:300'); } $inputField[] = $key; } } $this->validate($request, $rules); $user = auth()->user(); if ($user->ts) { $response = verifyG2fa($user,$request->authenticator_code); if (!$response) { $notify[] = ['error', 'Wrong verification code']; return back()->withNotify($notify); } } if ($withdraw->amount > $user->balance) { $notify[] = ['error', 'Your request amount is larger then your current balance.']; return back()->withNotify($notify); } $directory = date("Y")."/".date("m")."/".date("d"); $path = imagePath()['verify']['withdraw']['path'].'/'.$directory; $collection = collect($request); $reqField = []; if ($withdraw->method->user_data != null) { foreach ($collection as $k => $v) { foreach ($withdraw->method->user_data as $inKey => $inVal) { if ($k != $inKey) { continue; } else { if ($inVal->type == 'file') { if ($request->hasFile($inKey)) { try { $reqField[$inKey] = [ 'field_name' => $directory.'/'.uploadImage($request[$inKey], $path), 'type' => $inVal->type, ]; } catch (\Exception $exp) { $notify[] = ['error', 'Could not upload your ' . $request[$inKey]]; return back()->withNotify($notify)->withInput(); } } } else { $reqField[$inKey] = $v; $reqField[$inKey] = [ 'field_name' => $v, 'type' => $inVal->type, ]; } } } } $withdraw['withdraw_information'] = $reqField; } else { $withdraw['withdraw_information'] = null; } $withdraw->status = 2; $withdraw->save(); $user->balance -= $withdraw->amount; $user->save(); $transaction = new Transaction(); $transaction->user_id = $withdraw->user_id; $transaction->amount = $withdraw->amount; $transaction->post_balance = $user->balance; $transaction->charge = $withdraw->charge; $transaction->trx_type = '-'; $transaction->details = showAmount($withdraw->final_amount) . ' ' . $withdraw->currency . ' Withdraw Via ' . $withdraw->method->name; $transaction->trx = $withdraw->trx; $transaction->save(); $adminNotification = new AdminNotification(); $adminNotification->user_id = $user->id; $adminNotification->title = 'New withdraw request from '.$user->username; $adminNotification->click_url = urlPath('admin.withdraw.details',$withdraw->id); $adminNotification->save(); notify($user, 'WITHDRAW_REQUEST', [ 'method_name' => $withdraw->method->name, 'method_currency' => $withdraw->currency, 'method_amount' => showAmount($withdraw->final_amount), 'amount' => showAmount($withdraw->amount), 'charge' => showAmount($withdraw->charge), 'currency' => $general->cur_text, 'rate' => showAmount($withdraw->rate), 'trx' => $withdraw->trx, 'post_balance' => showAmount($user->balance), 'delay' => $withdraw->method->delay ]); $notify[] = ['success', 'Withdraw request sent successfully']; return redirect()->route('user.withdraw.history')->withNotify($notify); } public function withdrawLog() { $pageTitle = "Withdraw Log"; $emptyMessage = "No data found"; $withdraws = Withdrawal::where('user_id', Auth::id())->where('status', '!=', 0)->with('method')->orderBy('id','desc')->paginate(getPaginate()); return view($this->activeTemplate.'user.withdraw.log', compact('pageTitle','withdraws', 'emptyMessage')); } public function show2faForm() { $general = GeneralSetting::first(); $ga = new GoogleAuthenticator(); $user = auth()->user(); $secret = $ga->createSecret(); $qrCodeUrl = $ga->getQRCodeGoogleUrl($user->username . '@' . $general->sitename, $secret); $pageTitle = 'Two Factor'; return view($this->activeTemplate.'user.twofactor', compact('pageTitle', 'secret', 'qrCodeUrl')); } public function create2fa(Request $request) { $user = auth()->user(); $this->validate($request, [ 'key' => 'required', 'code' => 'required', ]); $response = verifyG2fa($user,$request->code,$request->key); if ($response) { $user->tsc = $request->key; $user->ts = 1; $user->save(); $userAgent = getIpInfo(); $osBrowser = osBrowser(); notify($user, '2FA_ENABLE', [ 'operating_system' => @$osBrowser['os_platform'], 'browser' => @$osBrowser['browser'], 'ip' => @$userAgent['ip'], 'time' => @$userAgent['time'] ]); $notify[] = ['success', 'Google authenticator enabled successfully']; return back()->withNotify($notify); } else { $notify[] = ['error', 'Wrong verification code']; return back()->withNotify($notify); } } public function disable2fa(Request $request) { $this->validate($request, [ 'code' => 'required', ]); $user = auth()->user(); $response = verifyG2fa($user,$request->code); if ($response) { $user->tsc = null; $user->ts = 0; $user->save(); $userAgent = getIpInfo(); $osBrowser = osBrowser(); notify($user, '2FA_DISABLE', [ 'operating_system' => @$osBrowser['os_platform'], 'browser' => @$osBrowser['browser'], 'ip' => @$userAgent['ip'], 'time' => @$userAgent['time'] ]); $notify[] = ['success', 'Two factor authenticator disable successfully']; } else { $notify[] = ['error', 'Wrong verification code']; } return back()->withNotify($notify); } public function report(Request $request) { $request->validate([ 'product_id' => 'required|exists:products,id', 'report' => 'required' ]); $product = Product::where('status', 1)/*->whereDate('time_duration','>', Carbon::now()->toDateTimeString())*/->firstOrFail(); $user = Auth::user(); $report = new ProductReport(); $report->user_id = $user->id; $report->product_id = $request->product_id; $report->report = $request->report; $report->save(); $notify[] = ['success', 'Report Submitted']; return back()->withNotify($notify); } public function markFavouriteTeam($team) { $team = Subcategory::find($team); $user = Auth::user(); $user->favouriteTeam()->associate($team); $user->save(); $notify[] = ['success', 'Marked as Favourite']; return back()->withNotify($notify); } public function unmarkFavouriteTeam($team) { $team = Subcategory::find($team); $user = Auth::user(); $user->favouriteTeam()->dissociate($team); $user->save(); $notify[] = ['success', 'Unmarked as Favourite']; return back()->withNotify($notify); } public function showTeamSetting() { if (auth()->user()->type !== 'TEAM') { abort(403, "You are not authorize on this area"); } $data['pageTitle'] = 'Update Team'; $data['team'] = isset(auth()->user()->subCategory) ? auth()->user()->subCategory : ''; return view('templates.basic.user.teamSetting.list', $data); } public function teamSetting(Request $request) { $team = auth()->user()->subCategory; $changed = false; $values = $request->validate([ 'social_link'=> 'required|url|max:255', 'image'=> 'image|mimes:jpeg,png,jpg,svg,gif|max:2000', ]); if ($team->social_link !== $values['social_link']) { $team->social_link = $values['social_link']; $changed = true; $team->save(); } if ($request->hasFile('image')) { $path = imagePath()['teamIcon']['path']; try { $filename = uploadImage($values['image'], $path); $team->image = $filename; $changed = true; $team->save(); } catch (\Exception $exp) { $notify[] = ['errors', 'Image could not be uploaded.']; return back()->withNotify($notify); } } if (! $changed) { $notify[] = ['warning', 'No changes done to save']; return redirect()->route('user.showTeamSetting')->withNotify($notify); } $notify[] = ['success', 'Team has been Updated']; return redirect()->route('user.showTeamSetting')->withNotify($notify); } }
[+]
..
[-] CollectionController.php
[edit]
[-] UserController.php
[edit]
[+]
Api
[+]
Gateway
[-] OrderProductController.php
[edit]
[-] ContactController.php
[edit]
[-] Controller.php
[edit]
[+]
Admin
[-] OrderController.php
[edit]
[+]
Auth
[-] ReviewController.php
[edit]
[-] PurchaseProductController.php
[edit]
[-] SiteController.php
[edit]
[-] AuthorizationController.php
[edit]
[-] FashionNftController.php
[edit]
[-] ProductController.php
[edit]
[-] ShowcaseController.php
[edit]
[-] TicketController.php
[edit]
[-] CronController.php
[edit]