Merge remote-tracking branch 'upstream/master' into password_expiration

This commit is contained in:
Lorenzo Milesi
2018-01-30 22:16:03 +01:00
81 changed files with 917 additions and 538 deletions

View File

@ -108,7 +108,7 @@ abstract class AbstractAuthItem extends Model
}
},
'when' => function () {
return $this->scenario == 'create' || $this->item->name != $this->name;
return $this->scenario === 'create' || $this->item->name !== $this->name;
},
],
['children', RbacItemsValidator::class],

View File

@ -20,6 +20,8 @@ use DateTime;
use DateTimeZone;
use Exception;
use Yii;
use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
use yii\db\ActiveRecord;
/**
@ -41,6 +43,9 @@ class Profile extends ActiveRecord
/**
* {@inheritdoc}
*
* @throws InvalidParamException
* @throws InvalidConfigException
*/
public function beforeSave($insert)
{
@ -64,6 +69,8 @@ class Profile extends ActiveRecord
/**
* {@inheritdoc}
*
* @throws InvalidConfigException
*/
public function rules()
{
@ -122,6 +129,8 @@ class Profile extends ActiveRecord
* Set the User's timezone.
*
* @param DateTimeZone $timezone
*
* @throws InvalidParamException
*/
public function setTimeZone(DateTimeZone $timezone)
{
@ -141,6 +150,7 @@ class Profile extends ActiveRecord
}
/**
* @throws InvalidConfigException
* @return \yii\db\ActiveQuery
*/
public function getUser()
@ -151,6 +161,7 @@ class Profile extends ActiveRecord
/**
* @param int $size
*
* @throws InvalidConfigException
* @return mixed
*/
public function getAvatarUrl($size = 200)

View File

@ -15,6 +15,8 @@ use Da\User\Query\SocialNetworkAccountQuery;
use Da\User\Traits\ContainerAwareTrait;
use Da\User\Traits\ModuleAwareTrait;
use Yii;
use yii\base\Exception;
use yii\base\InvalidParamException;
use yii\db\ActiveRecord;
use yii\helpers\Url;
@ -55,7 +57,7 @@ class SocialNetworkAccount extends ActiveRecord
*/
public function getIsConnected()
{
return $this->user_id != null;
return null !== $this->user_id;
}
/**
@ -71,6 +73,8 @@ class SocialNetworkAccount extends ActiveRecord
}
/**
* @throws Exception
* @throws InvalidParamException
* @return string the connection url
*/
public function getConnectionUrl()

View File

@ -16,6 +16,8 @@ use Da\User\Query\TokenQuery;
use Da\User\Traits\ContainerAwareTrait;
use Da\User\Traits\ModuleAwareTrait;
use RuntimeException;
use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
use yii\db\ActiveRecord;
use yii\helpers\Url;
@ -49,6 +51,9 @@ class Token extends ActiveRecord
/**
* {@inheritdoc}
*
* @throws InvalidParamException
* @throws InvalidConfigException
*/
public function beforeSave($insert)
{
@ -86,6 +91,7 @@ class Token extends ActiveRecord
}
/**
* @throws InvalidParamException
* @return string
*/
public function getUrl()
@ -94,16 +100,17 @@ class Token extends ActiveRecord
}
/**
* @throws RuntimeException
* @return bool Whether token has expired
*/
public function getIsExpired()
{
if ($this->type == static::TYPE_RECOVERY) {
if ($this->type === static::TYPE_RECOVERY) {
$expirationTime = $this->getModule()->tokenRecoveryLifespan;
} elseif ($this->type >= static::TYPE_CONFIRMATION && $this->type <= static::TYPE_CONFIRM_OLD_EMAIL) {
$expirationTime = $this->getModule()->tokenConfirmationLifespan;
} else {
throw new RuntimeException();
throw new RuntimeException('Unknown Token type.');
}
return ($this->created_at + $expirationTime) < time();

View File

@ -16,6 +16,9 @@ use Da\User\Query\UserQuery;
use Da\User\Traits\ContainerAwareTrait;
use Da\User\Traits\ModuleAwareTrait;
use Yii;
use yii\base\Exception;
use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
@ -74,6 +77,10 @@ class User extends ActiveRecord implements IdentityInterface
/**
* {@inheritdoc}
*
* @throws InvalidParamException
* @throws InvalidConfigException
* @throws Exception
*/
public function beforeSave($insert)
{
@ -99,6 +106,8 @@ class User extends ActiveRecord implements IdentityInterface
/**
* @inheritdoc
*
* @throws InvalidConfigException
*/
public function afterSave($insert, $changedAttributes)
{
@ -245,6 +254,7 @@ class User extends ActiveRecord implements IdentityInterface
}
/**
* @throws InvalidConfigException
* @return bool whether the user is an admin or not
*/
public function getIsAdmin()
@ -274,6 +284,8 @@ class User extends ActiveRecord implements IdentityInterface
}
/**
* @throws InvalidConfigException
* @throws InvalidParamException
* @return \yii\db\ActiveQuery
*/
public function getProfile()
@ -282,11 +294,13 @@ class User extends ActiveRecord implements IdentityInterface
}
/**
* @throws \Exception
* @return SocialNetworkAccount[] social connected accounts [ 'providerName' => socialAccountModel ]
*
*/
public function getSocialNetworkAccounts()
{
if ($this->connectedAccounts == null) {
if (null === $this->connectedAccounts) {
/** @var SocialNetworkAccount[] $accounts */
$accounts = $this->hasMany(
$this->getClassMap()
@ -313,6 +327,8 @@ class User extends ActiveRecord implements IdentityInterface
/**
* {@inheritdoc}
*
* @throws NotSupportedException
*/
public static function findIdentityByAccessToken($token, $type = null)
{