public function passportDecline($id, $log) { $user = User::findOrFail($id); $profile = $user->profile; $profile->confirmed_passport = false; $profile->passport = null; $profile->save(); $log = Log::findOrFail($log); LogMapper::reviewed($log); return Redirect::back(); }
public function streamer($bannerStreamId) { $bannerStream = BannerStream::findOrFail($bannerStreamId); $banner = $bannerStream->banner; $stream = $bannerStream->stream; $client = $banner->client; StreamMapper::pay($client, $banner, $stream); LogMapper::log('banner_paid', $banner->id, $stream->id); LogMapper::log('decline_resolve', $banner->id, $stream->id, ['resolution' => 'streamer wins']); NotificationMapper::bannerPayAccept($banner, $stream, $bannerStream->amount); return redirect('/admin/decline')->with(['success' => 'You accepted streamer\'s point of view']); }
public function declineSave($withdrawId, Request $request) { $rules = ['comment' => 'required|min:5|max:255']; $this->validate($request, $rules); $withdrawal = Withdrawal::findOrFail($withdrawId); $withdrawal->admin_id = $this->user->id; $withdrawal->admin_comment = $request->get('comment'); $withdrawal->status = 'declined'; $user = $withdrawal->user; $user->balance_blocked = $user->balance_blocked - $withdrawal->amount; if ($user->balance_blocked < 0) { $user->balance_blocked = 0; } $withdrawal->save(); $user->save(); NotificationMapper::withdrawDecline($withdrawal); LogMapper::log('withdraw_decline', $withdrawal->id, $withdrawal->amount, $withdrawal->toArray()); return redirect('/admin/withdraw/' . $withdrawal->id . '/show')->with(['success' => 'Withdraw declined']); }
public function complainDeclineSave($streamId, $bannerId, Request $request) { $stream = Stream::findOrFail($streamId); $banner = Banner::findOrFail($bannerId); if ($stream->user_id != $this->user->id) { return Redirect::to('/user/twitcher/streams')->withErrors('You have no rights for this'); } $pivot = StreamMapper::getPivot($banner, $stream); if ($pivot->status != 'declining') { return Redirect::to('/user/twitcher/stream/' . $stream->id)->withErrors('Stream is not declining'); } $this->validate($request, ['comment' => 'required|min:5']); $comment = $request->get('comment'); $pivot->status = 'complain'; $pivot->twitcher_comment = $comment; $pivot->save(); LogMapper::log('banner_complained', $banner->id, $stream->id); NotificationMapper::bannerPayComplained($banner, $stream, $pivot->amount); return Redirect::to('/user/twitcher/stream/' . $stream->id)->with(['success' => 'You complained about banner declined']); }
public function addBanners($limit = 2000) { $clients = User::whereType('client')->get(); $twitchers = User::whereType('twitcher')->get(); $bannerTypes = $this->data['bannerTypes']; $faker = $this->faker; $i = 0; foreach ($clients as $c) { try { $bannerCounts = rand(0, 4); if ($i > $limit) { //continue; } for ($i = 0; $i < $bannerCounts; $i++) { $bannerType = $bannerTypes->random(); $twitcher = $twitchers->random(); if (BannerMapper::twitcherFree($twitcher, $bannerType->id)) { $limit = rand(0, $c->balance); if ($limit > 0) { $requiredSizes = explode('*', $bannerType->title); $w = $requiredSizes[0]; $h = $requiredSizes[1]; $file = $faker->imageUrl($w, $h); $banner = BannerMapper::addForTwitcher($twitcher, $c, $bannerType, $file, $limit); NotificationMapper::bannerAdd($banner); LogMapper::log('banner_add', $banner->id); $accept = rand(0, 10); $i++; if ($accept != 0) { BannerMapper::acceptBanner($banner); } else { BannerMapper::declineBanner($banner); } } } } } catch (\Exception $e) { dd($e->getTraceAsString()); } } }
public function stream($userId) { $user = User::findOrFail($userId); $banners = BannerMapper::activeTwitcher($user); if (count($banners) == 0) { echo 'no banners'; die; } $faker = FakerFactory::create(); $streamDate = \Carbon\Carbon::createFromTimestamp($faker->dateTimeBetween($user->created_at)->getTimestamp()); $stream = Stream::create(['user_id' => $user->id, 'time_start' => $streamDate]); BannerMapper::bannersToStream($stream, $banners); LogMapper::log('stream_start', $stream->id); foreach ($banners as $b) { NotificationMapper::bannerStream($b, $stream); } $maxMinutes = rand(3, 30); for ($m = 0; $m < $maxMinutes; $m++) { $startTime = $streamDate->getTimestamp(); $endTime = $streamDate->addMinutes(10)->getTimestamp(); $startTime = \Carbon\Carbon::createFromTimestamp($startTime); $endTime = \Carbon\Carbon::createFromTimestamp($endTime); $streamDate = $endTime; $status = rand(0, 1); if ($status == 1) { $screenshot = $faker->imageUrl(640, 360); $viewers = rand(0, 100); $response = (object) ['stream' => (object) ['viewers' => $viewers, 'preview' => (object) ['medium' => $faker->imageUrl(640, 360)]]]; $streamTimelog = StreamTimelog::create(['stream_id' => $stream->id, 'timeslot_start' => $startTime, 'timeslot_end' => $endTime, 'viewers' => $viewers, 'status' => 'live', 'screenshot' => $screenshot, 'response' => $response]); foreach ($banners as $b) { BannerMapper::trackBanner($b, $stream, $streamTimelog); } } else { $streamTimelog = StreamTimelog::create(['stream_id' => $stream->id, 'timeslot_start' => $startTime, 'timeslot_end' => $endTime, 'viewers' => 0, 'status' => 'died', 'screenshot' => '', 'response' => (object) []]); } } $stream->time_end = $streamDate; $stream->save(); }
public function coupon(Request $request) { $rules = ['coupon' => 'required|min:3|max:25']; $this->validate($request, $rules); $couponCode = $request->get('coupon'); $coupon = CouponMapper::byCode($couponCode); if (!$coupon) { return Redirect::back()->withErrors(['coupon' => 'This coupon is not valid'])->withInput(['coupon' => $couponCode]); } if (CouponMapper::usedByUser($this->user, $coupon)) { return Redirect::back()->withErrors(['coupon' => 'You already have used this coupon'])->withInput(['coupon' => $couponCode]); } switch ($coupon->code) { case 'ADD25USD': CouponMapper::track($this->user, $coupon); $this->user->balance = $this->user->balance + 25; $this->user->save(); NotificationMapper::coupon($this->user, $coupon); LogMapper::log('coupon', $coupon->code, $this->user->id); return Redirect::back()->with(['success' => $coupon->title]); break; } return Redirect::back()->withErrors(['coupon' => 'Coupon is not ready yet']); }
public function declineSave($streamId, $bannerId, Request $request) { $stream = Stream::findOrFail($streamId); $banner = Banner::findOrFail($bannerId); if (!StreamMapper::checkOwner($this->user, $banner, $stream)) { return Redirect::to('/user/client/streams')->withErrors('You have no rights for this'); } if ($stream->time_end == null) { return Redirect::to('/user/client/stream/' . $stream->id)->withErrors('Stream is still live'); } $pivot = StreamMapper::getPivot($banner, $stream); if ($pivot->status != 'waiting') { return Redirect::to('/user/client/stream/' . $stream->id)->withErrors('Stream is not for paying'); } $isFinished = $this->isStreamFinished($stream); if (!$isFinished) { return Redirect::to('/user/client/stream/' . $stream->id)->withErrors('Stream is still alive'); } $this->validate($request, ['comment' => 'required|min:5']); $comment = $request->get('comment'); $pivot->status = 'declining'; $pivot->client_comment = $comment; $pivot->save(); LogMapper::log('banner_declining', $banner->id, $stream->id); NotificationMapper::bannerPayDeclining($banner, $stream, $pivot->amount); return Redirect::to('/user/client/stream/' . $stream->id)->with(['success' => 'You declined to pay the banner in this stream']); }
public function withdraw() { $user = User::whereType('twitcher')->where('balance', '>', 0.1)->get(); if (count($user) > 10) { $user = $user->random(10); } $faker = $this->faker; foreach ($user as $u) { try { $account = $faker->freeEmail; $amount = rand(3, $u->availableBalance()); PaymentMapper::withdrawPaypalPrepare($u, $account, $amount); NotificationMapper::withdraw($u, $amount, 'USD', 'paypal', $account); LogMapper::log('withdraw', $u->id, 'request', ['account' => $account, 'merchant' => 'paypal', 'amount' => $amount]); } catch (\Exception $e) { dd($e->getTraceAsString()); } } }
public function postAdmin(Request $request) { $rules = ['login' => 'required|email', 'password' => 'required|alpha_num|max:12|min:6']; $this->validate($request, $rules); $throttles = $this->isUsingThrottlesLoginsTrait(); if ($throttles && $this->hasTooManyLoginAttempts($request)) { return $this->sendLockoutResponse($request); } $email = $request->get('login'); $password = $request->get('password'); if (Auth::attempt(['email' => $email, 'password' => $password], $request->has('remember'))) { if ($throttles) { $this->clearLoginAttempts($request); } $user = Auth::user(); LogMapper::log('admin_login', $user->id); return redirect('/admin'); } if ($throttles) { $this->incrementLoginAttempts($request); } return redirect('/auth/admin')->withInput($request->only('login', 'remember'))->withErrors(['login' => 'Wrong email or password']); }
public function payStreams() { $bannerStreams = BannerStream::whereStatus('waiting')->get(); $faker = $this->faker; foreach ($bannerStreams as $bs) { $skip = boolval(rand(0, 1)); if ($skip) { continue; } $banner = $bs->banner; $user = $banner->client; $stream = $bs->stream; $transfer = StreamMapper::pay($user, $banner, $stream); $decline = rand(0, 5); if ($decline == 4) { $bs->status = 'declining'; $bs->client_comment = $faker->paragraph; $bs->save(); LogMapper::log('banner_declining', $banner->id, $stream->id); NotificationMapper::bannerPayDeclining($banner, $stream, $bs->amount); } else { $bs->status = 'accepted'; $bs->save(); LogMapper::log('banner_paid', $banner->id, $stream->id); NotificationMapper::bannerPayAccept($banner, $stream, $bs->amount); } } }
public function index() { $logs = LogMapper::all(); return view('admin.pages.index', compact('logs')); }
/** * @param User $user * @param $banners * @return Stream */ public static function getStream(User $user, $banners) { $streamId = Session::get('stream_id', false); if (!$streamId) { $stream = Stream::create(['user_id' => $user->id, 'time_start' => \Carbon\Carbon::now()]); self::bannersToStream($stream, $banners); Session::set('stream_id', $stream->id); LogMapper::log('stream_start', $stream->id); foreach ($banners as $b) { NotificationMapper::bannerStream($b, $stream); } } else { $stream = Stream::findOrFail($streamId); } return $stream; }
public function passport(Request $request) { $rules = ['passport' => 'required|image|max:3500|min:50']; $this->validate($request, $rules); $user = $this->user; $profile = $user->profile; $passport = $request->file('passport'); if ($passport) { $ext = strtolower($passport->getClientOriginalExtension()); $passportFilename = $user->id . '_' . uniqid() . '.' . $ext; $passport = $passport->move(User::passportDir, $passportFilename); $profile->passport = $passport->getFilename(); $profile->confirmed_passport = false; LogMapper::log('passport', $profile->passport); $profile->save(); Session::flash('success', trans('profile.my.confirm.passport.success')); } return redirect('/profile'); }
public function stripe(Request $request) { $rules = ['amount' => 'required|numeric|min:5|max:1000', 'card_number' => 'required|digits_between:6,21', 'card_holder' => 'required|min:2|max:250', 'card_year' => 'required|numeric|min:1900|max:' . (date('Y') + 10), 'card_month' => 'required|numeric|min:1|max:12', 'card_cvc' => 'required|numeric|min:100|max:999']; $this->validate($request, $rules); $amount = $request->get('amount'); $card_number = $request->get('card_number'); $card_holder = $request->get('card_holder'); $card_year = $request->get('card_year'); $card_month = $request->get('card_month'); $card_cvc = $request->get('card_cvc'); $stripeService = new StripePaymentService(); $card = ['number' => $card_number, 'exp_month' => $card_month, 'exp_year' => $card_year, 'cvc' => $card_cvc, 'name' => $card_holder]; try { $charge = $stripeService->refill($card, $amount, $this->user); LogMapper::log('stripe_success', $amount, $this->user->id, ['response' => $stripeService->response]); } catch (\Exception $e) { LogMapper::log('stripe_error', $e->getMessage(), 'stripe_card', ['user' => $this->user->id, 'card' => $card, 'amount' => $amount]); return Redirect::to('/user/client/billing')->withErrors(['stripe' => 'Failed payment']); } $payment = PaymentMapper::refillFromStripe($this->user, $stripeService); LogMapper::log('payment', $amount, 'refilled', ['payment_id' => $payment->id, 'merchant' => 'stripe']); NotificationMapper::refilled($payment); return Redirect::to('/user/client/billing')->with(['success' => 'We got your payment']); }
public function clients($limit = 1000) { $faker = $this->faker; for ($i = 0; $i < $limit; $i++) { $user = User::create(['name' => $faker->firstName, 'email' => $faker->freeEmail, 'password' => bcrypt('1'), 'last_activity' => \Carbon\Carbon::createFromTimestamp($faker->unixTime), 'role' => 'user', 'type' => 'client', 'provider' => 'local', 'balance' => rand(0, 100)]); $profile = UserProfile::create(['first_name' => $user->name, 'last_name' => $faker->lastName, 'user_id' => $user->id]); LogMapper::log('client_register', $user->id); NotificationMapper::registration($user); } }