Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 145
feat: User activation checks and utility functions.#580
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
d37cf147d3bc7ad1b3afc62b60a98ab2d6fFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -49,12 +49,24 @@ public function before(RequestInterface $request, $arguments = null) | ||
| ]); | ||
| if (! $result->isOK() || (! empty($arguments) && $result->extraInfo()->tokenCant($arguments[0]))) { | ||
| return redirect()->to('/login'); | ||
| return service('response') | ||
| ->setStatusCode(Response::HTTP_UNAUTHORIZED) | ||
| ->setJson(['message' => lang('Auth.badToken')]); | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a breaking change. It is better to document it. #433 suggests 401, not 403. Which is better? Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for 401. For example, I already using it in few deployments with own api-filter. I would like to switch to this one if it's will be suitable for me.
| ||
| } | ||
| if (setting('Auth.recordActiveDate')) { | ||
| $authenticator->recordActiveDate(); | ||
| } | ||
| // Block inactive users when Email Activation is enabled | ||
| $user = $authenticator->getUser(); | ||
| if ($user !== null && ! $user->isActivated()) { | ||
| $authenticator->logout(); | ||
| return service('response') | ||
| ->setStatusCode(Response::HTTP_FORBIDDEN) | ||
| ->setJson(['message' => lang('Auth.activationBlocked')]); | ||
datamweb marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| } | ||
| /** | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
| namespace CodeIgniter\Shield\Traits; | ||
| trait Activatable | ||
| { | ||
| /** | ||
| * Returns true if the user has been activated | ||
| * and activation is required after registration. | ||
| */ | ||
| public function isActivated(): bool | ||
| { | ||
| // If activation is not required, then we're always active. | ||
| return ! $this->shouldActivate() || $this->active; | ||
| } | ||
| /** | ||
| * Returns true if the user has not been activated. | ||
| */ | ||
| public function isNotActivated(): bool | ||
| { | ||
| return ! $this->isActivated(); | ||
| } | ||
| /** | ||
| * Activates the user. | ||
| */ | ||
| public function activate(): bool | ||
datamweb marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you change the return type to MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless it's changing in a PR, Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I sent a PR #626 | ||
| { | ||
| $model = auth()->getProvider(); | ||
| return $model->update($this->id, ['active' => 1]); | ||
| } | ||
| /** | ||
| * Deactivates the user. | ||
| */ | ||
| public function deactivate(): bool | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same above. | ||
| { | ||
| $model = auth()->getProvider(); | ||
| return $model->update($this->id, ['active' => 0]); | ||
| } | ||
| /** | ||
| * Does the Auth actions require activation? | ||
| * Check for the generic 'Activator' class name to allow | ||
| * for custom implementations, provided they follow the naming convention. | ||
| */ | ||
| private function shouldActivate(): bool | ||
| { | ||
| return strpos(setting('Auth.actions')['register'] ?? '', 'Activator') !== false; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.