Fix empty password (#7025)

This commit is contained in:
Yuriy Bakhtin 2024-05-23 14:56:24 +02:00 committed by GitHub
parent 49bd25f022
commit a0bc4085e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 38 additions and 0 deletions

View File

@ -33,6 +33,7 @@ HumHub Changelog
- Fix #7021: Image cropping: prevent vertical images from being displayed higher than the browser window
- Fix #7007: Allow resetting of people filters
- Fix #7023: Fix `Unsupported configuration type: object` Exception when running `php yii` on fresh installation
- Fix #7025: Fix empty password
1.16.0-beta.2 (April 9, 2024)
-----------------------------

View File

@ -0,0 +1,31 @@
<?php
use humhub\modules\user\models\Password;
use yii\db\Expression;
use yii\db\Migration;
/**
* Class m240523_081438_fix_null_password
*/
class m240523_081438_fix_null_password extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
Password::deleteAll(['OR',
['IS', 'algorithm', new Expression('NULL')],
['IS', 'password', new Expression('NULL')]]);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
echo "m240523_081438_fix_null_password cannot be reverted.\n";
return false;
}
}

View File

@ -15,6 +15,7 @@ use yii\base\ErrorException;
use yii\base\Exception;
use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
use yii\web\BadRequestHttpException;
/**
* This is the model class for table "user_password".
@ -64,6 +65,11 @@ class Password extends ActiveRecord
public function beforeSave($insert)
{
if (empty($this->password) || empty($this->algorithm)) {
Yii::error(sprintf('Stop saving of empty password for user #%s', $this->user_id), 'user');
throw new BadRequestHttpException(Yii::t('UserModule.base', 'Empty password cannot be saved!'));
}
$this->created_at = date('Y-m-d H:i:s');
return parent::beforeSave($insert);