mirror of
https://github.com/humhub/humhub.git
synced 2025-02-24 19:23:21 +01:00
Added AuthHelper::isGuestAccessEnabled()
This commit is contained in:
parent
055a5cbc28
commit
3eb5a9e002
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
namespace humhub\components\access;
|
namespace humhub\components\access;
|
||||||
|
|
||||||
|
use humhub\modules\user\helpers\AuthHelper;
|
||||||
use Yii;
|
use Yii;
|
||||||
use humhub\modules\user\models\User;
|
use humhub\modules\user\models\User;
|
||||||
use yii\base\InvalidArgumentException;
|
use yii\base\InvalidArgumentException;
|
||||||
@ -415,7 +416,7 @@ class ControllerAccess extends BaseObject
|
|||||||
*/
|
*/
|
||||||
public function validateStrictMode()
|
public function validateStrictMode()
|
||||||
{
|
{
|
||||||
return !$this->isGuest() || Yii::$app->user->isGuestAccessEnabled();
|
return !$this->isGuest() || AuthHelper::isGuestAccessEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
namespace humhub\components\access;
|
namespace humhub\components\access;
|
||||||
|
|
||||||
|
use humhub\modules\user\helpers\AuthHelper;
|
||||||
use Yii;
|
use Yii;
|
||||||
|
|
||||||
class GuestAccessValidator extends AccessValidator
|
class GuestAccessValidator extends AccessValidator
|
||||||
@ -20,7 +21,7 @@ class GuestAccessValidator extends AccessValidator
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
if ($this->access->isGuest() && !Yii::$app->user->isGuestAccessEnabled()) {
|
if ($this->access->isGuest() && !AuthHelper::isGuestAccessEnabled()) {
|
||||||
$this->code = 401;
|
$this->code = 401;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
namespace humhub\controllers;
|
namespace humhub\controllers;
|
||||||
|
|
||||||
|
use humhub\modules\user\helpers\AuthHelper;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\web\HttpException;
|
use yii\web\HttpException;
|
||||||
use yii\base\UserException;
|
use yii\base\UserException;
|
||||||
@ -48,7 +49,7 @@ class ErrorController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Show special login required view for guests
|
* Show special login required view for guests
|
||||||
*/
|
*/
|
||||||
if (Yii::$app->user->isGuest && $exception instanceof HttpException && $exception->statusCode == '401' && Yii::$app->getModule('user')->settings->get('auth.allowGuestAccess')) {
|
if (Yii::$app->user->isGuest && $exception instanceof HttpException && $exception->statusCode == '401' && AuthHelper::isGuestAccessEnabled()) {
|
||||||
return $this->render('@humhub/views/error/401_guests', ['message' => $message]);
|
return $this->render('@humhub/views/error/401_guests', ['message' => $message]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ features:
|
|||||||
if(Yii::$app->user->isGuest) {
|
if(Yii::$app->user->isGuest) {
|
||||||
//...
|
//...
|
||||||
}
|
}
|
||||||
|
use humhub\modules\user\helpers\AuthHelper;
|
||||||
if(Yii::$app->user->isGuestAccessEnabled()) {
|
if(AuthHelper::isGuestAccessEnabled()) {
|
||||||
//...
|
//...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -109,4 +109,4 @@ public static function onUserDelete(Event $event)
|
|||||||
$user = $event->sender;
|
$user = $event->sender;
|
||||||
MyRecord::deleteAll(['user_id' => $user->id]);
|
MyRecord::deleteAll(['user_id' => $user->id]);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -12,6 +12,7 @@ use humhub\modules\admin\models\forms\SpaceSettingsForm;
|
|||||||
use humhub\modules\admin\models\SpaceSearch;
|
use humhub\modules\admin\models\SpaceSearch;
|
||||||
use humhub\modules\content\models\Content;
|
use humhub\modules\content\models\Content;
|
||||||
use humhub\modules\space\models\Space;
|
use humhub\modules\space\models\Space;
|
||||||
|
use humhub\modules\user\helpers\AuthHelper;
|
||||||
use Yii;
|
use Yii;
|
||||||
use humhub\modules\admin\components\Controller;
|
use humhub\modules\admin\components\Controller;
|
||||||
use humhub\modules\admin\permissions\ManageSpaces;
|
use humhub\modules\admin\permissions\ManageSpaces;
|
||||||
@ -104,7 +105,7 @@ class SpaceController extends Controller
|
|||||||
$form = new SpaceSettingsForm;
|
$form = new SpaceSettingsForm;
|
||||||
$visibilityOptions = [];
|
$visibilityOptions = [];
|
||||||
|
|
||||||
if (Yii::$app->getModule('user')->settings->get('auth.allowGuestAccess')) {
|
if (AuthHelper::isGuestAccessEnabled()) {
|
||||||
$visibilityOptions[Space::VISIBILITY_ALL] = Yii::t('SpaceModule.base', 'Public (Members & Guests)');
|
$visibilityOptions[Space::VISIBILITY_ALL] = Yii::t('SpaceModule.base', 'Public (Members & Guests)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ Your account request has been declined.<br><br>
|
|||||||
|
|
||||||
Kind Regards<br>
|
Kind Regards<br>
|
||||||
{AdminName}<br><br>';
|
{AdminName}<br><br>';
|
||||||
|
|
||||||
public $internalAllowAnonymousRegistration;
|
public $internalAllowAnonymousRegistration;
|
||||||
public $internalRequireApprovalAfterRegistration;
|
public $internalRequireApprovalAfterRegistration;
|
||||||
public $internalUsersCanInvite;
|
public $internalUsersCanInvite;
|
||||||
@ -120,17 +120,17 @@ Kind Regards<br>
|
|||||||
if ($settingsManager->get('auth.anonymousRegistration')) {
|
if ($settingsManager->get('auth.anonymousRegistration')) {
|
||||||
$settingsManager->set('auth.showCaptureInRegisterForm', $this->showCaptureInRegisterForm);
|
$settingsManager->set('auth.showCaptureInRegisterForm', $this->showCaptureInRegisterForm);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($settingsManager->get('auth.needApproval')) {
|
if ($settingsManager->get('auth.needApproval')) {
|
||||||
if(empty($this->registrationApprovalMailContent) || (strcmp($this->registrationApprovalMailContent, Yii::t('AdminModule.controllers_ApprovalController', self::defaultRegistrationApprovalMailContent)) == 0)) {
|
if(empty($this->registrationApprovalMailContent) || (strcmp($this->registrationApprovalMailContent, Yii::t('AdminModule.controllers_ApprovalController', self::defaultRegistrationApprovalMailContent)) == 0)) {
|
||||||
$this->registrationApprovalMailContent = Yii::t('AdminModule.controllers_ApprovalController', self::defaultRegistrationApprovalMailContent);
|
$this->registrationApprovalMailContent = Yii::t('AdminModule.controllers_ApprovalController', self::defaultRegistrationApprovalMailContent);
|
||||||
$settingsManager->delete('auth.registrationApprovalMailContent');
|
$settingsManager->delete('auth.registrationApprovalMailContent');
|
||||||
} else {
|
} else {
|
||||||
$settingsManager->set('auth.registrationApprovalMailContent', $this->registrationApprovalMailContent);
|
$settingsManager->set('auth.registrationApprovalMailContent', $this->registrationApprovalMailContent);
|
||||||
}
|
}
|
||||||
if(empty($this->registrationDenialMailContent) || strcmp($this->registrationDenialMailContent, Yii::t('AdminModule.controllers_ApprovalController', self::defaultRegistrationDenialMailContent)) == 0) {
|
if(empty($this->registrationDenialMailContent) || strcmp($this->registrationDenialMailContent, Yii::t('AdminModule.controllers_ApprovalController', self::defaultRegistrationDenialMailContent)) == 0) {
|
||||||
$this->registrationDenialMailContent = Yii::t('AdminModule.controllers_ApprovalController', self::defaultRegistrationDenialMailContent);
|
$this->registrationDenialMailContent = Yii::t('AdminModule.controllers_ApprovalController', self::defaultRegistrationDenialMailContent);
|
||||||
$settingsManager->delete('auth.registrationDenialMailContent');
|
$settingsManager->delete('auth.registrationDenialMailContent');
|
||||||
} else {
|
} else {
|
||||||
$settingsManager->set('auth.registrationDenialMailContent', $this->registrationDenialMailContent);
|
$settingsManager->set('auth.registrationDenialMailContent', $this->registrationDenialMailContent);
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ namespace humhub\modules\content\components;
|
|||||||
use humhub\modules\content\models\ContentTag;
|
use humhub\modules\content\models\ContentTag;
|
||||||
use humhub\modules\content\models\ContentTagRelation;
|
use humhub\modules\content\models\ContentTagRelation;
|
||||||
use humhub\modules\space\models\Space;
|
use humhub\modules\space\models\Space;
|
||||||
|
use humhub\modules\user\helpers\AuthHelper;
|
||||||
use humhub\modules\user\models\User;
|
use humhub\modules\user\models\User;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\db\Expression;
|
use yii\db\Expression;
|
||||||
@ -76,7 +77,7 @@ class ActiveQueryContent extends \yii\db\ActiveQuery
|
|||||||
|
|
||||||
// Created content of is always visible
|
// Created content of is always visible
|
||||||
$conditionUser .= 'OR content.created_by=' . $user->id;
|
$conditionUser .= 'OR content.created_by=' . $user->id;
|
||||||
} elseif (Yii::$app->user->isGuestAccessEnabled()) {
|
} elseif (AuthHelper::isGuestAccessEnabled()) {
|
||||||
$conditionSpace = 'space.id IS NOT NULL and space.visibility=' . Space::VISIBILITY_ALL . ' AND content.visibility=1';
|
$conditionSpace = 'space.id IS NOT NULL and space.visibility=' . Space::VISIBILITY_ALL . ' AND content.visibility=1';
|
||||||
$conditionUser = 'cuser.id IS NOT NULL and cuser.visibility=' . User::VISIBILITY_ALL . ' AND content.visibility=1';
|
$conditionUser = 'cuser.id IS NOT NULL and cuser.visibility=' . User::VISIBILITY_ALL . ' AND content.visibility=1';
|
||||||
} else {
|
} else {
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
namespace humhub\modules\content\components;
|
namespace humhub\modules\content\components;
|
||||||
|
|
||||||
|
use humhub\modules\user\helpers\AuthHelper;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\web\HttpException;
|
use yii\web\HttpException;
|
||||||
use humhub\components\Controller;
|
use humhub\components\Controller;
|
||||||
@ -103,7 +104,7 @@ class ContentContainerController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Directly redirect guests to login page - if guest access isn't enabled
|
// Directly redirect guests to login page - if guest access isn't enabled
|
||||||
if (Yii::$app->user->isGuest && Yii::$app->getModule('user')->settings->get('auth.allowGuestAccess') != 1) {
|
if (Yii::$app->user->isGuest && !AuthHelper::isGuestAccessEnabled()) {
|
||||||
Yii::$app->user->loginRequired();
|
Yii::$app->user->loginRequired();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ use humhub\modules\content\permissions\CreatePublicContent;
|
|||||||
use humhub\modules\content\permissions\ManageContent;
|
use humhub\modules\content\permissions\ManageContent;
|
||||||
use humhub\modules\space\models\Space;
|
use humhub\modules\space\models\Space;
|
||||||
use humhub\modules\user\components\PermissionManager;
|
use humhub\modules\user\components\PermissionManager;
|
||||||
|
use humhub\modules\user\helpers\AuthHelper;
|
||||||
use humhub\modules\user\models\User;
|
use humhub\modules\user\models\User;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\base\Exception;
|
use yii\base\Exception;
|
||||||
@ -780,14 +781,14 @@ class Content extends ContentDeprecated implements Movable, ContentOwner
|
|||||||
* This is the case if all of the following conditions are met:
|
* This is the case if all of the following conditions are met:
|
||||||
*
|
*
|
||||||
* - The content is public
|
* - The content is public
|
||||||
* - The `auth.allowGuestAccess` module setting is enabled
|
* - The `auth.allowGuestAccess` setting is enabled
|
||||||
* - The space or profile visibility is set to VISIBILITY_ALL
|
* - The space or profile visibility is set to VISIBILITY_ALL
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function checkGuestAccess()
|
public function checkGuestAccess()
|
||||||
{
|
{
|
||||||
if (!$this->isPublic() || !Yii::$app->getModule('user')->settings->get('auth.allowGuestAccess')) {
|
if (!$this->isPublic() || !AuthHelper::isGuestAccessEnabled()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
namespace humhub\modules\space\behaviors;
|
namespace humhub\modules\space\behaviors;
|
||||||
|
|
||||||
|
use humhub\modules\user\helpers\AuthHelper;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\base\Behavior;
|
use yii\base\Behavior;
|
||||||
use yii\helpers\Json;
|
use yii\helpers\Json;
|
||||||
@ -62,7 +63,7 @@ class SpaceController extends Behavior
|
|||||||
{
|
{
|
||||||
$this->updateLastVisit();
|
$this->updateLastVisit();
|
||||||
|
|
||||||
if (Yii::$app->getModule('user')->settings->get('auth.allowGuestAccess') && Yii::$app->user->isGuest && $this->space->visibility != Space::VISIBILITY_ALL) {
|
if (AuthHelper::isGuestAccessEnabled() && Yii::$app->user->isGuest && $this->space->visibility != Space::VISIBILITY_ALL) {
|
||||||
throw new HttpException(401, Yii::t('SpaceModule.behaviors_SpaceControllerBehavior', 'You need to login to view contents of this space!'));
|
throw new HttpException(401, Yii::t('SpaceModule.behaviors_SpaceControllerBehavior', 'You need to login to view contents of this space!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ use humhub\modules\space\permissions\CreatePrivateSpace;
|
|||||||
use humhub\modules\space\permissions\CreatePublicSpace;
|
use humhub\modules\space\permissions\CreatePublicSpace;
|
||||||
use humhub\modules\space\models\forms\InviteForm;
|
use humhub\modules\space\models\forms\InviteForm;
|
||||||
use Colors\RandomColor;
|
use Colors\RandomColor;
|
||||||
|
use humhub\modules\user\helpers\AuthHelper;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\base\Exception;
|
use yii\base\Exception;
|
||||||
use yii\web\HttpException;
|
use yii\web\HttpException;
|
||||||
@ -72,7 +73,7 @@ class CreateController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$visibilityOptions = [];
|
$visibilityOptions = [];
|
||||||
if (Yii::$app->getModule('user')->settings->get('auth.allowGuestAccess') && Yii::$app->user->permissionmanager->can(new CreatePublicSpace)) {
|
if (AuthHelper::isGuestAccessEnabled() && Yii::$app->user->permissionmanager->can(new CreatePublicSpace)) {
|
||||||
$visibilityOptions[Space::VISIBILITY_ALL] = Yii::t('SpaceModule.base', 'Public (Members & Guests)');
|
$visibilityOptions[Space::VISIBILITY_ALL] = Yii::t('SpaceModule.base', 'Public (Members & Guests)');
|
||||||
}
|
}
|
||||||
if (Yii::$app->user->permissionmanager->can(new CreatePublicSpace)) {
|
if (Yii::$app->user->permissionmanager->can(new CreatePublicSpace)) {
|
||||||
|
@ -28,6 +28,7 @@ use humhub\modules\space\activities\Created;
|
|||||||
use humhub\modules\content\components\ContentContainerActiveRecord;
|
use humhub\modules\content\components\ContentContainerActiveRecord;
|
||||||
use humhub\modules\content\models\Content;
|
use humhub\modules\content\models\Content;
|
||||||
use humhub\modules\user\components\ActiveQueryUser;
|
use humhub\modules\user\components\ActiveQueryUser;
|
||||||
|
use humhub\modules\user\helpers\AuthHelper;
|
||||||
use humhub\modules\user\models\User;
|
use humhub\modules\user\models\User;
|
||||||
use humhub\modules\user\models\Follow;
|
use humhub\modules\user\models\Follow;
|
||||||
use humhub\modules\user\models\Invite;
|
use humhub\modules\user\models\Invite;
|
||||||
@ -579,7 +580,7 @@ class Space extends ContentContainerActiveRecord implements Searchable
|
|||||||
];
|
];
|
||||||
|
|
||||||
// Add guest groups if enabled
|
// Add guest groups if enabled
|
||||||
if (Yii::$app->getModule('user')->settings->get('auth.allowGuestAccess')) {
|
if (AuthHelper::isGuestAccessEnabled()) {
|
||||||
$groups[self::USERGROUP_GUEST] = 'Guests';
|
$groups[self::USERGROUP_GUEST] = 'Guests';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use humhub\modules\space\models\Space;
|
use humhub\modules\space\models\Space;
|
||||||
use humhub\modules\space\modules\manage\widgets\SecurityTabMenu;
|
use humhub\modules\space\modules\manage\widgets\SecurityTabMenu;
|
||||||
|
use humhub\modules\user\helpers\AuthHelper;
|
||||||
use humhub\widgets\DataSaved;
|
use humhub\widgets\DataSaved;
|
||||||
use yii\bootstrap\ActiveForm;
|
use yii\bootstrap\ActiveForm;
|
||||||
use yii\helpers\Html;
|
use yii\helpers\Html;
|
||||||
@ -26,7 +27,7 @@ use yii\helpers\Html;
|
|||||||
Space::VISIBILITY_NONE => Yii::t('SpaceModule.base', 'Private (Invisible)'),
|
Space::VISIBILITY_NONE => Yii::t('SpaceModule.base', 'Private (Invisible)'),
|
||||||
Space::VISIBILITY_REGISTERED_ONLY => Yii::t('SpaceModule.base', 'Public (Registered users only)')
|
Space::VISIBILITY_REGISTERED_ONLY => Yii::t('SpaceModule.base', 'Public (Registered users only)')
|
||||||
];
|
];
|
||||||
if (Yii::$app->getModule('user')->settings->get('auth.allowGuestAccess') == 1) {
|
if (AuthHelper::isGuestAccessEnabled()) {
|
||||||
$visibilities[Space::VISIBILITY_ALL] = Yii::t('SpaceModule.base', 'Visible for all (members and guests)');
|
$visibilities[Space::VISIBILITY_ALL] = Yii::t('SpaceModule.base', 'Visible for all (members and guests)');
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
namespace humhub\modules\user\behaviors;
|
namespace humhub\modules\user\behaviors;
|
||||||
|
|
||||||
|
use humhub\modules\user\helpers\AuthHelper;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\base\Behavior;
|
use yii\base\Behavior;
|
||||||
use yii\web\HttpException;
|
use yii\web\HttpException;
|
||||||
@ -16,9 +17,9 @@ use humhub\components\Controller;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* ProfileController Behavior
|
* ProfileController Behavior
|
||||||
*
|
*
|
||||||
* In User container scopes, this behavior will automatically attached to a contentcontainer controller.
|
* In User container scopes, this behavior will automatically attached to a contentcontainer controller.
|
||||||
*
|
*
|
||||||
* @see User::controllerBehavior
|
* @see User::controllerBehavior
|
||||||
* @see \humhub\modules\contentcontainer\components\Controller
|
* @see \humhub\modules\contentcontainer\components\Controller
|
||||||
* @property \humhub\modules\contentcontainer\components\Controller $owner the controller
|
* @property \humhub\modules\contentcontainer\components\Controller $owner the controller
|
||||||
@ -56,7 +57,7 @@ class ProfileController extends Behavior
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return type
|
* @return type
|
||||||
*/
|
*/
|
||||||
public function getUser()
|
public function getUser()
|
||||||
@ -74,7 +75,7 @@ class ProfileController extends Behavior
|
|||||||
throw new HttpException(404, Yii::t('UserModule.behaviors_ProfileControllerBehavior', 'This profile is no longer available!'));
|
throw new HttpException(404, Yii::t('UserModule.behaviors_ProfileControllerBehavior', 'This profile is no longer available!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Yii::$app->getModule('user')->settings->get('auth.allowGuestAccess') && $this->user->visibility != User::VISIBILITY_ALL && Yii::$app->user->isGuest) {
|
if (AuthHelper::isGuestAccessEnabled() && $this->user->visibility != User::VISIBILITY_ALL && Yii::$app->user->isGuest) {
|
||||||
throw new HttpException(401, Yii::t('UserModule.behaviors_ProfileControllerBehavior', 'You need to login to view this user profile!'));
|
throw new HttpException(401, Yii::t('UserModule.behaviors_ProfileControllerBehavior', 'You need to login to view this user profile!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ use humhub\modules\user\authclient\AuthClientHelpers;
|
|||||||
use humhub\modules\user\authclient\Password;
|
use humhub\modules\user\authclient\Password;
|
||||||
use humhub\modules\user\authclient\interfaces\AutoSyncUsers;
|
use humhub\modules\user\authclient\interfaces\AutoSyncUsers;
|
||||||
use humhub\modules\user\events\UserEvent;
|
use humhub\modules\user\events\UserEvent;
|
||||||
|
use humhub\modules\user\helpers\AuthHelper;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\authclient\ClientInterface;
|
use yii\authclient\ClientInterface;
|
||||||
use yii\db\Expression;
|
use yii\db\Expression;
|
||||||
@ -84,8 +85,8 @@ class User extends \yii\web\User
|
|||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @param string|string[]|BasePermission $permission
|
* @param string|string[]|BasePermission $permission
|
||||||
* @see PermissionManager::can()
|
|
||||||
* @return boolean
|
* @return boolean
|
||||||
|
* @see PermissionManager::can()
|
||||||
* @since 1.2
|
* @since 1.2
|
||||||
*/
|
*/
|
||||||
public function can($permission, $params = [], $allowCaching = true)
|
public function can($permission, $params = [], $allowCaching = true)
|
||||||
@ -201,10 +202,11 @@ class User extends \yii\web\User
|
|||||||
* Checks if the system configuration allows access for guests
|
* Checks if the system configuration allows access for guests
|
||||||
*
|
*
|
||||||
* @return boolean is guest access enabled and allowed
|
* @return boolean is guest access enabled and allowed
|
||||||
|
* @deprecated since 1.4
|
||||||
*/
|
*/
|
||||||
public static function isGuestAccessEnabled()
|
public static function isGuestAccessEnabled()
|
||||||
{
|
{
|
||||||
return (Yii::$app->getModule('user')->settings->get('auth.allowGuestAccess'));
|
return AuthHelper::isGuestAccessEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
namespace humhub\modules\user\controllers;
|
namespace humhub\modules\user\controllers;
|
||||||
|
|
||||||
|
use humhub\modules\user\helpers\AuthHelper;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\web\HttpException;
|
use yii\web\HttpException;
|
||||||
use humhub\modules\user\components\BaseAccountController;
|
use humhub\modules\user\components\BaseAccountController;
|
||||||
@ -143,7 +144,7 @@ class AccountController extends BaseAccountController
|
|||||||
public function actionSecurity()
|
public function actionSecurity()
|
||||||
{
|
{
|
||||||
$groups = [];
|
$groups = [];
|
||||||
$groupAccessEnabled = (boolean) Yii::$app->getModule('user')->settings->get('auth.allowGuestAccess');
|
$groupAccessEnabled = AuthHelper::isGuestAccessEnabled();
|
||||||
|
|
||||||
if (Yii::$app->getModule('friendship')->getIsEnabled()) {
|
if (Yii::$app->getModule('friendship')->getIsEnabled()) {
|
||||||
$groups[User::USERGROUP_FRIEND] = Yii::t('UserModule.account', 'Your friends');
|
$groups[User::USERGROUP_FRIEND] = Yii::t('UserModule.account', 'Your friends');
|
||||||
|
41
protected/humhub/modules/user/helpers/AuthHelper.php
Normal file
41
protected/humhub/modules/user/helpers/AuthHelper.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @link https://www.humhub.org/
|
||||||
|
* @copyright Copyright (c) 2015 HumHub GmbH & Co. KG
|
||||||
|
* @license https://www.humhub.com/licences
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace humhub\modules\user\helpers;
|
||||||
|
|
||||||
|
|
||||||
|
use humhub\modules\user\Module;
|
||||||
|
use Yii;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class AuthHelper
|
||||||
|
*
|
||||||
|
* @since 1.4
|
||||||
|
* @package humhub\modules\user\helpers
|
||||||
|
*/
|
||||||
|
class AuthHelper
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if limited access is allowed for unauthenticated users.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static function isGuestAccessEnabled()
|
||||||
|
{
|
||||||
|
/** @var Module $module */
|
||||||
|
$module = Yii::$app->getModule('user');
|
||||||
|
|
||||||
|
if ($module->settings->get('auth.allowGuestAccess')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -25,6 +25,7 @@ use humhub\modules\user\behaviors\Followable;
|
|||||||
use humhub\modules\user\behaviors\ProfileController;
|
use humhub\modules\user\behaviors\ProfileController;
|
||||||
use humhub\modules\user\components\ActiveQueryUser;
|
use humhub\modules\user\components\ActiveQueryUser;
|
||||||
use humhub\modules\user\events\UserEvent;
|
use humhub\modules\user\events\UserEvent;
|
||||||
|
use humhub\modules\user\helpers\AuthHelper;
|
||||||
use humhub\modules\user\Module;
|
use humhub\modules\user\Module;
|
||||||
use humhub\modules\user\widgets\UserWall;
|
use humhub\modules\user\widgets\UserWall;
|
||||||
use Yii;
|
use Yii;
|
||||||
@ -452,7 +453,7 @@ class User extends ContentContainerActiveRecord implements IdentityInterface, Se
|
|||||||
$this->auth_mode = $passwordAuth->getId();
|
$this->auth_mode = $passwordAuth->getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Yii::$app->getModule('user')->settings->get('auth.allowGuestAccess')) {
|
if (AuthHelper::isGuestAccessEnabled()) {
|
||||||
// Set users profile default visibility to all
|
// Set users profile default visibility to all
|
||||||
if (Yii::$app->getModule('user')->settings->get('auth.defaultUserProfileVisibility') == User::VISIBILITY_ALL) {
|
if (Yii::$app->getModule('user')->settings->get('auth.defaultUserProfileVisibility') == User::VISIBILITY_ALL) {
|
||||||
$this->visibility = User::VISIBILITY_ALL;
|
$this->visibility = User::VISIBILITY_ALL;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use humhub\libs\TimezoneHelper;
|
use humhub\libs\TimezoneHelper;
|
||||||
|
use humhub\modules\user\helpers\AuthHelper;
|
||||||
use yii\widgets\ActiveForm;
|
use yii\widgets\ActiveForm;
|
||||||
use \humhub\compat\CHtml;
|
use \humhub\compat\CHtml;
|
||||||
?>
|
?>
|
||||||
@ -17,7 +18,7 @@ use \humhub\compat\CHtml;
|
|||||||
|
|
||||||
<?= $form->field($model, 'timeZone')->dropDownList(TimezoneHelper::generateList(), ['data-ui-select2' => '']); ?>
|
<?= $form->field($model, 'timeZone')->dropDownList(TimezoneHelper::generateList(), ['data-ui-select2' => '']); ?>
|
||||||
|
|
||||||
<?php if (Yii::$app->getModule('user')->settings->get('auth.allowGuestAccess')): ?>
|
<?php if (AuthHelper::isGuestAccessEnabled()): ?>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
echo $form->field($model, 'visibility')->dropDownList([
|
echo $form->field($model, 'visibility')->dropDownList([
|
||||||
|
Loading…
x
Reference in New Issue
Block a user