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

Feat: Force password reset #601

Merged
merged 25 commits into from
Feb 3, 2023

Conversation

sammyskills
Copy link
Contributor

Fixes #522

Implemented the force password reset functionality with the following highlights:

  • Added a new Resettable trait that is used on the User entity. This provides a couple of methods to check if a user requires a password reset or not, forcing a password reset and undoing the forced password reset. Thanks @lonnieezell
  • Updated the UserIdentityModel with methods to force a password reset for multiple users and globally, i.e., all the users.
  • Added a filter ForcePasswordResetFilter to check and redirect appropriately after a user is logged in.
  • Updated the Registrar config.
  • Updated Auth config to allow devs to specify a force_reset redirect.
  • Updated quickstart.md and install.md docs.
  • And of course, created and updated tests.

@kenjis kenjis added the new feature PRs for new features label Jan 16, 2023
@kenjis
Copy link
Member

kenjis commented Jan 18, 2023

Tests do not pass on Postgres.

There were 6 errors:

1) Tests\Unit\UserIdentityModelTest::testForceMultiplePasswordReset
CodeIgniter\Database\Exceptions\DatabaseException: pg_query(): Query failed: ERROR:  operator does not exist: smallint = boolean
LINE 3: AND "force_reset" = FALSE
                          ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.

/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:645
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseBuilder.php:2462
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:395
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/BaseModel.php:943
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:755
/home/runner/work/shield/shield/src/Models/UserIdentityModel.php:345
/home/runner/work/shield/shield/tests/Unit/UserIdentityModelTest.php:96
phpvfscomposer:///home/runner/work/shield/shield/vendor/phpunit/phpunit/phpunit:97

Caused by
CodeIgniter\Database\Exceptions\DatabaseException: pg_query(): Query failed: ERROR:  operator does not exist: smallint = boolean
LINE 3: AND "force_reset" = FALSE
                          ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.

/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/Postgre/Connection.php:152
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:691
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:605
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseBuilder.php:2462
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:395
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/BaseModel.php:943
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:755
/home/runner/work/shield/shield/src/Models/UserIdentityModel.php:345
/home/runner/work/shield/shield/tests/Unit/UserIdentityModelTest.php:96
phpvfscomposer:///home/runner/work/shield/shield/vendor/phpunit/phpunit/phpunit:97

Caused by
ErrorException: pg_query(): Query failed: ERROR:  operator does not exist: smallint = boolean
LINE 3: AND "force_reset" = FALSE
                          ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.

/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/Postgre/Connection.php:147
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:691
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:605
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseBuilder.php:2462
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:395
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/BaseModel.php:943
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:755
/home/runner/work/shield/shield/src/Models/UserIdentityModel.php:345
/home/runner/work/shield/shield/tests/Unit/UserIdentityModelTest.php:96
phpvfscomposer:///home/runner/work/shield/shield/vendor/phpunit/phpunit/phpunit:97

2) Tests\Authentication\ForcePasswordResetTest::testRequiresPasswordResetRedirect
CodeIgniter\Database\Exceptions\DatabaseException: pg_query(): Query failed: ERROR:  column "force_reset" is of type smallint but expression is of type boolean
LINE 1: UPDATE "db_auth_identities" SET "force_reset" = TRUE, "updat...
                                                        ^
HINT:  You will need to rewrite or cast the expression.

/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:645
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseBuilder.php:2462
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:395
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/BaseModel.php:943
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:755
/home/runner/work/shield/shield/src/Traits/Resettable.php:43
/home/runner/work/shield/shield/tests/Authentication/ForcePasswordResetTest.php:96
phpvfscomposer:///home/runner/work/shield/shield/vendor/phpunit/phpunit/phpunit:97

Caused by
CodeIgniter\Database\Exceptions\DatabaseException: pg_query(): Query failed: ERROR:  column "force_reset" is of type smallint but expression is of type boolean
LINE 1: UPDATE "db_auth_identities" SET "force_reset" = TRUE, "updat...
                                                        ^
HINT:  You will need to rewrite or cast the expression.

/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/Postgre/Connection.php:152
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:691
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:605
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseBuilder.php:2462
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:395
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/BaseModel.php:943
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:755
/home/runner/work/shield/shield/src/Traits/Resettable.php:43
/home/runner/work/shield/shield/tests/Authentication/ForcePasswordResetTest.php:96
phpvfscomposer:///home/runner/work/shield/shield/vendor/phpunit/phpunit/phpunit:97

Caused by
ErrorException: pg_query(): Query failed: ERROR:  column "force_reset" is of type smallint but expression is of type boolean
LINE 1: UPDATE "db_auth_identities" SET "force_reset" = TRUE, "updat...
                                                        ^
HINT:  You will need to rewrite or cast the expression.

/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/Postgre/Connection.php:147
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:691
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:605
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseBuilder.php:2462
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:395
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/BaseModel.php:943
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:755
/home/runner/work/shield/shield/src/Traits/Resettable.php:43
/home/runner/work/shield/shield/tests/Authentication/ForcePasswordResetTest.php:96
phpvfscomposer:///home/runner/work/shield/shield/vendor/phpunit/phpunit/phpunit:97

3) Tests\Authentication\ForcePasswordResetTest::testForceGlobalPasswordReset
CodeIgniter\Database\Exceptions\DatabaseException: pg_query(): Query failed: ERROR:  operator does not exist: smallint = boolean
LINE 4: AND "force_reset" = FALSE
                          ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.

/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:645
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseBuilder.php:2462
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:395
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/BaseModel.php:943
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:755
/home/runner/work/shield/shield/src/Models/UserIdentityModel.php:369
/home/runner/work/shield/shield/tests/Authentication/ForcePasswordResetTest.php:125
phpvfscomposer:///home/runner/work/shield/shield/vendor/phpunit/phpunit/phpunit:97

Caused by
CodeIgniter\Database\Exceptions\DatabaseException: pg_query(): Query failed: ERROR:  operator does not exist: smallint = boolean
LINE 4: AND "force_reset" = FALSE
                          ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.

/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/Postgre/Connection.php:152
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:691
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:605
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseBuilder.php:2462
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:395
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/BaseModel.php:943
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:755
/home/runner/work/shield/shield/src/Models/UserIdentityModel.php:369
/home/runner/work/shield/shield/tests/Authentication/ForcePasswordResetTest.php:125
phpvfscomposer:///home/runner/work/shield/shield/vendor/phpunit/phpunit/phpunit:97

Caused by
ErrorException: pg_query(): Query failed: ERROR:  operator does not exist: smallint = boolean
LINE 4: AND "force_reset" = FALSE
                          ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.

/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/Postgre/Connection.php:147
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:691
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:605
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseBuilder.php:2462
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:395
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/BaseModel.php:943
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:755
/home/runner/work/shield/shield/src/Models/UserIdentityModel.php:369
/home/runner/work/shield/shield/tests/Authentication/ForcePasswordResetTest.php:125
phpvfscomposer:///home/runner/work/shield/shield/vendor/phpunit/phpunit/phpunit:97

4) Tests\Authentication\ForcePasswordResetTest::testUserRequiresPasswordReset
CodeIgniter\Database\Exceptions\DatabaseException: pg_query(): Query failed: ERROR:  column "force_reset" is of type smallint but expression is of type boolean
LINE 1: UPDATE "db_auth_identities" SET "force_reset" = TRUE, "updat...
                                                        ^
HINT:  You will need to rewrite or cast the expression.

/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:645
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseBuilder.php:2462
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:395
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/BaseModel.php:943
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:755
/home/runner/work/shield/shield/tests/Authentication/ForcePasswordResetTest.php:59
phpvfscomposer:///home/runner/work/shield/shield/vendor/phpunit/phpunit/phpunit:97

Caused by
CodeIgniter\Database\Exceptions\DatabaseException: pg_query(): Query failed: ERROR:  column "force_reset" is of type smallint but expression is of type boolean
LINE 1: UPDATE "db_auth_identities" SET "force_reset" = TRUE, "updat...
                                                        ^
HINT:  You will need to rewrite or cast the expression.

/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/Postgre/Connection.php:152
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:691
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:605
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseBuilder.php:2462
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:395
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/BaseModel.php:943
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:755
/home/runner/work/shield/shield/tests/Authentication/ForcePasswordResetTest.php:59
phpvfscomposer:///home/runner/work/shield/shield/vendor/phpunit/phpunit/phpunit:97

Caused by
ErrorException: pg_query(): Query failed: ERROR:  column "force_reset" is of type smallint but expression is of type boolean
LINE 1: UPDATE "db_auth_identities" SET "force_reset" = TRUE, "updat...
                                                        ^
HINT:  You will need to rewrite or cast the expression.

/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/Postgre/Connection.php:147
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:691
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:605
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseBuilder.php:2462
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:395
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/BaseModel.php:943
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:755
/home/runner/work/shield/shield/tests/Authentication/ForcePasswordResetTest.php:59
phpvfscomposer:///home/runner/work/shield/shield/vendor/phpunit/phpunit/phpunit:97

5) Tests\Authentication\ForcePasswordResetTest::testForcePasswordResetOnUser
CodeIgniter\Database\Exceptions\DatabaseException: pg_query(): Query failed: ERROR:  column "force_reset" is of type smallint but expression is of type boolean
LINE 1: UPDATE "db_auth_identities" SET "force_reset" = TRUE, "updat...
                                                        ^
HINT:  You will need to rewrite or cast the expression.

/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:645
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseBuilder.php:2462
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:395
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/BaseModel.php:943
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:755
/home/runner/work/shield/shield/src/Traits/Resettable.php:43
/home/runner/work/shield/shield/tests/Authentication/ForcePasswordResetTest.php:71
phpvfscomposer:///home/runner/work/shield/shield/vendor/phpunit/phpunit/phpunit:97

Caused by
CodeIgniter\Database\Exceptions\DatabaseException: pg_query(): Query failed: ERROR:  column "force_reset" is of type smallint but expression is of type boolean
LINE 1: UPDATE "db_auth_identities" SET "force_reset" = TRUE, "updat...
                                                        ^
HINT:  You will need to rewrite or cast the expression.

/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/Postgre/Connection.php:152
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:691
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:605
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseBuilder.php:2462
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:395
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/BaseModel.php:943
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:755
/home/runner/work/shield/shield/src/Traits/Resettable.php:43
/home/runner/work/shield/shield/tests/Authentication/ForcePasswordResetTest.php:71
phpvfscomposer:///home/runner/work/shield/shield/vendor/phpunit/phpunit/phpunit:97

Caused by
ErrorException: pg_query(): Query failed: ERROR:  column "force_reset" is of type smallint but expression is of type boolean
LINE 1: UPDATE "db_auth_identities" SET "force_reset" = TRUE, "updat...
                                                        ^
HINT:  You will need to rewrite or cast the expression.

/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/Postgre/Connection.php:147
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:691
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:605
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseBuilder.php:2462
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:395
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/BaseModel.php:943
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:755
/home/runner/work/shield/shield/src/Traits/Resettable.php:43
/home/runner/work/shield/shield/tests/Authentication/ForcePasswordResetTest.php:71
phpvfscomposer:///home/runner/work/shield/shield/vendor/phpunit/phpunit/phpunit:97

6) Tests\Authentication\ForcePasswordResetTest::testUndoForcePasswordResetOnUser
CodeIgniter\Database\Exceptions\DatabaseException: pg_query(): Query failed: ERROR:  column "force_reset" is of type smallint but expression is of type boolean
LINE 1: UPDATE "db_auth_identities" SET "force_reset" = TRUE, "updat...
                                                        ^
HINT:  You will need to rewrite or cast the expression.

/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:645
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseBuilder.php:2462
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:395
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/BaseModel.php:943
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:755
/home/runner/work/shield/shield/src/Traits/Resettable.php:43
/home/runner/work/shield/shield/tests/Authentication/ForcePasswordResetTest.php:83
phpvfscomposer:///home/runner/work/shield/shield/vendor/phpunit/phpunit/phpunit:97

Caused by
CodeIgniter\Database\Exceptions\DatabaseException: pg_query(): Query failed: ERROR:  column "force_reset" is of type smallint but expression is of type boolean
LINE 1: UPDATE "db_auth_identities" SET "force_reset" = TRUE, "updat...
                                                        ^
HINT:  You will need to rewrite or cast the expression.

/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/Postgre/Connection.php:152
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:691
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:605
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseBuilder.php:2462
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:395
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/BaseModel.php:943
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:755
/home/runner/work/shield/shield/src/Traits/Resettable.php:43
/home/runner/work/shield/shield/tests/Authentication/ForcePasswordResetTest.php:83
phpvfscomposer:///home/runner/work/shield/shield/vendor/phpunit/phpunit/phpunit:97

Caused by
ErrorException: pg_query(): Query failed: ERROR:  column "force_reset" is of type smallint but expression is of type boolean
LINE 1: UPDATE "db_auth_identities" SET "force_reset" = TRUE, "updat...
                                                        ^
HINT:  You will need to rewrite or cast the expression.

/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/Postgre/Connection.php:147
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:691
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseConnection.php:605
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Database/BaseBuilder.php:2462
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:395
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/BaseModel.php:943
/home/runner/work/shield/shield/vendor/codeigniter4/framework/system/Model.php:755
/home/runner/work/shield/shield/src/Traits/Resettable.php:43
/home/runner/work/shield/shield/tests/Authentication/ForcePasswordResetTest.php:83
phpvfscomposer:///home/runner/work/shield/shield/vendor/phpunit/phpunit/phpunit:97

ERRORS!
Tests: 227, Assertions: 575, Errors: 6.

https://github.com/codeigniter4/shield/actions/runs/3933401851/jobs/6727065311

@kenjis
Copy link
Member

kenjis commented Jan 20, 2023

@sammyskills
Copy link
Contributor Author

The test passed now. Please check.

docs/install.md Outdated Show resolved Hide resolved
docs/install.md Outdated Show resolved Hide resolved
docs/install.md Outdated Show resolved Hide resolved
docs/install.md Outdated Show resolved Hide resolved
docs/install.md Outdated Show resolved Hide resolved
@sammyskills
Copy link
Contributor Author

Hi @kenjis,

Still waiting for your review.

docs/quickstart.md Outdated Show resolved Hide resolved
docs/quickstart.md Outdated Show resolved Hide resolved
docs/quickstart.md Outdated Show resolved Hide resolved
src/Traits/Resettable.php Outdated Show resolved Hide resolved
src/Traits/Resettable.php Outdated Show resolved Hide resolved
@kenjis kenjis merged commit 2263f82 into codeigniter4:develop Feb 3, 2023
@kenjis
Copy link
Member

kenjis commented Feb 3, 2023

@sammyskills Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature PRs for new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dev: force password reset functionality
2 participants