Skip to content

Conversation

@LightningBoltz21
Copy link

Fixes issue #5322. NOTE: the functionality of the controller has not been tested yet, but I'm making a PR so what I have so far can be reviewed.

@LightningBoltz21
Copy link
Author

I believe the linting is failing because Pint and PHPCS have conflicting documentation.

For example:
valid in Pint, not valid in PHPCS
$result = $sponsorUser->attemptLoginUsingOneTimePassword((string) $request->input('otp'));

not valid in Pint, valid in PHPCS
$result = $sponsorUser->attemptLoginUsingOneTimePassword( (string) $request->input('otp'));

}

// Generate and dispatch OTP using Spatie
$sponsorUser->sendOneTimePassword();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SponsorUser must exist in the database at this point, because the one-time password is associated with their ID. You need to save the SponsorUser before this point if it is a new user.

Comment on lines +82 to +87
$sponsorUser = SponsorUser::where('email', $email)->first();
if (! $sponsorUser) {
// Create temporary unsaved user for OTP verification
$sponsorUser = new SponsorUser();
$sponsorUser->email = $email;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user must already exist at this point for an OTP to be generated anyway, so you can simplify this

Suggested change
$sponsorUser = SponsorUser::where('email', $email)->first();
if (! $sponsorUser) {
// Create temporary unsaved user for OTP verification
$sponsorUser = new SponsorUser();
$sponsorUser->email = $email;
}
$sponsorUser = SponsorUser::where('email', $email)->sole();

Comment on lines +105 to +107
if (! $sponsorUser->exists) {
$sponsorUser->save();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not required since the user must already exist earlier in the flow

Comment on lines +112 to +120
// Establish authenticated session
$request->session()->regenerate();
session([
'sponsor_authenticated' => true,
'sponsor_id' => $sponsor->id,
'sponsor_name' => $sponsor->name,
'sponsor_email' => $email,
]);
session()->forget('sponsor_email_pending');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using Auth::login instead

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we using that middleware for regular users, and if so, could it be problematic to use Auth::login() on multiple User types?

Copy link
Member

@kberzinch kberzinch Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CasAuthenticate is how all current users authenticate to the web interface, yes.

There would be some kinks to work out with access to normal member pages, but I still think that's a better design than manually managing sessions.


This password will expire in 10 minutes.

If you did not request this password, please contact [email protected].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We typically include a footer with an unsubscribe link from our email vendor, Postmark

----
To stop receiving emails from {{ config('app.name') }}, visit @{{{ pm:unsubscribe }}}.

There's a bunch of other plumbing we do with unsubscribes via Postmark, but, we can get more into that later.

Comment on lines +112 to +120
// Establish authenticated session
$request->session()->regenerate();
session([
'sponsor_authenticated' => true,
'sponsor_id' => $sponsor->id,
'sponsor_name' => $sponsor->name,
'sponsor_email' => $email,
]);
session()->forget('sponsor_email_pending');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we using that middleware for regular users, and if so, could it be problematic to use Auth::login() on multiple User types?

return response()->json([
'success' => true,
'message' => 'Login successful! Redirecting to dashboard...',
'redirect' => route('home'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this redirect to? If it goes to the normal home page, we will need to change it to a sponsor-specific page before deploying the app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants