Skip to content

Commit

Permalink
4.2.1 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette authored Apr 19, 2019
2 parents d312d1f + 25e6125 commit adec2ed
Show file tree
Hide file tree
Showing 32 changed files with 918 additions and 119 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ before_install:

before_script:
# install deps and UF
- composer install
- COMPOSER_MEMORY_LIMIT=-1 travis_retry composer install --no-interaction
- php bakery debug
- php bakery build-assets
- php bakery migrate
Expand Down
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [v4.2.1]

### Added
- `UserFrosting\Sprinkle\Core\Database\Models\Session` model for the `sessions` db table.
- `TEST_SESSION_HANDLER` environment variable to set the session save handler to use for Testing.
- `withDatabaseSessionHandler` Trait for testing. Use `$this->useDatabaseSessionHandler()` to use database session handler in tests.

### Fixed
- Italian translation ([#950])
- User Registration failing when trying to register two accounts with the same email address ([#953])
- Bad test case for `CoreController::getAsset`.
- User Model `forceDelete` doesn't remove the record from the DB ([#951])
- Fix PHP Fatal error that can be thrown when registering a new User
- Session not working with database handler ([#952])
- Remove any persistences when forceDeleting user to prevent Foreign Key Constraints issue ([#963])
- More helpful error message in checkEnvironment.php (Thanks @amosfolz; [#958])
- Hide locale select from UI if only one locale is available (Thanks @avsdev-cw; [#968])
- Download CSV filename error ([#893])

## [v4.2.0]
### Changed Requirements
- Changed minimum Node.js version to **v10.12.0**
Expand Down Expand Up @@ -702,7 +721,16 @@ See [http://learn.userfrosting.com/upgrading/40-to-41](Upgrading 4.0.x to 4.1.x
[#869]: https://github.com/userfrosting/UserFrosting/issues/869
[#872]: https://github.com/userfrosting/UserFrosting/issues/872
[#888]: https://github.com/userfrosting/UserFrosting/issues/888
[#893]: https://github.com/userfrosting/UserFrosting/issues/893
[#919]: https://github.com/userfrosting/UserFrosting/issues/919
[#940]: https://github.com/userfrosting/UserFrosting/issues/940
[#950]: https://github.com/userfrosting/UserFrosting/issues/950
[#951]: https://github.com/userfrosting/UserFrosting/issues/951
[#952]: https://github.com/userfrosting/UserFrosting/issues/952
[#953]: https://github.com/userfrosting/UserFrosting/issues/953
[#958]: https://github.com/userfrosting/UserFrosting/issues/958
[#963]: https://github.com/userfrosting/UserFrosting/issues/963
[#968]: https://github.com/userfrosting/UserFrosting/issues/968

[v4.2.0]: https://github.com/userfrosting/UserFrosting/compare/v4.1.22...v4.2.0
[v4.2.1]: https://github.com/userfrosting/UserFrosting/compare/v4.2.0...v4.2.1
2 changes: 1 addition & 1 deletion app/defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace UserFrosting;

// Some standard defines
define('UserFrosting\VERSION', '4.2.0');
define('UserFrosting\VERSION', '4.2.1');
define('UserFrosting\DS', '/');
define('UserFrosting\PHP_MIN_VERSION', '5.6');
define('UserFrosting\PHP_RECOMMENDED_VERSION', '7.1');
Expand Down
2 changes: 1 addition & 1 deletion app/sprinkles/account/locale/it_IT/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,5 @@
'USER_OR_EMAIL_INVALID' => "L'indirizzo mail o il nome utente non sono validi",
'USER_OR_PASS_INVALID' => 'Il nome utente o la password non sono validi',

'WELCOME' => 'Bentornato, {{display_name}}'
'WELCOME' => 'Bentornato, {{first_name}}'
];
8 changes: 4 additions & 4 deletions app/sprinkles/account/src/Account/Registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ public function validate()

// Check if username is unique
if (!$this->usernameIsUnique($this->userdata['user_name'])) {
$e = new HttpException();
$e->addUserMessage('USERNAME.IN_USE');
$e = new HttpException('Username is already in use.');
$e->addUserMessage('USERNAME.IN_USE', ['user_name' => $this->userdata['user_name']]);
throw $e;
}

// Check if email is unique
if (!$this->emailIsUnique($this->userdata['email'])) {
$e = new HttpException();
$e->addUserMessage('EMAIL.IN_USE');
$e = new HttpException('Email is already in use.');
$e->addUserMessage('EMAIL.IN_USE', ['email' => $this->userdata['email']]);
throw $e;
}

Expand Down
44 changes: 38 additions & 6 deletions app/sprinkles/account/src/Controller/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,12 +509,22 @@ public function pageRegister(Request $request, Response $response, $args)
// Get locale information
$currentLocales = $localePathBuilder->getLocales();

// Hide the locale field if there is only 1 locale available
$fields = [
'hidden' => [],
'disabled' => []
];
if (count($config->getDefined('site.locales.available')) <= 1) {
$fields['hidden'][] = 'locale';
}

return $this->ci->view->render($response, 'pages/register.html.twig', [
'page' => [
'validators' => [
'register' => $validatorRegister->rules('json', false)
]
],
'fields' => $fields,
'locales' => [
'available' => $config['site.locales.available'],
'current' => end($currentLocales)
Expand Down Expand Up @@ -658,8 +668,18 @@ public function pageSettings(Request $request, Response $response, $args)
// Get a list of all locales
$locales = $config->getDefined('site.locales.available');

// Hide the locale field if there is only 1 locale available
$fields = [
'hidden' => [],
'disabled' => []
];
if (count($config->getDefined('site.locales.available')) <= 1) {
$fields['hidden'][] = 'locale';
}

return $this->ci->view->render($response, 'pages/account-settings.html.twig', [
'locales' => $locales,
'fields' => $fields,
'page' => [
'validators' => [
'account_settings' => $validatorAccountSettings->rules('json', false),
Expand Down Expand Up @@ -766,6 +786,11 @@ public function profile(Request $request, Response $response, $args)

$error = false;

// Ensure that in the case of using a single locale, that the locale is set
if (count($config->getDefined('site.locales.available')) <= 1) {
$data['locale'] = $currentUser->locale;
}

// Validate, and halt on validation errors.
$validator = new ServerSideValidator($schema, $this->ci->translator);
if (!$validator->validate($data)) {
Expand Down Expand Up @@ -877,6 +902,11 @@ public function register(Request $request, Response $response, $args)

$error = false;

// Ensure that in the case of using a single locale, that the locale is set
if (count($config->getDefined('site.locales.available')) <= 1) {
$data['locale'] = $config['site.registration.user_defaults.locale'];
}

// Validate request data
$validator = new ServerSideValidator($schema, $this->ci->translator);
if (!$validator->validate($data)) {
Expand Down Expand Up @@ -913,12 +943,9 @@ public function register(Request $request, Response $response, $args)
// Now that we check the form, we can register the actual user
$registration = new Registration($this->ci, $data);

try {
$user = $registration->register();
} catch (\Exception $e) {
$ms->addMessageTranslated('danger', $e->getMessage(), $data);
$error = true;
}
// Try registration. An HttpException will be thrown if it fails
// No need to catch, as this kind of exception will automatically returns the addMessageTranslated
$user = $registration->register();

// Success message
if ($config['site.registration.require_email_verification']) {
Expand Down Expand Up @@ -1163,6 +1190,11 @@ public function settings(Request $request, Response $response, $args)

$error = false;

// Ensure that in the case of using a single locale, that the locale is set
if (count($config->getDefined('site.locales.available')) <= 1) {
$data['locale'] = $currentUser->locale;
}

// Validate, and halt on validation errors.
$validator = new ServerSideValidator($schema, $this->ci->translator);
if (!$validator->validate($data)) {
Expand Down
13 changes: 7 additions & 6 deletions app/sprinkles/account/src/Database/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,18 @@ public function delete($hardDelete = false)
// Remove all role associations
$this->roles()->detach();

// Remove all user activities
$classMapper->staticMethod('activity', 'where', 'user_id', $this->id)->delete();
// Remove last activity association
$this->lastActivity()->dissociate();
$this->save();

// Remove all user tokens
$classMapper->staticMethod('password_reset', 'where', 'user_id', $this->id)->delete();
$this->activities()->delete();
$this->passwordResets()->delete();
$classMapper->staticMethod('verification', 'where', 'user_id', $this->id)->delete();

// TODO: remove any persistences
$classMapper->staticMethod('persistence', 'where', 'user_id', $this->id)->delete();

// Delete the user
$result = parent::forceDelete();
$result = $this->forceDelete();
} else {
// Soft delete the user, leaving all associated records alone
$result = parent::delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function write(array $record)

if (isset($record['extra']['user_id'])) {
$user = $this->classMapper->staticMethod('user', 'find', $record['extra']['user_id']);
$user->last_activity_id = $log->id;
$user->lastActivity()->associate($log);
$user->save();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace UserFrosting\Sprinkle\Account\Repository;

use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface;
use UserFrosting\Sprinkle\Account\Facades\Password;

/**
Expand All @@ -27,7 +28,7 @@ class PasswordResetRepository extends TokenRepository
/**
* {@inheritdoc}
*/
protected function updateUser($user, $args)
protected function updateUser(UserInterface $user, $args)
{
$user->password = Password::hash($args['password']);
// TODO: generate user activity? or do this in controller?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace UserFrosting\Sprinkle\Account\Repository;

use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface;

/**
* Token repository class for new account verifications.
*
Expand All @@ -25,7 +27,7 @@ class VerificationRepository extends TokenRepository
/**
* {@inheritdoc}
*/
protected function updateUser($user, $args)
protected function updateUser(UserInterface $user, $args)
{
$user->flag_verified = 1;
// TODO: generate user activity? or do this in controller?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function register(ContainerInterface $container)
$classMapper->setClassMapping('activity', 'UserFrosting\Sprinkle\Account\Database\Models\Activity');
$classMapper->setClassMapping('password_reset', 'UserFrosting\Sprinkle\Account\Database\Models\PasswordReset');
$classMapper->setClassMapping('verification', 'UserFrosting\Sprinkle\Account\Database\Models\Verification');
$classMapper->setClassMapping('persistence', 'UserFrosting\Sprinkle\Account\Database\Models\Persistence');

return $classMapper;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
</div>
</div>

{% if 'locale' not in fields.hidden %}
<div class="form-group">
<label for="input-locale" class="control-label">{{translate("LOCALE")}}</label>
<select id="input-locale" class="form-control js-select2" name="locale" {{page.visibility}}>
Expand All @@ -31,6 +32,7 @@
</select>
<p class="help-block">{{translate("LOCALE.ACCOUNT")}}.</p>
</div>
{% endif %}
{% endblock %}
</div>
<div class="box-footer text-center">
Expand Down
2 changes: 2 additions & 0 deletions app/sprinkles/account/templates/pages/register.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<label class="sr-only" for="r-form-passwordc">{{translate('PASSWORD.CONFIRM')}}</label>
<input type="password" name="passwordc" placeholder="{{translate('PASSWORD.CONFIRM')}}" class="form-control" id="r-form-passwordc">
</div>
{% if 'locale' not in fields.hidden %}
<div class="form-group">
<label for="r-form-locale" class="control-label">{{translate("LOCALE")}}</label>
<select id="r-form-locale" class="form-control js-select2" name="locale">
Expand All @@ -64,6 +65,7 @@
</select>
<p class="help-block">{{translate("LOCALE.ACCOUNT")}}.</p>
</div>
{% endif %}
{% if site.registration.captcha %}
<div class="form-group">
<label class="sr-only" for="r-form-passwordc">{{translate('CAPTCHA.VERIFY')}}</label>
Expand Down
51 changes: 51 additions & 0 deletions app/sprinkles/account/tests/Integration/AuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
use UserFrosting\Sprinkle\Account\Authenticate\Authenticator;
use UserFrosting\Sprinkle\Account\Facades\Password;
use UserFrosting\Sprinkle\Account\Tests\withTestUser;
use UserFrosting\Sprinkle\Core\Database\Models\Session as SessionTable;
use UserFrosting\Sprinkle\Core\Tests\TestDatabase;
use UserFrosting\Sprinkle\Core\Tests\RefreshDatabase;
use UserFrosting\Sprinkle\Core\Tests\withDatabaseSessionHandler;
use UserFrosting\Tests\TestCase;

/**
Expand All @@ -26,6 +28,7 @@ class AuthenticatorTest extends TestCase
use TestDatabase;
use RefreshDatabase;
use withTestUser;
use withDatabaseSessionHandler;

/**
* Setup the test database.
Expand Down Expand Up @@ -80,6 +83,54 @@ public function testLogin(Authenticator $authenticator)
$this->assertNotSame($testUser->id, $this->ci->session[$key]);
}

/**
* @depends testConstructor
* @param Authenticator $authenticator
*/
public function testLoginWithSessionDatabase(Authenticator $authenticator)
{
// Reset CI Session
$this->useDatabaseSessionHandler();

// Create a test user
$testUser = $this->createTestUser();

// Check the table
$this->assertSame(0, SessionTable::count());

// Test session to avoid false positive
$key = $this->ci->config['session.keys.current_user_id'];
$this->assertNull($this->ci->session[$key]);
$this->assertNotSame($testUser->id, $this->ci->session[$key]);

// Login the test user
$authenticator->login($testUser, false);

// Test session to see if user was logged in
$this->assertNotNull($this->ci->session[$key]);
$this->assertSame($testUser->id, $this->ci->session[$key]);

// Close session to initiate write
session_write_close();

// Check the table again
$this->assertSame(1, SessionTable::count());

// Reopen session
$this->ci->session->start();

// Must logout to avoid test issue
$authenticator->logout(true);

// We'll test the logout system works too while we're at it (and depend on it)
$key = $this->ci->config['session.keys.current_user_id'];
$this->assertNull($this->ci->session[$key]);
$this->assertNotSame($testUser->id, $this->ci->session[$key]);

// Make sure table entry has been removed
$this->assertSame(0, SessionTable::count());
}

/**
* @depends testConstructor
* @expectedException \UserFrosting\Sprinkle\Account\Authenticate\Exception\AccountInvalidException
Expand Down
Loading

0 comments on commit adec2ed

Please sign in to comment.