Fix user approving/declining (#5737)

Co-authored-by: Lucas Bartholemy <luke-@users.noreply.github.com>
This commit is contained in:
Yuriy Bakhtin 2022-06-09 14:32:55 +03:00 committed by GitHub
parent 418f862f3d
commit be2b8f1f73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 25 deletions

View File

@ -3,6 +3,7 @@ HumHub Changelog
1.11.3 (Unreleased)
---------------------
- Fix: #5736: Fix status message on user approval
- Fix #5734: Fix error message when uninstall module and module folder is not writable
- Fix #5740: Fix logout action on force change password
- Fix #5735: OEmbed migration might fail with more complex Endpoint URLs

View File

@ -135,9 +135,12 @@ class ApprovalController extends Controller
{
$model = new ApproveUserForm($id);
$model->setApprovalDefaults();
if ($model->load(Yii::$app->request->post()) && $model->approve()) {
$this->view->success(Yii::t('AdminModule.user', 'The registration was approved and the user was notified by email.'));
return $this->redirect(['index']);
if ($model->load(Yii::$app->request->post())) {
if ($model->approve()) {
$this->view->success(Yii::t('AdminModule.user', 'The registration was approved and the user was notified by email.'));
return $this->redirect(['index']);
}
$this->view->error(Yii::t('AdminModule.user', 'Could not approve the user!'));
}
return $this->render('approve', [
@ -157,9 +160,12 @@ class ApprovalController extends Controller
{
$model = new ApproveUserForm($id);
$model->setDeclineDefaults();
if ($model->load(Yii::$app->request->post()) && $model->decline()) {
$this->view->success(Yii::t('AdminModule.user', 'The registration was declined and the user was notified by email.'));
return $this->redirect(['index']);
if ($model->load(Yii::$app->request->post())) {
if ($model->decline()) {
$this->view->success(Yii::t('AdminModule.user', 'The registration was declined and the user was notified by email.'));
return $this->redirect(['index']);
}
$this->view->error(Yii::t('AdminModule.user', 'Could not decline the user!'));
}
return $this->render('decline', [

View File

@ -146,21 +146,22 @@ class ApproveUserForm extends \yii\base\Model
* Approves user by sending approval mail and updating user status and running initial approval logic.
* @return bool
*/
public function approve()
public function approve(): bool
{
if (!$this->message) {
$this->setApprovalDefaults();
}
if (!$this->validate()) {
return false;
$this->user->status = User::STATUS_ENABLED;
if ($this->validate() &&
$this->user->save() &&
$this->send()) {
$this->user->setUpApproved();
return true;
}
$this->send();
$this->user->status = User::STATUS_ENABLED;
$this->user->save();
$this->user->setUpApproved();
return true;
return false;
}
/**
@ -169,19 +170,15 @@ class ApproveUserForm extends \yii\base\Model
* @throws \Throwable
* @throws \yii\db\StaleObjectException
*/
public function decline()
public function decline(): bool
{
if (!$this->message) {
$this->setDeclineDefaults();
}
if (!$this->validate()) {
return false;
}
$this->send();
$this->user->delete();
return true;
return $this->validate() &&
$this->send() &&
$this->user->delete();
}
/**
@ -221,16 +218,16 @@ class ApproveUserForm extends \yii\base\Model
}
/**
* @return void
* @return bool
*/
public function send()
public function send(): bool
{
$mail = Yii::$app->mailer->compose(['html' => '@humhub/views/mail/TextOnly'], [
'message' => RichTextToEmailHtmlConverter::process($this->message)
]);
$mail->setTo($this->user->email);
$mail->setSubject($this->subject);
$mail->send();
return $mail->send();
}
/**