/** * Get the current discount for the given user. * * @param Request $request * @param string $userId * @return Response */ public function current(Request $request, $userId) { $user = Spark::user()->where('id', $userId)->firstOrFail(); if ($coupon = $this->coupons->forBillable($user)) { return response()->json($coupon->toArray()); } }
/** * Create a discount for the given user. * * @param Request $request * @param string $userId * @return Response */ public function store(Request $request, $userId) { $user = Spark::user()->where('id', $userId)->firstOrFail(); $this->validate($request, ['type' => 'required|in:amount,percent', 'value' => 'required|integer', 'duration' => 'required|in:once,forever,repeating', 'months' => 'required_if:duration,repeating']); $coupon = StripeCoupon::create(['currency' => 'usd', 'amount_off' => $request->type == 'amount' ? $request->value * 100 : null, 'percent_off' => $request->type == 'percent' ? $request->value : null, 'duration' => $request->duration, 'duration_in_months' => $request->months, 'max_redemptions' => 1], config('services.stripe.secret')); $user->applyCoupon($coupon->id); }
/** * Get the current user of the application. * * @return \Illuminate\Http\Response */ public function getCurrentUser() { $user = Spark::user(); if (Spark::usingTeams()) { $user->currentTeam; } return $user->withHidden(['last_four', 'extra_billing_info']); }
/** * {@inheritdoc} */ public function handle($team, $email) { $invitedUser = Spark::user()->where('email', $email)->first(); $this->emailInvitation($invitation = $this->createInvitation($team, $email, $invitedUser)); if ($invitedUser) { event(new UserInvitedToTeam($team, $invitedUser)); } return $invitation; }
/** * Get the current user of the application. * * @return \Illuminate\Http\Response */ public function getCurrentUser() { $user = Spark::user(); if (Spark::usingTeams()) { $user->currentTeam; } $user->subscriptions; return $user->withHidden(['card_brand', 'card_last_four', 'extra_billing_info']); }
/** * Stop impersonating and switch back to primary account. * * @param Request $request * @return Response */ public function stopImpersonating(Request $request) { $currentId = Auth::id(); // We will make sure we have an impersonator's user ID in the session and if the // value doesn't exist in the session we will log this user out of the system // since they aren't really impersonating anyone and manually hit this URL. if (!$request->session()->has('spark:impersonator')) { Auth::logout(); return redirect('/'); } $userId = $request->session()->pull('spark:impersonator'); // After removing the impersonator user's ID from the session so we can retrieve // the original user. Then, we will flush the entire session to clear out any // stale data from while we were doing the impersonation of the other user. $request->session()->flush(); Auth::login(Spark::user()->findOrFail($userId)); return redirect('/spark/kiosk#/users/' . $currentId); }
/** * Login via the emergency token. * * @param Request $request * @return Response */ public function login(Request $request) { $this->validate($request, ['token' => 'required']); // If there is no authentication ID stored in the session, it means that the user // hasn't made it through the login screen so we'll just redirect them back to // the login view. They must have hit the route manually via a specific URL. if (!$request->session()->has('spark:auth:id')) { return redirect('login'); } $user = Spark::user()->findOrFail($request->session()->pull('spark:auth:id')); // Here we will check this hash of the token against the stored hash of the reset // token to make sure they match. If they don't match then the emergency token // is invalid so we'll redirect back out with an error message for the user. $resetCode = $user->two_factor_reset_code; if (!Hash::check($request->token, $resetCode)) { return redirect('login')->withErrors(['token' => 'The emergency token was invalid.']); } // If the token was valid we will login this user after disabling the two-factor // authentication settings so that they don't get stuck again. They will then // re-enable two-factor authentication in their settings if they so choose. $this->disableTwoFactorAuth($user); Auth::login($user, $request->session()->pull('spark:auth:remember', false)); return redirect()->intended($this->redirectPath()); }
/** * Get the number of users who are on a generic trial. * * @return Response */ public function trialUsers() { return Spark::user()->where('trial_ends_at', '>=', Carbon::now())->count(); }
/** * Verify the given authentication token. * * @param Request $request * @return Response */ public function verifyToken(Request $request) { $this->validate($request, ['token' => 'required']); // If there is no authentication ID stored in the session, it means that the user // hasn't made it through the login screen so we'll just redirect them back to // the login view. They must have hit the route manually via a specific URL. if (!$request->session()->has('spark:auth:id')) { return redirect('login'); } $user = Spark::user()->findOrFail($request->session()->pull('spark:auth:id')); // Next, we'll verify the actual token with our two-factor authentication service // to see if the token is valid. If it is, we can login the user and send them // to their intended location within the protected part of this application. if (Spark::interact(Verify::class, [$user, $request->token])) { Auth::login($user, $request->session()->pull('spark:auth:remember', false)); return redirect()->intended($this->redirectPath()); } else { return back(); } }
/** * {@inheritdoc} */ public function create(array $data) { $user = Spark::user(); $user->forceFill(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'last_read_announcements_at' => Carbon::now(), 'trial_ends_at' => Carbon::now()->addDays(Spark::trialDays())])->save(); return $user; }