Skip to content

Commit

Permalink
Merge branch '11.next-cake4.4' into 11.next-cake4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
skie committed Oct 19, 2023
2 parents ff9401f + 9229d77 commit f6876ba
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 55 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ parameters:
count: 1
path: src/Controller/UsersController.php

-
message: "#^Parameter \\#1 \\$message of method Cake\\\\Controller\\\\Controller\\:\\:log\\(\\) expects string, Exception given\\.$#"
count: 1
path: src/Controller/UsersController.php

-
message: "#^Parameter \\#1 \\$object of method Cake\\\\Controller\\\\Controller\\:\\:paginate\\(\\) expects Cake\\\\ORM\\\\Query\\|Cake\\\\ORM\\\\Table\\|string\\|null, Cake\\\\Datasource\\\\RepositoryInterface given\\.$#"
count: 1
Expand Down
12 changes: 2 additions & 10 deletions src/Controller/Traits/OneTimePasswordVerifyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,11 @@ protected function onVerifyGetSecret($user)

// catching sql exception in case of any sql inconsistencies
try {
$query = $this->getUsersTable()->updateQuery();
$query
->set(['secret' => $secret])
->where(['id' => $user['id']]);
$query->execute();
$query = $this->getUsersTable()->updateAll(['secret' => $secret], ['id' => $user['id']]);
$user['secret'] = $secret;
$this->getRequest()->getSession()->write(AuthenticationService::TWO_FACTOR_VERIFY_SESSION_KEY, $user);
} catch (\Exception $e) {
$this->getRequest()->getSession()->destroy();
$this->log($e);
$message = __d('cake_d_c/users', 'Could not verify, please try again');
$this->Flash->error($message, [
'key' => 'auth',
Expand Down Expand Up @@ -183,10 +178,7 @@ protected function onPostVerifyCodeOkay($loginAction, $user)
unset($user['secret']);

if (!$user['secret_verified']) {
$this->getUsersTable()->updateQuery()
->set(['secret_verified' => true])
->where(['id' => $user['id']])
->execute();
$this->getUsersTable()->updateAll(['secret_verified' => true], ['id' => $user['id']]);
}

$this->getRequest()->getSession()->delete(AuthenticationService::TWO_FACTOR_VERIFY_SESSION_KEY);
Expand Down
6 changes: 1 addition & 5 deletions src/Controller/Traits/PasswordManagementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,7 @@ public function resetOneTimePasswordAuthenticator($id = null)
{
if ($this->getRequest()->is('post')) {
try {
$query = $this->getUsersTable()->updateQuery();
$query
->set(['secret_verified' => false, 'secret' => null])
->where(['id' => $id]);
$query->execute();
$query = $this->getUsersTable()->updateAll(['secret_verified' => false, 'secret' => null], ['id' => $id]);

$message = __d('cake_d_c/users', 'Google Authenticator token was successfully reset');
$this->Flash->success($message, 'default');
Expand Down
28 changes: 14 additions & 14 deletions src/Mailer/UsersMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ class UsersMailer extends Mailer
* @param \Cake\Datasource\EntityInterface $user User entity
* @return void
*/
protected function validation(EntityInterface $user, $options = [])
protected function validation(EntityInterface $user, array $options = [])
{
$firstName = isset($user['first_name']) ? $user['first_name'] . ', ' : '';
// un-hide the token to be able to send it in the email content
$user->setHidden(['password', 'token_expires', 'api_token']);
$subject = __d('cake_d_c/users', 'Your account validation link');

if (isset($options['linkGenerator']) && is_callable($options['linkGenerator'])) {
$generator = $options['linkGenerator'];
$link = $generator($user['token']);
} else {
$link = UsersUrl::actionUrl('validateEmail', [
if (isset($options['linkGenerator']) && is_callable($options['linkGenerator'])) {
$generator = $options['linkGenerator'];
$link = $generator($user['token']);
} else {
$link = UsersUrl::actionUrl('validateEmail', [
'_full' => true,
$user['token'],
]);
}
}

$viewVars = [
'activationUrl' => $link,
Expand All @@ -65,22 +65,22 @@ protected function validation(EntityInterface $user, $options = [])
* @param \Cake\Datasource\EntityInterface $user User entity
* @return void
*/
protected function resetPassword(EntityInterface $user, $options = [])
protected function resetPassword(EntityInterface $user, array $options = [])
{
$firstName = isset($user['first_name']) ? $user['first_name'] . ', ' : '';
$subject = __d('cake_d_c/users', '{0}Your reset password link', $firstName);
// un-hide the token to be able to send it in the email content
$user->setHidden(['password', 'token_expires', 'api_token']);

if (isset($options['linkGenerator']) && is_callable($options['linkGenerator'])) {
$generator = $options['linkGenerator'];
$link = $generator($user['token']);
} else {
$link = UsersUrl::actionUrl('resetPassword', [
if (isset($options['linkGenerator']) && is_callable($options['linkGenerator'])) {
$generator = $options['linkGenerator'];
$link = $generator($user['token']);
} else {
$link = UsersUrl::actionUrl('resetPassword', [
'_full' => true,
$user['token'],
]);
}
}

$viewVars = [
'activationUrl' => $link,
Expand Down
8 changes: 4 additions & 4 deletions src/Model/Behavior/PasswordBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ public function resetToken($reference, array $options = [])
$user->updateToken($expiration);
$saveResult = $this->_table->save($user);
if ($options['sendEmail'] ?? false) {
$emailOptions = [];
if (isset($options['linkGenerator']) && is_callable($options['linkGenerator'])) {
$emailOptions['linkGenerator'] = $options['linkGenerator'];
}
$emailOptions = [];
if (isset($options['linkGenerator']) && is_callable($options['linkGenerator'])) {
$emailOptions['linkGenerator'] = $options['linkGenerator'];
}
switch ($options['type'] ?? null) {
case 'email':
$this->_sendValidationEmail($user, $emailOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ public function testLoginGetRequestNoSocialLogin()
$this->assertResponseNotContains('Username or password is incorrect');
$this->assertResponseContains('<form method="post" accept-charset="utf-8" action="/login">');
$this->assertResponseContains('<legend>Please enter your username and password</legend>');
$this->assertResponseContains('<input type="text" name="username" required="required" id="username" aria-required="true">');
$this->assertResponseContains('<input type="password" name="password" required="required" id="password" aria-required="true">');
$this->assertResponseContains('<input type="checkbox" name="remember_me" value="1" checked="checked" id="remember-me">');
$this->assertResponseContains('<input type="text" name="username" required="required" id="username" aria-required="true"');
$this->assertResponseContains('<input type="password" name="password" required="required" id="password" aria-required="true"');
$this->assertResponseContains('<input type="checkbox" name="remember_me" value="1" checked="checked" id="remember-me"');
$this->assertResponseContains('<button type="submit">Login</button>');
$this->assertResponseContains('<a href="/register">Register</a>');
$this->assertResponseContains('<a href="/users/request-reset-password">Reset Password</a>');
Expand All @@ -102,9 +102,9 @@ public function testLoginGetRequest()
$this->assertResponseNotContains('Username or password is incorrect');
$this->assertResponseContains('<form method="post" accept-charset="utf-8" action="/login">');
$this->assertResponseContains('<legend>Please enter your username and password</legend>');
$this->assertResponseContains('<input type="text" name="username" required="required" id="username" aria-required="true">');
$this->assertResponseContains('<input type="password" name="password" required="required" id="password" aria-required="true">');
$this->assertResponseContains('<input type="checkbox" name="remember_me" value="1" checked="checked" id="remember-me">');
$this->assertResponseContains('<input type="text" name="username" required="required" id="username" aria-required="true"');
$this->assertResponseContains('<input type="password" name="password" required="required" id="password" aria-required="true"');
$this->assertResponseContains('<input type="checkbox" name="remember_me" value="1" checked="checked" id="remember-me"');
$this->assertResponseContains('<button type="submit">Login</button>');
$this->assertResponseContains('<a href="/register">Register</a>');
$this->assertResponseContains('<a href="/users/request-reset-password">Reset Password</a>');
Expand All @@ -131,9 +131,9 @@ public function testLoginPostRequestInvalidPassword()
$this->assertResponseContains('Username or password is incorrect');
$this->assertResponseContains('<form method="post" accept-charset="utf-8" action="/login">');
$this->assertResponseContains('<legend>Please enter your username and password</legend>');
$this->assertResponseContains('<input type="text" name="username" required="required" id="username" aria-required="true" value="user-2">');
$this->assertResponseContains('<input type="password" name="password" required="required" id="password" aria-required="true" value="123456789">');
$this->assertResponseContains('<input type="checkbox" name="remember_me" value="1" checked="checked" id="remember-me">');
$this->assertResponseContains('<input type="text" name="username" required="required" id="username" aria-required="true" value="user-2"');
$this->assertResponseContains('<input type="password" name="password" required="required" id="password" aria-required="true" value="123456789"');
$this->assertResponseContains('<input type="checkbox" name="remember_me" value="1" checked="checked" id="remember-me"');
$this->assertResponseContains('<button type="submit">Login</button>');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testRequestResetPassword()
$this->get('/users/request-reset-password');
$this->assertResponseOk();
$this->assertResponseContains('Please enter your email or username to reset your password');
$this->assertResponseContains('<input type="text" name="reference" id="reference">');
$this->assertResponseContains('<input type="text" name="reference" id="reference"');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public function testRegister()
$this->assertResponseContains('<input type="email" name="email" required="required"');
$this->assertResponseContains('<input type="password" name="password" required="required"');
$this->assertResponseContains('<input type="password" name="password_confirm" required="required"');
$this->assertResponseContains('<input type="text" name="first_name" id="first-name" maxlength="50">');
$this->assertResponseContains('<input type="text" name="last_name" id="last-name" maxlength="50">');
$this->assertResponseContains('<input type="hidden" name="tos" value="0">');
$this->assertResponseContains('<input type="text" name="first_name" id="first-name" maxlength="50"');
$this->assertResponseContains('<input type="text" name="last_name" id="last-name" maxlength="50"');
$this->assertResponseContains('<input type="hidden" name="tos" value="0"');
$this->assertResponseContains('<label for="tos"><input type="checkbox" name="tos" value="1" required="required" id="tos" aria-required="true">Accept TOS conditions?</label>');
$this->assertResponseContains('<button type="submit">Submit</button>');
}
Expand Down Expand Up @@ -80,9 +80,9 @@ public function testRegisterPostWithErrors()
$this->assertResponseContains('<input type="email" name="email" required="required"');
$this->assertResponseContains('<input type="password" name="password" required="required"');
$this->assertResponseContains('<input type="password" name="password_confirm" required="required"');
$this->assertResponseContains('<input type="text" name="first_name" id="first-name" value="" maxlength="50">');
$this->assertResponseContains('<input type="text" name="last_name" id="last-name" value="" maxlength="50">');
$this->assertResponseContains('<input type="hidden" name="tos" value="0">');
$this->assertResponseContains('<input type="text" name="first_name" id="first-name" value="" maxlength="50"');
$this->assertResponseContains('<input type="text" name="last_name" id="last-name" value="" maxlength="50"');
$this->assertResponseContains('<input type="hidden" name="tos" value="0"');
$this->assertResponseContains('<label for="tos"><input type="checkbox" name="tos" value="1" required="required" id="tos" aria-required="true">Accept TOS conditions?</label>');
$this->assertResponseContains('<button type="submit">Submit</button>');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_app/TestApp/Mailer/OverrideMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class OverrideMailer extends UsersMailer
* @param EntityInterface $user
* @return array|void
*/
public function resetPassword(EntityInterface $user)
public function resetPassword(EntityInterface $user, array $options = [])
{
parent::resetPassword($user);
$this->setSubject('This is the new subject');
Expand Down

0 comments on commit f6876ba

Please sign in to comment.