Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: redirect inactive account to auth action page #869

Merged
merged 2 commits into from
Oct 3, 2023

Conversation

sammyskills
Copy link
Contributor

@sammyskills sammyskills commented Sep 30, 2023

Description
The isActivated() check works for when a register action has been set in the auth config. Currently, if an inactive account tries to log in, the system redirects the user to the login page with the error message:

You must activate your account before logging in.

This begs the question: "How do I activate my account?"

This PR fixes this issue by redirecting the user to the auth action page, where a new token is generated and sent to the user's email.

Checklist:

  • Securely signed commits
  • [] Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • [] User guide updated
  • Conforms to style guide

@kenjis
Copy link
Member

kenjis commented Oct 2, 2023

@sammyskills I cannot reproduce the situation with develop branch.

If an inactive account tries to log in, the system redirects the user to auth/a/show and I see:

Email Activation

We just sent an email to you with a code to confirm your email address. Copy that code and paste it below.

and I get a email with token.

@sammyskills
Copy link
Contributor Author

Hi @kenjis,

Yes, you will get the error message and it will be redirected to the auth/a/show page because the inactive account in your case, still has the email_activate identity.

Try this:

  • Delete the email_activate identity associated with the user from the auth_identities table and try to login again
    OR
  • Set the register action in the app/Config/Auth.php file to null temporarily
    • Register a new account
    • Set the register action back to \CodeIgniter\Shield\Authentication\Actions\EmailActivator::class in the app/Config/Auth.php file
    • Try to login with this account.

Live scenario:

  • An application allowed some users to register without email verification
  • But later activated email verification in the system.

@kenjis
Copy link
Member

kenjis commented Oct 2, 2023

@sammyskills "Delete the email_activate identity", this does not seem to happen.
Or it seems a bug in the application, not in Shield.
Why do you delete the identity?

The live scenario could happen. But we already set the user active:

// Set the user active
$user->activate();

@sammyskills
Copy link
Contributor Author

Ok, fine.

Let's look at it this way.

  • You activate the register action
  • Register an account
  • Verify the token (which activates the account and deletes the email_activate identity)
  • Now, deactivate this account $user->deactivate().
  • Try to login with this deactivated account.

If you get what I mean, how does a user with a deactivated account "reactivate" their account?

@kenjis
Copy link
Member

kenjis commented Oct 2, 2023

@sammyskills Okay, I got "You must activate your account before logging in."!

@sammyskills
Copy link
Contributor Author

Perfect!

Now, how does this user activate/reactivate their account?

@kenjis kenjis added the bug Something isn't working label Oct 2, 2023
Copy link
Member

@kenjis kenjis left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Collaborator

@datamweb datamweb left a comment

Choose a reason for hiding this comment

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

@sammyskills thank you!

@datamweb datamweb merged commit defdd11 into codeigniter4:develop Oct 3, 2023
31 checks passed
@sammyskills sammyskills deleted the fix-inactive-redirect branch October 3, 2023 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants