first commit
This commit is contained in:
20
common/classes/Debug.php
Normal file
20
common/classes/Debug.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace common\classes;
|
||||
|
||||
class Debug
|
||||
{
|
||||
public static function prn($content)
|
||||
{
|
||||
echo '<pre style="background: lightgray; border: 1px solid black; padding: 2px">';
|
||||
print_r($content);
|
||||
echo '</pre>';
|
||||
}
|
||||
public static function dd($content)
|
||||
{
|
||||
echo '<pre style="background: lightgray; border: 1px solid black; padding: 2px">';
|
||||
print_r($content);
|
||||
echo '</pre>';
|
||||
die();
|
||||
}
|
||||
}
|
15
common/codeception.yml
Normal file
15
common/codeception.yml
Normal file
@ -0,0 +1,15 @@
|
||||
namespace: common\tests
|
||||
actor_suffix: Tester
|
||||
paths:
|
||||
tests: tests
|
||||
output: tests/_output
|
||||
data: tests/_data
|
||||
support: tests/_support
|
||||
settings:
|
||||
bootstrap: _bootstrap.php
|
||||
colors: true
|
||||
memory_limit: 1024M
|
||||
modules:
|
||||
config:
|
||||
Yii2:
|
||||
configFile: 'config/test-local.php'
|
3
common/config/.gitignore
vendored
Normal file
3
common/config/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
main-local.php
|
||||
params-local.php
|
||||
test-local.php
|
5
common/config/bootstrap.php
Normal file
5
common/config/bootstrap.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
Yii::setAlias('@common', dirname(__DIR__));
|
||||
Yii::setAlias('@frontend', dirname(dirname(__DIR__)) . '/frontend');
|
||||
Yii::setAlias('@backend', dirname(dirname(__DIR__)) . '/backend');
|
||||
Yii::setAlias('@console', dirname(dirname(__DIR__)) . '/console');
|
37
common/config/main.php
Normal file
37
common/config/main.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
return [
|
||||
'aliases' => [
|
||||
'@bower' => '@vendor/bower-asset',
|
||||
'@npm' => '@vendor/npm-asset',
|
||||
],
|
||||
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
|
||||
'components' => [
|
||||
'cache' => [
|
||||
'class' => 'yii\caching\FileCache',
|
||||
],
|
||||
],
|
||||
'controllerMap' => [
|
||||
'elfinder' => [
|
||||
'class' => 'mihaildev\elfinder\Controller',
|
||||
'access' => ['@', '?'],
|
||||
'disabledCommands' => ['netmount'],
|
||||
'roots' => [
|
||||
[
|
||||
'baseUrl' => '',
|
||||
'basePath' => '@frontend/web',
|
||||
'path' => 'media/upload',
|
||||
'name' => 'Изображения',
|
||||
],
|
||||
],
|
||||
'watermark' => [
|
||||
'source' => __DIR__ . '/logo.png', // Path to Water mark image
|
||||
'marginRight' => 5, // Margin right pixel
|
||||
'marginBottom' => 5, // Margin bottom pixel
|
||||
'quality' => 95, // JPEG image save quality
|
||||
'transparency' => 70, // Water mark image transparency ( other than PNG )
|
||||
'targetType' => IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP, // Target image formats ( bit-field )
|
||||
'targetMinPixel' => 200 // Target image minimum pixel size
|
||||
]
|
||||
]
|
||||
],
|
||||
];
|
6
common/config/params.php
Normal file
6
common/config/params.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
return [
|
||||
'adminEmail' => 'admin@example.com',
|
||||
'supportEmail' => 'support@example.com',
|
||||
'user.passwordResetTokenExpire' => 3600,
|
||||
];
|
14
common/config/test.php
Normal file
14
common/config/test.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
return [
|
||||
'id' => 'app-common-tests',
|
||||
'basePath' => dirname(__DIR__),
|
||||
'components' => [
|
||||
'user' => [
|
||||
'class' => 'yii\web\User',
|
||||
'identityClass' => 'common\models\User',
|
||||
],
|
||||
'request' => [
|
||||
'cookieValidationKey' => 'test',
|
||||
],
|
||||
],
|
||||
];
|
9
common/fixtures/UserFixture.php
Normal file
9
common/fixtures/UserFixture.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace common\fixtures;
|
||||
|
||||
use yii\test\ActiveFixture;
|
||||
|
||||
class UserFixture extends ActiveFixture
|
||||
{
|
||||
public $modelClass = 'common\models\User';
|
||||
}
|
22
common/mail/layouts/html.php
Normal file
22
common/mail/layouts/html.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var $this \yii\web\View view component instance */
|
||||
/* @var $message \yii\mail\MessageInterface the message being composed */
|
||||
/* @var $content string main view render result */
|
||||
?>
|
||||
<?php $this->beginPage() ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=<?= Yii::$app->charset ?>" />
|
||||
<title><?= Html::encode($this->title) ?></title>
|
||||
<?php $this->head() ?>
|
||||
</head>
|
||||
<body>
|
||||
<?php $this->beginBody() ?>
|
||||
<?= $content ?>
|
||||
<?php $this->endBody() ?>
|
||||
</body>
|
||||
</html>
|
||||
<?php $this->endPage() ?>
|
14
common/mail/layouts/text.php
Normal file
14
common/mail/layouts/text.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/** @var \yii\web\View $this view component instance */
|
||||
/** @var \yii\mail\MessageInterface $message the message being composed */
|
||||
/** @var string $content main view render result */
|
||||
?>
|
||||
|
||||
<?php $this->beginPage() ?>
|
||||
<?php $this->beginBody() ?>
|
||||
<?= $content ?>
|
||||
<?php $this->endBody() ?>
|
||||
<?php $this->endPage() ?>
|
15
common/mail/passwordResetToken-html.php
Normal file
15
common/mail/passwordResetToken-html.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $user common\models\User */
|
||||
|
||||
$resetLink = Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]);
|
||||
?>
|
||||
<div class="password-reset">
|
||||
<p>Hello <?= Html::encode($user->username) ?>,</p>
|
||||
|
||||
<p>Follow the link below to reset your password:</p>
|
||||
|
||||
<p><?= Html::a(Html::encode($resetLink), $resetLink) ?></p>
|
||||
</div>
|
12
common/mail/passwordResetToken-text.php
Normal file
12
common/mail/passwordResetToken-text.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $user common\models\User */
|
||||
|
||||
$resetLink = Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]);
|
||||
?>
|
||||
Hello <?= $user->username ?>,
|
||||
|
||||
Follow the link below to reset your password:
|
||||
|
||||
<?= $resetLink ?>
|
66
common/models/AdditionalFields.php
Normal file
66
common/models/AdditionalFields.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "additional_fields".
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
*
|
||||
* @property FieldsValue[] $fieldsValues
|
||||
* @property UseField[] $useFields
|
||||
*/
|
||||
class AdditionalFields extends \yii\db\ActiveRecord
|
||||
{
|
||||
public $use = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'additional_fields';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['name', 'use'], 'required'],
|
||||
[['name'], 'string', 'max' => 100],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'name' => 'Название',
|
||||
'use' => 'Применение',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getFieldsValues()
|
||||
{
|
||||
return $this->hasMany(FieldsValue::className(), ['field_id' => 'id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getUseFields()
|
||||
{
|
||||
return $this->hasMany(UseField::className(), ['field_id' => 'id']);
|
||||
}
|
||||
}
|
82
common/models/FieldsValue.php
Normal file
82
common/models/FieldsValue.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "fields_value".
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $card_id
|
||||
* @property int $project_id
|
||||
* @property int $field_id
|
||||
* @property string $value
|
||||
* @property int $order
|
||||
*
|
||||
* @property AdditionalFields $field
|
||||
* @property UserCard $card
|
||||
*/
|
||||
class FieldsValue extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'fields_value';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['field_id', 'value'], 'required'],
|
||||
[['card_id', 'field_id', 'order', 'project_id'], 'integer'],
|
||||
[['value'], 'string', 'max' => 255],
|
||||
[['field_id'], 'exist', 'skipOnError' => true, 'targetClass' => AdditionalFields::class, 'targetAttribute' => ['field_id' => 'id']],
|
||||
[['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::class, 'targetAttribute' => ['project_id' => 'id']],
|
||||
[['card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::class, 'targetAttribute' => ['card_id' => 'id']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'card_id' => 'Card ID',
|
||||
'field_id' => 'Field ID',
|
||||
'value' => 'Value',
|
||||
'project_id' => 'Project ID',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getField()
|
||||
{
|
||||
return $this->hasOne(AdditionalFields::class, ['id' => 'field_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getProject()
|
||||
{
|
||||
return $this->hasOne(Project::class, ['id' => 'project_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getCard()
|
||||
{
|
||||
return $this->hasOne(UserCard::class, ['id' => 'card_id']);
|
||||
}
|
||||
}
|
78
common/models/LoginForm.php
Normal file
78
common/models/LoginForm.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
|
||||
/**
|
||||
* Login form
|
||||
*/
|
||||
class LoginForm extends Model
|
||||
{
|
||||
public $username;
|
||||
public $password;
|
||||
public $rememberMe = true;
|
||||
|
||||
private $_user;
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
// username and password are both required
|
||||
[['username', 'password'], 'required'],
|
||||
// rememberMe must be a boolean value
|
||||
['rememberMe', 'boolean'],
|
||||
// password is validated by validatePassword()
|
||||
['password', 'validatePassword'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the password.
|
||||
* This method serves as the inline validation for password.
|
||||
*
|
||||
* @param string $attribute the attribute currently being validated
|
||||
* @param array $params the additional name-value pairs given in the rule
|
||||
*/
|
||||
public function validatePassword($attribute, $params)
|
||||
{
|
||||
if (!$this->hasErrors()) {
|
||||
$user = $this->getUser();
|
||||
if (!$user || !$user->validatePassword($this->password)) {
|
||||
$this->addError($attribute, 'Incorrect username or password.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs in a user using the provided username and password.
|
||||
*
|
||||
* @return bool whether the user is logged in successfully
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
if ($this->validate()) {
|
||||
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds user by [[username]]
|
||||
*
|
||||
* @return User|null
|
||||
*/
|
||||
protected function getUser()
|
||||
{
|
||||
if ($this->_user === null) {
|
||||
$this->_user = User::findByUsername($this->username);
|
||||
}
|
||||
|
||||
return $this->_user;
|
||||
}
|
||||
}
|
66
common/models/Project.php
Normal file
66
common/models/Project.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\db\Expression;
|
||||
|
||||
/**
|
||||
* This is the model class for table "project".
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $description
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
*/
|
||||
class Project extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'project';
|
||||
}
|
||||
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'class' => TimestampBehavior::class,
|
||||
'createdAtAttribute' => 'created_at',
|
||||
'updatedAtAttribute' => 'updated_at',
|
||||
'value' => new Expression('NOW()'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['name'], 'required'],
|
||||
[['description'], 'string'],
|
||||
[['created_at', 'updated_at'], 'safe'],
|
||||
[['name'], 'string', 'max' => 255],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'name' => 'Название',
|
||||
'description' => 'Описание',
|
||||
'created_at' => 'Дата создания',
|
||||
'updated_at' => 'Дата редактирования',
|
||||
];
|
||||
}
|
||||
}
|
67
common/models/ProjectUser.php
Normal file
67
common/models/ProjectUser.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "project_user".
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $card_id
|
||||
* @property int $project_id
|
||||
*
|
||||
* @property Project $project
|
||||
* @property UserCard $card
|
||||
*/
|
||||
class ProjectUser extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'project_user';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['card_id', 'project_id'], 'required'],
|
||||
[['card_id', 'project_id'], 'integer'],
|
||||
[['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']],
|
||||
[['card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['card_id' => 'id']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'card_id' => 'Card ID',
|
||||
'project_id' => 'Project ID',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getProject()
|
||||
{
|
||||
return $this->hasOne(Project::className(), ['id' => 'project_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getCard()
|
||||
{
|
||||
return $this->hasOne(UserCard::className(), ['id' => 'card_id']);
|
||||
}
|
||||
}
|
66
common/models/Status.php
Normal file
66
common/models/Status.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "status".
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
*
|
||||
* @property UseStatus[] $useStatuses
|
||||
* @property UserCard[] $userCards
|
||||
*/
|
||||
class Status extends \yii\db\ActiveRecord
|
||||
{
|
||||
public $use = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'status';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['name', 'use'], 'required'],
|
||||
[['name'], 'string', 'max' => 100],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'name' => 'Название',
|
||||
'use' => 'Применение',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getUseStatuses()
|
||||
{
|
||||
return $this->hasMany(UseStatus::class, ['status_id' => 'id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getUserCards()
|
||||
{
|
||||
return $this->hasMany(UserCard::class, ['status' => 'id']);
|
||||
}
|
||||
}
|
80
common/models/UseField.php
Normal file
80
common/models/UseField.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "use_field".
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $field_id
|
||||
* @property int $use
|
||||
*
|
||||
* @property array $statuses
|
||||
* @property string $statusesText
|
||||
*
|
||||
* @property AdditionalFields $field
|
||||
*/
|
||||
class UseField extends \yii\db\ActiveRecord
|
||||
{
|
||||
const USE_PROFILE = 0;
|
||||
const USE_PROJECT = 1;
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'use_field';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['field_id', 'use'], 'required'],
|
||||
[['field_id', 'use'], 'integer'],
|
||||
[['field_id'], 'exist', 'skipOnError' => true, 'targetClass' => AdditionalFields::className(), 'targetAttribute' => ['field_id' => 'id']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'field_id' => 'Поле',
|
||||
'use' => 'Применение',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getField()
|
||||
{
|
||||
return $this->hasOne(AdditionalFields::className(), ['id' => 'field_id']);
|
||||
}
|
||||
|
||||
public function getStatuses()
|
||||
{
|
||||
return [
|
||||
self::USE_PROFILE => 'Профиль',
|
||||
self::USE_PROJECT => 'Проект'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string status text label
|
||||
*/
|
||||
public function getStatusesText()
|
||||
{
|
||||
return $this->statuses[$this->status_id];
|
||||
}
|
||||
}
|
79
common/models/UseStatus.php
Normal file
79
common/models/UseStatus.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "use_status".
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $status_id
|
||||
* @property int $use
|
||||
*
|
||||
* @property array $statuses
|
||||
* @property string $statusesText
|
||||
*
|
||||
* @property Status $status
|
||||
*/
|
||||
class UseStatus extends \yii\db\ActiveRecord
|
||||
{
|
||||
const USE_PROFILE = 0;
|
||||
const USE_PROJECT = 1;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'use_status';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['status_id', 'use'], 'required'],
|
||||
[['status_id', 'use'], 'integer'],
|
||||
[['status_id'], 'exist', 'skipOnError' => true, 'targetClass' => Status::class, 'targetAttribute' => ['status_id' => 'id']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'status_id' => 'Статус',
|
||||
'use' => 'Применение',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->hasOne(Status::class, ['id' => 'status_id']);
|
||||
}
|
||||
|
||||
public function getStatuses()
|
||||
{
|
||||
return [
|
||||
self::USE_PROFILE => 'Профиль',
|
||||
self::USE_PROJECT => 'Проект'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string status text label
|
||||
*/
|
||||
public function getStatusesText()
|
||||
{
|
||||
return $this->statuses[$this->status_id];
|
||||
}
|
||||
}
|
189
common/models/User.php
Normal file
189
common/models/User.php
Normal file
@ -0,0 +1,189 @@
|
||||
<?php
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\NotSupportedException;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\db\ActiveRecord;
|
||||
use yii\web\IdentityInterface;
|
||||
|
||||
/**
|
||||
* User model
|
||||
*
|
||||
* @property integer $id
|
||||
* @property string $username
|
||||
* @property string $password_hash
|
||||
* @property string $password_reset_token
|
||||
* @property string $email
|
||||
* @property string $auth_key
|
||||
* @property integer $status
|
||||
* @property integer $created_at
|
||||
* @property integer $updated_at
|
||||
* @property string $password write-only password
|
||||
*/
|
||||
class User extends ActiveRecord implements IdentityInterface
|
||||
{
|
||||
const STATUS_DELETED = 0;
|
||||
const STATUS_ACTIVE = 10;
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%user}}';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
TimestampBehavior::className(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
['status', 'default', 'value' => self::STATUS_ACTIVE],
|
||||
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function findIdentity($id)
|
||||
{
|
||||
return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function findIdentityByAccessToken($token, $type = null)
|
||||
{
|
||||
throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds user by username
|
||||
*
|
||||
* @param string $username
|
||||
* @return static|null
|
||||
*/
|
||||
public static function findByUsername($username)
|
||||
{
|
||||
return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds user by password reset token
|
||||
*
|
||||
* @param string $token password reset token
|
||||
* @return static|null
|
||||
*/
|
||||
public static function findByPasswordResetToken($token)
|
||||
{
|
||||
if (!static::isPasswordResetTokenValid($token)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return static::findOne([
|
||||
'password_reset_token' => $token,
|
||||
'status' => self::STATUS_ACTIVE,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds out if password reset token is valid
|
||||
*
|
||||
* @param string $token password reset token
|
||||
* @return bool
|
||||
*/
|
||||
public static function isPasswordResetTokenValid($token)
|
||||
{
|
||||
if (empty($token)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$timestamp = (int) substr($token, strrpos($token, '_') + 1);
|
||||
$expire = Yii::$app->params['user.passwordResetTokenExpire'];
|
||||
return $timestamp + $expire >= time();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->getPrimaryKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAuthKey()
|
||||
{
|
||||
return $this->auth_key;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validateAuthKey($authKey)
|
||||
{
|
||||
return $this->getAuthKey() === $authKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates password
|
||||
*
|
||||
* @param string $password password to validate
|
||||
* @return bool if password provided is valid for current user
|
||||
*/
|
||||
public function validatePassword($password)
|
||||
{
|
||||
return Yii::$app->security->validatePassword($password, $this->password_hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates password hash from password and sets it to the model
|
||||
*
|
||||
* @param string $password
|
||||
*/
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates "remember me" authentication key
|
||||
*/
|
||||
public function generateAuthKey()
|
||||
{
|
||||
$this->auth_key = Yii::$app->security->generateRandomString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates new password reset token
|
||||
*/
|
||||
public function generatePasswordResetToken()
|
||||
{
|
||||
$this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes password reset token
|
||||
*/
|
||||
public function removePasswordResetToken()
|
||||
{
|
||||
$this->password_reset_token = null;
|
||||
}
|
||||
}
|
112
common/models/UserCard.php
Normal file
112
common/models/UserCard.php
Normal file
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\db\Expression;
|
||||
|
||||
/**
|
||||
* This is the model class for table "user_card".
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $fio
|
||||
* @property string $passport
|
||||
* @property string $photo
|
||||
* @property string $email
|
||||
* @property int $gender
|
||||
* @property string $dob
|
||||
* @property int $status
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
* @property string $resume
|
||||
*
|
||||
* @property array $genders
|
||||
* @property string $gendersText
|
||||
*
|
||||
* @property Status $status0
|
||||
*/
|
||||
class UserCard extends \yii\db\ActiveRecord
|
||||
{
|
||||
const GENDER_M = 0;
|
||||
const GENDER_W = 1;
|
||||
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'class' => TimestampBehavior::class,
|
||||
'createdAtAttribute' => 'created_at',
|
||||
'updatedAtAttribute' => 'updated_at',
|
||||
'value' => new Expression('NOW()'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'user_card';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['fio', 'status'], 'required'],
|
||||
[['status'], 'integer'],
|
||||
[['gender'], 'in', 'range' => array_keys($this->genders)],
|
||||
[['dob', 'created_at', 'updated_at'], 'safe'],
|
||||
[['fio', 'passport', 'photo', 'email', 'resume'], 'string', 'max' => 255],
|
||||
[['status'], 'exist', 'skipOnError' => true, 'targetClass' => Status::class, 'targetAttribute' => ['status' => 'id']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'fio' => 'ФИО',
|
||||
'passport' => 'Паспорт',
|
||||
'photo' => 'Фото',
|
||||
'email' => 'Email',
|
||||
'gender' => 'Пол',
|
||||
'dob' => 'Дата рождения',
|
||||
'status' => 'Статус',
|
||||
'created_at' => 'Дата создания',
|
||||
'updated_at' => 'Дата редактирование',
|
||||
'resume' => 'Резюме',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getStatus0()
|
||||
{
|
||||
return $this->hasOne(Status::class, ['id' => 'status']);
|
||||
}
|
||||
|
||||
public function getGenders()
|
||||
{
|
||||
return [
|
||||
self::GENDER_M => 'Мужчина',
|
||||
self::GENDER_W => 'Женщина'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string status text label
|
||||
*/
|
||||
public function getGendersText()
|
||||
{
|
||||
return $this->genders[$this->gender];
|
||||
}
|
||||
}
|
9
common/tests/_bootstrap.php
Normal file
9
common/tests/_bootstrap.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
defined('YII_DEBUG') or define('YII_DEBUG', true);
|
||||
defined('YII_ENV') or define('YII_ENV', 'test');
|
||||
defined('YII_APP_BASE_PATH') or define('YII_APP_BASE_PATH', __DIR__.'/../../');
|
||||
|
||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
require_once __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php';
|
||||
require __DIR__ . '/../config/bootstrap.php';
|
||||
|
14
common/tests/_data/user.php
Normal file
14
common/tests/_data/user.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
'username' => 'bayer.hudson',
|
||||
'auth_key' => 'HP187Mvq7Mmm3CTU80dLkGmni_FUH_lR',
|
||||
//password_0
|
||||
'password_hash' => '$2y$13$EjaPFBnZOQsHdGuHI.xvhuDp1fHpo8hKRSk6yshqa9c5EG8s3C3lO',
|
||||
'password_reset_token' => 'ExzkCOaYc1L8IOBs4wdTGGbgNiG3Wz1I_1402312317',
|
||||
'created_at' => '1402312317',
|
||||
'updated_at' => '1402312317',
|
||||
'email' => 'nicole.paucek@schultz.info',
|
||||
],
|
||||
];
|
2
common/tests/_output/.gitignore
vendored
Normal file
2
common/tests/_output/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
1
common/tests/_support/.gitignore
vendored
Normal file
1
common/tests/_support/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
_generated
|
25
common/tests/_support/UnitTester.php
Normal file
25
common/tests/_support/UnitTester.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace common\tests;
|
||||
|
||||
/**
|
||||
* Inherited Methods
|
||||
* @method void wantToTest($text)
|
||||
* @method void wantTo($text)
|
||||
* @method void execute($callable)
|
||||
* @method void expectTo($prediction)
|
||||
* @method void expect($prediction)
|
||||
* @method void amGoingTo($argumentation)
|
||||
* @method void am($role)
|
||||
* @method void lookForwardTo($achieveValue)
|
||||
* @method void comment($description)
|
||||
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class UnitTester extends \Codeception\Actor
|
||||
{
|
||||
use _generated\UnitTesterActions;
|
||||
/**
|
||||
* Define custom actions here
|
||||
*/
|
||||
}
|
7
common/tests/unit.suite.yml
Normal file
7
common/tests/unit.suite.yml
Normal file
@ -0,0 +1,7 @@
|
||||
suite_namespace: common\tests\unit
|
||||
actor: UnitTester
|
||||
bootstrap: false
|
||||
modules:
|
||||
enabled:
|
||||
- Yii2:
|
||||
part: fixtures
|
67
common/tests/unit/models/LoginFormTest.php
Normal file
67
common/tests/unit/models/LoginFormTest.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace common\tests\unit\models;
|
||||
|
||||
use Yii;
|
||||
use common\models\LoginForm;
|
||||
use common\fixtures\UserFixture;
|
||||
|
||||
/**
|
||||
* Login form test
|
||||
*/
|
||||
class LoginFormTest extends \Codeception\Test\Unit
|
||||
{
|
||||
/**
|
||||
* @var \common\tests\UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function _fixtures()
|
||||
{
|
||||
return [
|
||||
'user' => [
|
||||
'class' => UserFixture::className(),
|
||||
'dataFile' => codecept_data_dir() . 'user.php'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function testLoginNoUser()
|
||||
{
|
||||
$model = new LoginForm([
|
||||
'username' => 'not_existing_username',
|
||||
'password' => 'not_existing_password',
|
||||
]);
|
||||
|
||||
expect('model should not login user', $model->login())->false();
|
||||
expect('user should not be logged in', Yii::$app->user->isGuest)->true();
|
||||
}
|
||||
|
||||
public function testLoginWrongPassword()
|
||||
{
|
||||
$model = new LoginForm([
|
||||
'username' => 'bayer.hudson',
|
||||
'password' => 'wrong_password',
|
||||
]);
|
||||
|
||||
expect('model should not login user', $model->login())->false();
|
||||
expect('error message should be set', $model->errors)->hasKey('password');
|
||||
expect('user should not be logged in', Yii::$app->user->isGuest)->true();
|
||||
}
|
||||
|
||||
public function testLoginCorrect()
|
||||
{
|
||||
$model = new LoginForm([
|
||||
'username' => 'bayer.hudson',
|
||||
'password' => 'password_0',
|
||||
]);
|
||||
|
||||
expect('model should login user', $model->login())->true();
|
||||
expect('error message should not be set', $model->errors)->hasntKey('password');
|
||||
expect('user should be logged in', Yii::$app->user->isGuest)->false();
|
||||
}
|
||||
}
|
75
common/widgets/Alert.php
Normal file
75
common/widgets/Alert.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
namespace common\widgets;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* Alert widget renders a message from session flash. All flash messages are displayed
|
||||
* in the sequence they were assigned using setFlash. You can set message as following:
|
||||
*
|
||||
* ```php
|
||||
* Yii::$app->session->setFlash('error', 'This is the message');
|
||||
* Yii::$app->session->setFlash('success', 'This is the message');
|
||||
* Yii::$app->session->setFlash('info', 'This is the message');
|
||||
* ```
|
||||
*
|
||||
* Multiple messages could be set as follows:
|
||||
*
|
||||
* ```php
|
||||
* Yii::$app->session->setFlash('error', ['Error 1', 'Error 2']);
|
||||
* ```
|
||||
*
|
||||
* @author Kartik Visweswaran <kartikv2@gmail.com>
|
||||
* @author Alexander Makarov <sam@rmcreative.ru>
|
||||
*/
|
||||
class Alert extends \yii\bootstrap\Widget
|
||||
{
|
||||
/**
|
||||
* @var array the alert types configuration for the flash messages.
|
||||
* This array is setup as $key => $value, where:
|
||||
* - key: the name of the session flash variable
|
||||
* - value: the bootstrap alert type (i.e. danger, success, info, warning)
|
||||
*/
|
||||
public $alertTypes = [
|
||||
'error' => 'alert-danger',
|
||||
'danger' => 'alert-danger',
|
||||
'success' => 'alert-success',
|
||||
'info' => 'alert-info',
|
||||
'warning' => 'alert-warning'
|
||||
];
|
||||
/**
|
||||
* @var array the options for rendering the close button tag.
|
||||
* Array will be passed to [[\yii\bootstrap\Alert::closeButton]].
|
||||
*/
|
||||
public $closeButton = [];
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$session = Yii::$app->session;
|
||||
$flashes = $session->getAllFlashes();
|
||||
$appendClass = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
|
||||
|
||||
foreach ($flashes as $type => $flash) {
|
||||
if (!isset($this->alertTypes[$type])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ((array) $flash as $i => $message) {
|
||||
echo \yii\bootstrap\Alert::widget([
|
||||
'body' => $message,
|
||||
'closeButton' => $this->closeButton,
|
||||
'options' => array_merge($this->options, [
|
||||
'id' => $this->getId() . '-' . $type . '-' . $i,
|
||||
'class' => $this->alertTypes[$type] . $appendClass,
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
$session->removeFlash($type);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user