first commit
This commit is contained in:
20
common/classes/Debug.php
Executable file
20
common/classes/Debug.php
Executable 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
Executable file
15
common/codeception.yml
Executable file
@ -0,0 +1,15 @@
|
||||
namespace: common\tests
|
||||
actor_suffix: Tester
|
||||
paths:
|
||||
tests: tests
|
||||
output: tests/_output
|
||||
data: tests/_data
|
||||
support: tests/_support
|
||||
bootstrap: _bootstrap.php
|
||||
settings:
|
||||
colors: true
|
||||
memory_limit: 1024M
|
||||
modules:
|
||||
config:
|
||||
Yii2:
|
||||
configFile: 'config/codeception-local.php'
|
4
common/config/.gitignore
vendored
Executable file
4
common/config/.gitignore
vendored
Executable file
@ -0,0 +1,4 @@
|
||||
codeception-local.php
|
||||
main-local.php
|
||||
params-local.php
|
||||
test-local.php
|
33
common/config/__autocomplete.php
Executable file
33
common/config/__autocomplete.php
Executable file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This class only exists here for IDE (PHPStorm/Netbeans/...) autocompletion.
|
||||
* This file is never included anywhere.
|
||||
* Adjust this file to match classes configured in your application config, to enable IDE autocompletion for custom components.
|
||||
* Example: A property phpdoc can be added in `__Application` class as `@property \vendor\package\Rollbar|__Rollbar $rollbar` and adding a class in this file
|
||||
* ```php
|
||||
* // @property of \vendor\package\Rollbar goes here
|
||||
* class __Rollbar {
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
class Yii {
|
||||
/**
|
||||
* @var \yii\web\Application|\yii\console\Application|__Application
|
||||
*/
|
||||
public static $app;
|
||||
}
|
||||
|
||||
/**
|
||||
* @property yii\rbac\DbManager $authManager
|
||||
* @property \yii\web\User|__WebUser $user
|
||||
*
|
||||
*/
|
||||
class __Application {
|
||||
}
|
||||
|
||||
/**
|
||||
* @property app\models\User $identity
|
||||
*/
|
||||
class __WebUser {
|
||||
}
|
5
common/config/bootstrap.php
Executable file
5
common/config/bootstrap.php
Executable 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');
|
13
common/config/main.php
Executable file
13
common/config/main.php
Executable file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
return [
|
||||
'aliases' => [
|
||||
'@bower' => '@vendor/bower-asset',
|
||||
'@npm' => '@vendor/npm-asset',
|
||||
],
|
||||
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
|
||||
'components' => [
|
||||
'cache' => [
|
||||
'class' => \yii\caching\FileCache::class,
|
||||
],
|
||||
],
|
||||
];
|
9
common/config/params.php
Executable file
9
common/config/params.php
Executable file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
return [
|
||||
'adminEmail' => 'admin@example.com',
|
||||
'supportEmail' => 'support@example.com',
|
||||
'senderEmail' => 'noreply@example.com',
|
||||
'senderName' => 'Example.com mailer',
|
||||
'user.passwordResetTokenExpire' => 3600,
|
||||
'user.passwordMinLength' => 8,
|
||||
];
|
11
common/config/test.php
Executable file
11
common/config/test.php
Executable file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
return [
|
||||
'id' => 'app-common-tests',
|
||||
'basePath' => dirname(__DIR__),
|
||||
'components' => [
|
||||
'user' => [
|
||||
'class' => \yii\web\User::class,
|
||||
'identityClass' => 'common\models\User',
|
||||
],
|
||||
],
|
||||
];
|
10
common/fixtures/UserFixture.php
Executable file
10
common/fixtures/UserFixture.php
Executable file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace common\fixtures;
|
||||
|
||||
use yii\test\ActiveFixture;
|
||||
|
||||
class UserFixture extends ActiveFixture
|
||||
{
|
||||
public $modelClass = 'common\models\User';
|
||||
}
|
16
common/mail/emailVerify-html.php
Executable file
16
common/mail/emailVerify-html.php
Executable file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\User $user */
|
||||
|
||||
$verifyLink = Yii::$app->urlManager->createAbsoluteUrl(['site/verify-email', 'token' => $user->verification_token]);
|
||||
?>
|
||||
<div class="verify-email">
|
||||
<p>Hello <?= Html::encode($user->username) ?>,</p>
|
||||
|
||||
<p>Follow the link below to verify your email:</p>
|
||||
|
||||
<p><?= Html::a(Html::encode($verifyLink), $verifyLink) ?></p>
|
||||
</div>
|
12
common/mail/emailVerify-text.php
Executable file
12
common/mail/emailVerify-text.php
Executable file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\User $user */
|
||||
|
||||
$verifyLink = Yii::$app->urlManager->createAbsoluteUrl(['site/verify-email', 'token' => $user->verification_token]);
|
||||
?>
|
||||
Hello <?= $user->username ?>,
|
||||
|
||||
Follow the link below to verify your email:
|
||||
|
||||
<?= $verifyLink ?>
|
24
common/mail/layouts/html.php
Executable file
24
common/mail/layouts/html.php
Executable file
@ -0,0 +1,24 @@
|
||||
<?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() ?>
|
||||
<!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();
|
12
common/mail/layouts/text.php
Executable file
12
common/mail/layouts/text.php
Executable file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
/** @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() ?>
|
16
common/mail/passwordResetToken-html.php
Executable file
16
common/mail/passwordResetToken-html.php
Executable file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\User $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
Executable file
12
common/mail/passwordResetToken-text.php
Executable file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\User $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 ?>
|
46
common/models/Banner.php
Executable file
46
common/models/Banner.php
Executable file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "banner".
|
||||
*
|
||||
* @property int $id
|
||||
* @property string|null $photo
|
||||
* @property int|null $rating
|
||||
*/
|
||||
class Banner extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'banner';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['rating'], 'integer'],
|
||||
[['photo'], 'string', 'max' => 255],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'photo' => 'Photo',
|
||||
'rating' => 'Rating',
|
||||
];
|
||||
}
|
||||
}
|
59
common/models/Category.php
Executable file
59
common/models/Category.php
Executable file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "category".
|
||||
*
|
||||
* @property int $id
|
||||
* @property string|null $name
|
||||
* @property string|null $description
|
||||
* @property string|null $slug
|
||||
*
|
||||
* @property Product[] $products
|
||||
*/
|
||||
class Category extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'category';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['name', 'description', 'slug'], 'string', 'max' => 255],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'name' => 'Name',
|
||||
'description' => 'Description',
|
||||
'slug' => 'Slug',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets query for [[Products]].
|
||||
*
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getProducts()
|
||||
{
|
||||
return $this->hasMany(Product::class, ['category_id' => 'id']);
|
||||
}
|
||||
}
|
80
common/models/LoginForm.php
Executable file
80
common/models/LoginForm.php
Executable file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use common\classes\Debug;
|
||||
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;
|
||||
}
|
||||
}
|
109
common/models/Order.php
Executable file
109
common/models/Order.php
Executable file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "order".
|
||||
*
|
||||
* @property int $id
|
||||
* @property int|null $user_id
|
||||
* @property int|null $table_id
|
||||
* @property int|null $strength
|
||||
* @property string|null $amount
|
||||
* @property int|null $status
|
||||
* @property string|null $created_at
|
||||
* @property string|null $updated_at
|
||||
*
|
||||
* @property OrderProduct[] $orderProducts
|
||||
* @property Product[] $products
|
||||
* @property Table $table
|
||||
* @property User $user
|
||||
* @property Product[] $tastes
|
||||
*/
|
||||
class Order extends \yii\db\ActiveRecord
|
||||
{
|
||||
const STATUS_NEW = 0;
|
||||
const STATUS_IN_PROGRESS = 1;
|
||||
const STATUS_DONE = 2;
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'order';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['user_id', 'table_id', 'strength', 'status'], 'integer'],
|
||||
[['created_at', 'updated_at'], 'safe'],
|
||||
[['amount'], 'string', 'max' => 255],
|
||||
[['table_id'], 'exist', 'skipOnError' => true, 'targetClass' => Table::class, 'targetAttribute' => ['table_id' => 'id']],
|
||||
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['user_id' => 'id']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'user_id' => 'User ID',
|
||||
'table_id' => 'Table ID',
|
||||
'strength' => 'Strength',
|
||||
'amount' => 'Amount',
|
||||
'status' => 'Status',
|
||||
'created_at' => 'Created At',
|
||||
'updated_at' => 'Updated At',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets query for [[OrderProducts]].
|
||||
*
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getOrderProducts()
|
||||
{
|
||||
return $this->hasMany(OrderProduct::class, ['order_id' => 'id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets query for [[Table]].
|
||||
*
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getTable()
|
||||
{
|
||||
return $this->hasOne(Table::class, ['id' => 'table_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets query for [[User]].
|
||||
*
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
return $this->hasOne(User::class, ['id' => 'user_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets query for [[Products]].
|
||||
*
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getProducts()
|
||||
{
|
||||
return $this->hasMany(Product::class, ['id' => 'product_id'])
|
||||
->viaTable('order_product', ['order_id' => 'id']);
|
||||
}
|
||||
}
|
70
common/models/OrderProduct.php
Executable file
70
common/models/OrderProduct.php
Executable file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "order_product".
|
||||
*
|
||||
* @property int $id
|
||||
* @property int|null $order_id
|
||||
* @property int|null $product_id
|
||||
*
|
||||
* @property Order $order
|
||||
* @property Product $product
|
||||
*/
|
||||
class OrderProduct extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'order_product';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['order_id', 'product_id'], 'integer'],
|
||||
[['order_id'], 'exist', 'skipOnError' => true, 'targetClass' => Order::class, 'targetAttribute' => ['order_id' => 'id']],
|
||||
[['product_id'], 'exist', 'skipOnError' => true, 'targetClass' => Product::class, 'targetAttribute' => ['product_id' => 'id']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'order_id' => 'Order ID',
|
||||
'product_id' => 'Product ID',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets query for [[Order]].
|
||||
*
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
return $this->hasOne(Order::class, ['id' => 'order_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets query for [[Product]].
|
||||
*
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getProduct()
|
||||
{
|
||||
return $this->hasOne(Product::class, ['id' => 'product_id']);
|
||||
}
|
||||
}
|
123
common/models/Product.php
Executable file
123
common/models/Product.php
Executable file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "product".
|
||||
*
|
||||
* @property int $id
|
||||
* @property int|null $type
|
||||
* @property string|null $name
|
||||
* @property string|null $description
|
||||
* @property string|null $photo
|
||||
* @property float|null $price
|
||||
* @property int|null $status
|
||||
* @property int|null $quantity
|
||||
* @property string|null $taste
|
||||
* @property int|null $strength
|
||||
* @property int|null $category_id
|
||||
*
|
||||
* @property Category $category
|
||||
* @property OrderProduct[] $orderProducts
|
||||
* @property Order[] $orders
|
||||
*/
|
||||
class Product extends \yii\db\ActiveRecord
|
||||
{
|
||||
|
||||
const STATUS_ACTIVE = 1;
|
||||
const STATUS_INACTIVE = 0;
|
||||
const TYPE_TOBACCO = 1;
|
||||
const TYPE_ELSE = 0;
|
||||
const TOBACCO_STRENGTH_LITE = 0;
|
||||
const TOBACCO_STRENGTH_MIDDLE = 1;
|
||||
const TOBACCO_STRENGTH_HARD = 2;
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'product';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['type', 'status', 'quantity', 'strength', 'category_id'], 'integer'],
|
||||
[['price'], 'number'],
|
||||
[['name', 'description', 'taste', 'photo'], 'string', 'max' => 255],
|
||||
[['category_id'], 'exist', 'skipOnError' => true, 'targetClass' => Category::class, 'targetAttribute' => ['category_id' => 'id']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'type' => 'Type',
|
||||
'name' => 'Name',
|
||||
'description' => 'Description',
|
||||
'price' => 'Price',
|
||||
'status' => 'Status',
|
||||
'quantity' => 'Quantity',
|
||||
'taste' => 'Taste',
|
||||
'strength' => 'Strength',
|
||||
'category_id' => 'Category ID',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets query for [[Category]].
|
||||
*
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getCategory()
|
||||
{
|
||||
return $this->hasOne(Category::class, ['id' => 'category_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets query for [[OrderProducts]].
|
||||
*
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getOrderProducts()
|
||||
{
|
||||
return $this->hasMany(OrderProduct::class, ['product_id' => 'id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets query for [[Orders]].
|
||||
*
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getOrders()
|
||||
{
|
||||
return $this->hasMany(Order::class, ['id' => 'product_id'])
|
||||
->viaTable('order_product', ['order_id' => 'id']);
|
||||
}
|
||||
|
||||
public static function TypesWIthLabels()
|
||||
{
|
||||
return [
|
||||
0 => 'другое',
|
||||
1 => 'табак'
|
||||
];
|
||||
}
|
||||
|
||||
public static function TabacooStrengthWithLabel()
|
||||
{
|
||||
return [
|
||||
0 => 'Легкий',
|
||||
1 => 'Средний',
|
||||
2 => 'Тяжелый'
|
||||
];
|
||||
}
|
||||
}
|
62
common/models/Table.php
Executable file
62
common/models/Table.php
Executable file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "table".
|
||||
*
|
||||
* @property int $id
|
||||
* @property string|null $name
|
||||
* @property int|null $places
|
||||
* @property string|null $type
|
||||
* @property string|null $slug
|
||||
*
|
||||
* @property Order[] $orders
|
||||
*/
|
||||
class Table extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'table';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['places'], 'integer'],
|
||||
[['name', 'type', 'slug'], 'string', 'max' => 255],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'name' => 'Name',
|
||||
'places' => 'Places',
|
||||
'type' => 'Type',
|
||||
'slug' => 'Slug',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets query for [[Orders]].
|
||||
*
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getOrders()
|
||||
{
|
||||
return $this->hasMany(Order::class, ['table_id' => 'id']);
|
||||
}
|
||||
}
|
213
common/models/User.php
Executable file
213
common/models/User.php
Executable file
@ -0,0 +1,213 @@
|
||||
<?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 $verification_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_INACTIVE = 9;
|
||||
const STATUS_ACTIVE = 10;
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%user}}';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
TimestampBehavior::class,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
['status', 'default', 'value' => self::STATUS_INACTIVE],
|
||||
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_INACTIVE, 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)
|
||||
{
|
||||
return static::findOne(['access_token' => $token]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 user by verification email token
|
||||
*
|
||||
* @param string $token verify email token
|
||||
* @return static|null
|
||||
*/
|
||||
public static function findByVerificationToken($token) {
|
||||
return static::findOne([
|
||||
'verification_token' => $token,
|
||||
'status' => self::STATUS_INACTIVE
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates new token for email verification
|
||||
*/
|
||||
public function generateEmailVerificationToken()
|
||||
{
|
||||
$this->verification_token = Yii::$app->security->generateRandomString() . '_' . time();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes password reset token
|
||||
*/
|
||||
public function removePasswordResetToken()
|
||||
{
|
||||
$this->password_reset_token = null;
|
||||
}
|
||||
}
|
9
common/tests/_bootstrap.php
Executable file
9
common/tests/_bootstrap.php
Executable 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
Executable file
14
common/tests/_data/user.php
Executable 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
Executable file
2
common/tests/_output/.gitignore
vendored
Executable file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
1
common/tests/_support/.gitignore
vendored
Executable file
1
common/tests/_support/.gitignore
vendored
Executable file
@ -0,0 +1 @@
|
||||
_generated
|
26
common/tests/_support/UnitTester.php
Executable file
26
common/tests/_support/UnitTester.php
Executable file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace common\tests;
|
||||
|
||||
/**
|
||||
* Inherited Methods
|
||||
* @method void wantToTest($text)
|
||||
* @method void wantTo($text)
|
||||
* @method void execute($callable)
|
||||
* @method void expectTo($prediction)
|
||||
* @method void verify($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
Executable file
7
common/tests/unit.suite.yml
Executable 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
Executable file
67
common/tests/unit/models/LoginFormTest.php
Executable 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::class,
|
||||
'dataFile' => codecept_data_dir() . 'user.php'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function testLoginNoUser()
|
||||
{
|
||||
$model = new LoginForm([
|
||||
'username' => 'not_existing_username',
|
||||
'password' => 'not_existing_password',
|
||||
]);
|
||||
|
||||
verify($model->login())->false();
|
||||
verify(Yii::$app->user->isGuest)->true();
|
||||
}
|
||||
|
||||
public function testLoginWrongPassword()
|
||||
{
|
||||
$model = new LoginForm([
|
||||
'username' => 'bayer.hudson',
|
||||
'password' => 'wrong_password',
|
||||
]);
|
||||
|
||||
verify($model->login())->false();
|
||||
verify( $model->errors)->arrayHasKey('password');
|
||||
verify(Yii::$app->user->isGuest)->true();
|
||||
}
|
||||
|
||||
public function testLoginCorrect()
|
||||
{
|
||||
$model = new LoginForm([
|
||||
'username' => 'bayer.hudson',
|
||||
'password' => 'password_0',
|
||||
]);
|
||||
|
||||
verify($model->login())->true();
|
||||
verify($model->errors)->arrayHasNotKey('password');
|
||||
verify(Yii::$app->user->isGuest)->false();
|
||||
}
|
||||
}
|
76
common/widgets/Alert.php
Executable file
76
common/widgets/Alert.php
Executable file
@ -0,0 +1,76 @@
|
||||
<?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\bootstrap5\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\bootstrap5\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