Создание аутентификации и регистрации на ArangoDB через Ajax + фронтенд правки

This commit is contained in:
RedHood 2020-12-24 09:57:19 +10:00
parent 59faa344cb
commit e0a6ae88e4
22 changed files with 755 additions and 317 deletions

View File

@ -20,7 +20,7 @@
"bower-asset/bootstrap": "*",
"npm-asset/jquery": "^3.5",
"bower-asset/jquery": "^3.5",
"pbazsi/yii2-arangodb": "2.0",
"explosivebit/arangodb": "^2.0",
"triagens/arangodb": "^3.6"
},
"require-dev": {
@ -39,7 +39,10 @@
"autoload": {
"psr-4": {
"mirzaev\\skillparts\\": "mirzaev/skillparts/system"
}
},
"classmap": [
"vendor/explosivebit"
]
},
"autoload-dev": {
"psr-4": {
@ -86,14 +89,14 @@
{
"type": "package",
"package": {
"name": "pbazsi/yii2-arangodb",
"version": "2.0",
"source": {
"type" : "git",
"url" : "https://github.com/pBazsi/yii2-arangodb.git",
"reference" : "master"
}
"name": "explosivebit/arangodb",
"version": "2.0",
"source": {
"type": "git",
"url": "https://github.com/pBazsi/yii2-arangodb.git",
"reference": "master"
}
}
}
}
]
}
}

156
composer.lock generated
View File

@ -4,14 +4,14 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "5c6fa00f67028dbc18572600d2a1935d",
"content-hash": "d83ed7a25bd848237d6ae45b945471f6",
"packages": [
{
"name": "bower-asset/bootstrap",
"version": "v3.4.1",
"source": {
"type": "git",
"url": "git@github.com:twbs/bootstrap.git",
"url": "https://github.com/twbs/bootstrap.git",
"reference": "68b0d231a13201eb14acd3dc84e51543d16e5f7e"
},
"dist": {
@ -302,6 +302,16 @@
],
"time": "2020-11-14T15:56:27+00:00"
},
{
"name": "explosivebit/arangodb",
"version": "2.0",
"source": {
"type": "git",
"url": "https://github.com/pBazsi/yii2-arangodb.git",
"reference": "master"
},
"type": "library"
},
{
"name": "ezyang/htmlpurifier",
"version": "v4.13.0",
@ -364,16 +374,6 @@
"MIT"
]
},
{
"name": "pBazsi/yii2-arangodb",
"version": "2.0",
"source": {
"type": "git",
"url": "https://github.com/pBazsi/yii2-arangodb.git",
"reference": "master"
},
"type": "library"
},
{
"name": "swiftmailer/swiftmailer",
"version": "v6.2.4",
@ -1835,21 +1835,21 @@
},
{
"name": "codeception/verify",
"version": "2.1.0",
"version": "2.1.1",
"source": {
"type": "git",
"url": "https://github.com/Codeception/Verify.git",
"reference": "11fa56c223ae7188174c4ba50c68454d83b254e9"
"reference": "1cdac1867c33801ae8e4833015153766ef403c92"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Codeception/Verify/zipball/11fa56c223ae7188174c4ba50c68454d83b254e9",
"reference": "11fa56c223ae7188174c4ba50c68454d83b254e9",
"url": "https://api.github.com/repos/Codeception/Verify/zipball/1cdac1867c33801ae8e4833015153766ef403c92",
"reference": "1cdac1867c33801ae8e4833015153766ef403c92",
"shasum": ""
},
"require": {
"ext-dom": "*",
"php": "^7.3",
"php": "^7.3 || ^8.0",
"phpunit/phpunit": "^9.3"
},
"type": "library",
@ -1876,7 +1876,7 @@
}
],
"description": "BDD assertion library for PHPUnit",
"time": "2020-09-03T04:43:01+00:00"
"time": "2020-12-18T16:18:31+00:00"
},
{
"name": "doctrine/instantiator",
@ -1945,16 +1945,16 @@
},
{
"name": "fakerphp/faker",
"version": "v1.12.1",
"version": "v1.13.0",
"source": {
"type": "git",
"url": "https://github.com/FakerPHP/Faker.git",
"reference": "841e8bdde345cc1ea9f98e776959e7531cadea0e"
"reference": "ab3f5364d01f2c2c16113442fb987d26e4004913"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/FakerPHP/Faker/zipball/841e8bdde345cc1ea9f98e776959e7531cadea0e",
"reference": "841e8bdde345cc1ea9f98e776959e7531cadea0e",
"url": "https://api.github.com/repos/FakerPHP/Faker/zipball/ab3f5364d01f2c2c16113442fb987d26e4004913",
"reference": "ab3f5364d01f2c2c16113442fb987d26e4004913",
"shasum": ""
},
"require": {
@ -1989,11 +1989,7 @@
"faker",
"fixtures"
],
"support": {
"issues": "https://github.com/FakerPHP/Faker/issues",
"source": "https://github.com/FakerPHP/Faker/tree/v1.12.1"
},
"time": "2020-12-11T10:39:41+00:00"
"time": "2020-12-18T16:50:48+00:00"
},
{
"name": "guzzlehttp/psr7",
@ -2295,16 +2291,16 @@
},
{
"name": "phar-io/version",
"version": "3.0.3",
"version": "3.0.4",
"source": {
"type": "git",
"url": "https://github.com/phar-io/version.git",
"reference": "726c026815142e4f8677b7cb7f2249c9ffb7ecae"
"reference": "e4782611070e50613683d2b9a57730e9a3ba5451"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phar-io/version/zipball/726c026815142e4f8677b7cb7f2249c9ffb7ecae",
"reference": "726c026815142e4f8677b7cb7f2249c9ffb7ecae",
"url": "https://api.github.com/repos/phar-io/version/zipball/e4782611070e50613683d2b9a57730e9a3ba5451",
"reference": "e4782611070e50613683d2b9a57730e9a3ba5451",
"shasum": ""
},
"require": {
@ -2338,7 +2334,7 @@
}
],
"description": "Library for handling version information and constraints",
"time": "2020-11-30T09:21:21+00:00"
"time": "2020-12-13T23:18:30+00:00"
},
{
"name": "php-webdriver/webdriver",
@ -4142,16 +4138,16 @@
},
{
"name": "symfony/browser-kit",
"version": "v5.2.0",
"version": "v5.2.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/browser-kit.git",
"reference": "4fc769a12282a12bc47f883f04f01ff3777e369b"
"reference": "87d6f0a7436b03a57d4cf9a6a9cd0c83a355c49a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/browser-kit/zipball/4fc769a12282a12bc47f883f04f01ff3777e369b",
"reference": "4fc769a12282a12bc47f883f04f01ff3777e369b",
"url": "https://api.github.com/repos/symfony/browser-kit/zipball/87d6f0a7436b03a57d4cf9a6a9cd0c83a355c49a",
"reference": "87d6f0a7436b03a57d4cf9a6a9cd0c83a355c49a",
"shasum": ""
},
"require": {
@ -4192,9 +4188,6 @@
],
"description": "Symfony BrowserKit Component",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/browser-kit/tree/v5.2.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
@ -4209,20 +4202,20 @@
"type": "tidelift"
}
],
"time": "2020-11-14T11:04:29+00:00"
"time": "2020-12-18T08:03:05+00:00"
},
{
"name": "symfony/console",
"version": "v5.2.0",
"version": "v5.2.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
"reference": "3e0564fb08d44a98bd5f1960204c958e57bd586b"
"reference": "47c02526c532fb381374dab26df05e7313978976"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/3e0564fb08d44a98bd5f1960204c958e57bd586b",
"reference": "3e0564fb08d44a98bd5f1960204c958e57bd586b",
"url": "https://api.github.com/repos/symfony/console/zipball/47c02526c532fb381374dab26df05e7313978976",
"reference": "47c02526c532fb381374dab26df05e7313978976",
"shasum": ""
},
"require": {
@ -4303,20 +4296,20 @@
"type": "tidelift"
}
],
"time": "2020-11-28T11:24:18+00:00"
"time": "2020-12-18T08:03:05+00:00"
},
{
"name": "symfony/css-selector",
"version": "v5.2.0",
"version": "v5.2.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/css-selector.git",
"reference": "b8d8eb06b0942e84a69e7acebc3e9c1e6e6e7256"
"reference": "f789e7ead4c79e04ca9a6d6162fc629c89bd8054"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/css-selector/zipball/b8d8eb06b0942e84a69e7acebc3e9c1e6e6e7256",
"reference": "b8d8eb06b0942e84a69e7acebc3e9c1e6e6e7256",
"url": "https://api.github.com/repos/symfony/css-selector/zipball/f789e7ead4c79e04ca9a6d6162fc629c89bd8054",
"reference": "f789e7ead4c79e04ca9a6d6162fc629c89bd8054",
"shasum": ""
},
"require": {
@ -4365,7 +4358,7 @@
"type": "tidelift"
}
],
"time": "2020-10-28T21:31:18+00:00"
"time": "2020-12-08T17:02:38+00:00"
},
{
"name": "symfony/deprecation-contracts",
@ -4433,16 +4426,16 @@
},
{
"name": "symfony/dom-crawler",
"version": "v5.2.0",
"version": "v5.2.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/dom-crawler.git",
"reference": "0969122fe144dd8ab2e8c98c7e03eedc621b368c"
"reference": "ee7cf316fb0de786cfe5ae32ee79502b290c81ea"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/dom-crawler/zipball/0969122fe144dd8ab2e8c98c7e03eedc621b368c",
"reference": "0969122fe144dd8ab2e8c98c7e03eedc621b368c",
"url": "https://api.github.com/repos/symfony/dom-crawler/zipball/ee7cf316fb0de786cfe5ae32ee79502b290c81ea",
"reference": "ee7cf316fb0de786cfe5ae32ee79502b290c81ea",
"shasum": ""
},
"require": {
@ -4486,9 +4479,6 @@
],
"description": "Symfony DomCrawler Component",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/dom-crawler/tree/v5.2.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
@ -4503,20 +4493,20 @@
"type": "tidelift"
}
],
"time": "2020-10-24T12:01:57+00:00"
"time": "2020-12-18T08:02:46+00:00"
},
{
"name": "symfony/event-dispatcher",
"version": "v5.2.0",
"version": "v5.2.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/event-dispatcher.git",
"reference": "aa13a09811e6d2ad43f8fb336bebdb7691d85d3c"
"reference": "1c93f7a1dff592c252574c79a8635a8a80856042"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/aa13a09811e6d2ad43f8fb336bebdb7691d85d3c",
"reference": "aa13a09811e6d2ad43f8fb336bebdb7691d85d3c",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/1c93f7a1dff592c252574c79a8635a8a80856042",
"reference": "1c93f7a1dff592c252574c79a8635a8a80856042",
"shasum": ""
},
"require": {
@ -4585,7 +4575,7 @@
"type": "tidelift"
}
],
"time": "2020-11-01T16:14:45+00:00"
"time": "2020-12-18T08:03:05+00:00"
},
{
"name": "symfony/event-dispatcher-contracts",
@ -4665,16 +4655,16 @@
},
{
"name": "symfony/finder",
"version": "v5.2.0",
"version": "v5.2.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/finder.git",
"reference": "fd8305521692f27eae3263895d1ef1571c71a78d"
"reference": "0b9231a5922fd7287ba5b411893c0ecd2733e5ba"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/finder/zipball/fd8305521692f27eae3263895d1ef1571c71a78d",
"reference": "fd8305521692f27eae3263895d1ef1571c71a78d",
"url": "https://api.github.com/repos/symfony/finder/zipball/0b9231a5922fd7287ba5b411893c0ecd2733e5ba",
"reference": "0b9231a5922fd7287ba5b411893c0ecd2733e5ba",
"shasum": ""
},
"require": {
@ -4719,7 +4709,7 @@
"type": "tidelift"
}
],
"time": "2020-11-18T09:42:36+00:00"
"time": "2020-12-08T17:02:38+00:00"
},
{
"name": "symfony/polyfill-ctype",
@ -5033,16 +5023,16 @@
},
{
"name": "symfony/process",
"version": "v5.2.0",
"version": "v5.2.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/process.git",
"reference": "240e74140d4d956265048f3025c0aecbbc302d54"
"reference": "bd8815b8b6705298beaa384f04fabd459c10bedd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/process/zipball/240e74140d4d956265048f3025c0aecbbc302d54",
"reference": "240e74140d4d956265048f3025c0aecbbc302d54",
"url": "https://api.github.com/repos/symfony/process/zipball/bd8815b8b6705298beaa384f04fabd459c10bedd",
"reference": "bd8815b8b6705298beaa384f04fabd459c10bedd",
"shasum": ""
},
"require": {
@ -5088,7 +5078,7 @@
"type": "tidelift"
}
],
"time": "2020-11-02T15:47:15+00:00"
"time": "2020-12-08T17:03:37+00:00"
},
{
"name": "symfony/service-contracts",
@ -5168,16 +5158,16 @@
},
{
"name": "symfony/string",
"version": "v5.2.0",
"version": "v5.2.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/string.git",
"reference": "40e975edadd4e32cd16f3753b3bad65d9ac48242"
"reference": "5bd67751d2e3f7d6f770c9154b8fbcb2aa05f7ed"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/string/zipball/40e975edadd4e32cd16f3753b3bad65d9ac48242",
"reference": "40e975edadd4e32cd16f3753b3bad65d9ac48242",
"url": "https://api.github.com/repos/symfony/string/zipball/5bd67751d2e3f7d6f770c9154b8fbcb2aa05f7ed",
"reference": "5bd67751d2e3f7d6f770c9154b8fbcb2aa05f7ed",
"shasum": ""
},
"require": {
@ -5244,20 +5234,20 @@
"type": "tidelift"
}
],
"time": "2020-10-24T12:08:07+00:00"
"time": "2020-12-05T07:33:16+00:00"
},
{
"name": "symfony/yaml",
"version": "v5.2.0",
"version": "v5.2.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
"reference": "bb73619b2ae5121bbbcd9f191dfd53ded17ae598"
"reference": "290ea5e03b8cf9b42c783163123f54441fb06939"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/bb73619b2ae5121bbbcd9f191dfd53ded17ae598",
"reference": "bb73619b2ae5121bbbcd9f191dfd53ded17ae598",
"url": "https://api.github.com/repos/symfony/yaml/zipball/290ea5e03b8cf9b42c783163123f54441fb06939",
"reference": "290ea5e03b8cf9b42c783163123f54441fb06939",
"shasum": ""
},
"require": {
@ -5316,7 +5306,7 @@
"type": "tidelift"
}
],
"time": "2020-11-28T10:57:20+00:00"
"time": "2020-12-08T17:02:38+00:00"
},
{
"name": "theseer/tokenizer",

View File

@ -31,12 +31,14 @@ class AppAsset extends AssetBundle
'css/footer.css'
];
public $js = [
'https://kit.fontawesome.com/d7e922c226.js',
'https://code.jquery.com/jquery-3.5.1.min.js',
'js/bootstrap/popper.min.js',
'js/bootstrap/bootstrap.min.js',
'https://cdn.jsdelivr.net/bxslider/4.1.1/jquery.bxslider.min.js',
'js/account.js',
'js/ticker.js',
'https://kit.fontawesome.com/d7e922c226.js'
'js/reinitialization.js'
];
public $depends = [
'yii\web\YiiAsset',

View File

@ -1,17 +1,16 @@
<?php
$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';
$config = [
'id' => 'basic-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'app\commands',
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
'@tests' => '@app/tests',
'@vendor' => dirname(__DIR__) . '../../../../vendor',
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
'@explosivebit' => '@vendor/explosivebit',
'@tests' => '@app/tests',
],
'components' => [
'cache' => [
@ -25,16 +24,15 @@ $config = [
],
],
],
'db' => $db,
'arangodb' => require __DIR__ . '/db.php'
],
'params' => $params,
/*
'params' => require __DIR__ . '/params.php',
'controllerMap' => [
'fixture' => [ // Fixture generation command line.
'arangodb-migrate' => 'explosivebit\arangodb\console\controllers\MigrateController',
'fixture' => [
'class' => 'yii\faker\FixtureController',
],
],
*/
]
];
if (YII_ENV_DEV) {

View File

@ -1,14 +1,14 @@
<?php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=;dbname=',
'username' => '',
'password' => '',
'charset' => 'utf8',
use ArangoDBClient\ConnectionOptions;
// Schema cache options (for production environment)
//'enableSchemaCache' => true,
//'schemaCacheDuration' => 60,
//'schemaCache' => 'cache',
return [
'class' => '\explosivebit\arangodb\Connection',
'connectionOptions' => [
ConnectionOptions::OPTION_DATABASE => '',
ConnectionOptions::OPTION_ENDPOINT => 'tcp://127.0.0.1:8529',
ConnectionOptions::OPTION_AUTH_TYPE => 'Basic',
ConnectionOptions::OPTION_AUTH_USER => '',
ConnectionOptions::OPTION_AUTH_PASSWD => '',
],
];

View File

@ -1,6 +1,4 @@
<?php
$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/test_db.php';
/**
* Application configuration shared by all test types
@ -14,7 +12,7 @@ return [
],
'language' => 'en-US',
'components' => [
'db' => $db,
'db' => require __DIR__ . '/test_db.php',
'mailer' => [
'useFileTransport' => true,
],
@ -25,7 +23,7 @@ return [
'showScriptName' => true,
],
'user' => [
'identityClass' => 'app\models\User',
'identityClass' => 'app\models\Account',
],
'request' => [
'cookieValidationKey' => 'test',
@ -38,5 +36,5 @@ return [
*/
],
],
'params' => $params,
'params' => require __DIR__ . '/params.php',
];

View File

@ -1,31 +1,34 @@
<?php
use ArangoDBClient\ConnectionOptions;
$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'aliases' => [
'@vendor' => '../../../../vendor',
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
'@vendor' => dirname(__DIR__) . '../../../../vendor',
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
'@explosivebit' => '@vendor/explosivebit',
],
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '',
'baseUrl' => ''
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
// 'cache' => [
// 'class' => 'yii\caching\FileCache',
// ],
'user' => [
'identityClass' => 'app\models\User',
'identityClass' => 'app\models\Account',
'enableAutoLogin' => true,
],
// 'session' => [
// 'class' => 'yii\web\Session',
// 'cookieParams' => ['lifetime' => 3600 * 24 * 30 * 12],
// 'timeout' => 3600 * 24 * 30 * 12,
// 'useCookies' => true,
// ],
'errorHandler' => [
'errorAction' => 'site/error',
],
@ -45,32 +48,29 @@ $config = [
],
],
],
'db' => $db,
'arangodb' => [
'class' => '\explosivebit\arangodb\Connection',
'connectionOptions' => [
ConnectionOptions::OPTION_DATABASE => '',
ConnectionOptions::OPTION_ENDPOINT => '',
ConnectionOptions::OPTION_AUTH_TYPE => 'Basic',
ConnectionOptions::OPTION_AUTH_USER => '',
ConnectionOptions::OPTION_AUTH_PASSWD => '',
],
],
'arangodb' => require __DIR__ . '/db.php',
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [],
'rules' => [
['class' => 'yii\rest\UrlRule', 'controller' => 'site'],
'<action>' => 'site/<action>'
],
],
],
'params' => $params,
'params' => require __DIR__ . '/params.php',
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
'panels' => [
'ArangoDB' => [
'class' => 'explosivebit\arangodb\panels\arangodb\ArangoDbPanel'
]
],
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];

View File

@ -7,11 +7,14 @@ use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\Response;
use yii\filters\VerbFilter;
use app\models\LoginForm;
use app\models\AuthenticationForm;
use app\models\RegistrationForm;
use app\models\ContactForm;
use app\models\Account;
class SiteController extends Controller
{
/**
* {@inheritdoc}
*/
@ -19,7 +22,7 @@ class SiteController extends Controller
{
return [
'access' => [
'class' => AccessControl::className(),
'class' => AccessControl::class,
'only' => ['logout'],
'rules' => [
[
@ -30,7 +33,7 @@ class SiteController extends Controller
],
],
'verbs' => [
'class' => VerbFilter::className(),
'class' => VerbFilter::class,
'actions' => [
'logout' => ['post'],
],
@ -64,26 +67,94 @@ class SiteController extends Controller
return $this->render('index');
}
/**
* Identification action.
*
* @return Response
*/
public function actionIdentification()
{
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
if (Yii::$app->user->isGuest) {
return [
'menu' => '<a onclick="authentication()">Вход</a>',
'_csrf' => Yii::$app->request->getCsrfToken()
];
} else {
$mail = Yii::$app->user->identity->mail;
return [
'menu' => <<<HTML
<p class="m-0">
<a class="text-dark" href="/cart"><i class="fas fa-shopping-cart mr-4"></i></a>
<a class="text-dark" href="/orders"><i class="fas fa-list mr-4"></i></a>
<a class="text-dark" onclick="deauthentication()">Выход ($mail)</a>
</p>
HTML,
'_csrf' => Yii::$app->request->getCsrfToken()
];
}
}
}
/**
* Login action.
*
* @return Response|string
*/
public function actionLogin()
public function actionAuthentication()
{
if (!Yii::$app->user->isGuest) {
return $this->goHome();
$model = new AuthenticationForm(Yii::$app->request->post()['AuthenticationForm'] ?? Yii::$app->request->get()['AuthenticationForm']);
if (Yii::$app->request->isAjax) {
// AJAX-POST-запрос
if (!Yii::$app->user->isGuest) {
// Аккаунт уже авторизован
Yii::$app->response->statusCode = 403;
return [
'form' => $this->renderPartial('index'),
'_csrf' => Yii::$app->request->getCsrfToken()
];
}
Yii::$app->response->format = Response::FORMAT_JSON;
if (isset($model->mail, $model->pswd)) {
if ($model->load(Yii::$app->request->post()) && $model->authentication()) {
return [
'menu' => <<<HTML
<p class="m-0">
<a class="text-dark" href="/cart"><i class="fas fa-shopping-cart mr-4"></i></a>
<a class="text-dark" href="/orders"><i class="fas fa-list mr-4"></i></a>
<a class="text-dark" onclick="deauthentication()">Выход ($model->mail)</a>
</p>
HTML,
'form' => $this->renderPartial('index'),
'_csrf' => Yii::$app->request->getCsrfToken()
];
}
} else {
return [
'menu' => '<a onclick="authentication()">Вход</a>',
'form' => $this->renderPartial('authentication', compact('model')),
'_csrf' => Yii::$app->request->getCsrfToken()
];
}
} else if (Yii::$app->request->isPost) {
// POST-запрос
} else {
// GET-запрос и прочие
if (!Yii::$app->user->isGuest) {
// Аккаунт уже авторизован
Yii::$app->response->redirect('/');
}
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
}
$model->password = '';
return $this->render('login', [
'model' => $model,
]);
return $this->render('authentication', compact('model'));
}
/**
@ -91,11 +162,101 @@ class SiteController extends Controller
*
* @return Response
*/
public function actionLogout()
public function actionDeauthentication()
{
Yii::$app->user->logout();
if (Yii::$app->request->isAjax) {
// AJAX-POST-запрос
return $this->goHome();
Yii::$app->response->format = Response::FORMAT_JSON;
Yii::$app->user->logout();
return [
'menu' => '<a onclick="authentication()">Вход</a>',
'form' => $this->renderPartial('index'),
'_csrf' => Yii::$app->request->getCsrfToken()
];
}
Yii::$app->response->redirect('/');
}
/**
* Login action.
*
* @return Response|string
*/
public function actionRegistration()
{
$model = new RegistrationForm(Yii::$app->request->post()['RegistrationForm'] ?? Yii::$app->request->get()['RegistrationForm']);
if (Yii::$app->request->isAjax) {
// AJAX-POST-запрос
if (!Yii::$app->user->isGuest) {
// Аккаунт уже авторизован
Yii::$app->response->statusCode = 302;
return [
'form' => $this->renderPartial('index'),
'_csrf' => Yii::$app->request->getCsrfToken()
];
}
Yii::$app->response->format = Response::FORMAT_JSON;
if (isset($model->mail, $model->pswd)) {
// Аккаунт передал необходимые параметры
// Инициализация нового аккаунта
$account = new Account();
$account->mail = $model->mail;
$account->pswd = Yii::$app->security->generatePasswordHash($model->pswd);
if ($model->load(Yii::$app->request->post()) && $model->validate() && $account->save()) {
// Данные прошли проверку и аккаунт был создан
return [
'menu' => <<<HTML
<p class="m-0">
<a class="text-dark" href="/cart"><i class="fas fa-shopping-cart mr-4"></i></a>
<a class="text-dark" href="/orders"><i class="fas fa-list mr-4"></i></a>
<a class="text-dark" onclick="deauthentication()">Выход ($account->mail)</a>
</p>
HTML,
'form' => $this->renderPartial('index'),
'_csrf' => Yii::$app->request->getCsrfToken()
];
} else {
// Данные не прошли проверку
Yii::$app->response->statusCode = 400;
return [
'form' => $this->renderPartial('registration', compact('model')),
'_csrf' => Yii::$app->request->getCsrfToken()
];
}
} else {
// Аккаунт не передал необходимые параметры
return [
'menu' => '<a onclick="authentication()">Вход</a>',
'form' => $this->renderPartial('registration', compact('model')),
'_csrf' => Yii::$app->request->getCsrfToken()
];
}
} else if (Yii::$app->request->isPost) {
// POST-запрос
return;
} else {
// GET-запрос и прочие
if (!Yii::$app->user->isGuest) {
// Аккаунт уже авторизован
Yii::$app->response->redirect('/');
}
}
return $this->render('registration', compact('model'));
}
/**

View File

@ -0,0 +1,20 @@
<?php
use explosivebit\arangodb\Migration;
class m201219_074926_create_account_collection extends Migration
{
public function up()
{
$this->createCollection('account');
}
public function down()
{
// $this->delete('accounts', 'mail');
// $this->delete('accounts', 'name');
// $this->delete('accounts', 'pswd');
$this->dropCollection('account');
}
}

View File

@ -0,0 +1,115 @@
<?php
namespace app\models;
use Yii;
use yii\web\IdentityInterface;
use explosivebit\arangodb\ActiveRecord;
class Account extends ActiveRecord implements IdentityInterface
{
public $_mail;
public $_pswd;
public $_name;
public $_simc;
public $_sity;
public $_comp;
public $_taxn;
public $_auth;
/**
* @return string the name of the index associated with this ActiveRecord class.
*/
public static function collectionName()
{
return 'account';
}
/**
* @return array list of attribute names.
*/
public function attributes()
{
return ['mail', 'pswd', 'auth', 'name' => 'sex', 'simc', 'sity', 'comp', 'taxn', 'auth'];
}
/**
* @return int|string current user ID
*/
public function getId()
{
return $this->mail;
}
/**
* @return string current user auth key
*/
public function getAuthKey()
{
return $this->auth;
}
/**
* Finds an identity by the given ID.
*
* @param string|int $id the ID to be looked for
* @return IdentityInterface|null the identity object that matches the given ID.
*/
public static function findIdentity($mail)
{
return static::findOne(['mail' => $mail]);
}
/**
* Finds an identity by the given token.
*
* @param string $token the token to be looked for
* @return IdentityInterface|null the identity object that matches the given token.
*/
public static function findIdentityByAccessToken($pass, $type = null)
{
return static::findOne(['pass' => $pass]);
}
/**
* Finds user by mail
*
* @param string $mail
* @return static|null
*/
public static function findByMail($mail)
{
return static::findOne(['mail' => $mail]);
}
/**
* Validates password
*
* @param string $pswd password to validate
* @return bool if password provided is valid for current user
*/
public function validatePassword($pswd)
{
return Yii::$app->security->validatePassword($pswd, $this->pswd);
}
/**
* @param string $auth
* @return bool if auth key is valid for current user
*/
public function validateAuthKey($auth)
{
return $this->getAuthKey() === $auth;
}
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
if ($this->isNewRecord) {
$this->auth = Yii::$app->security->generateRandomString();
}
return true;
}
return false;
}
}

View File

@ -0,0 +1,91 @@
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use app\models\Account;
/**
* LoginForm is the model behind the login form.
*
* @property-read Account|null $account This property is read-only.
*
*/
class AuthenticationForm extends Model
{
public $mail;
public $pswd;
public $auto = true;
private $account = false;
/**
* @return array the validation rules.
*/
public function rules()
{
return [
// accountname and password are both required
[['mail', 'pswd'], 'required'],
// rememberMe must be a boolean value
['auto', 'boolean'],
// pswd is validated by validatePassword()
['pswd', 'validatePassword'],
];
}
public function attributeLabels()
{
return [
'mail' => 'Почта',
'pswd' => 'Пароль',
'auto' => 'Запомнить'
];
}
/**
* 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()) {
$account = $this->getAccount();
if (!$account || !$account->validatePassword($this->pswd)) {
$this->addError($attribute, 'Не удалось идентифицировать');
}
}
}
/**
* Logs in a account using the provided accountname and password.
* @return bool whether the account is logged in successfully
*/
public function authentication()
{
if ($this->validate()) {
return Yii::$app->user->login($this->getAccount(), $this->auto ? 3600*24*30 : 0);
}
return false;
}
/**
* Finds account by [[accountname]]
*
* @return Account|null
*/
public function getAccount()
{
if ($this->account === false) {
$this->account = Account::findByMail($this->mail);
}
return $this->account;
}
}

View File

@ -1,81 +0,0 @@
<?php
namespace app\models;
use Yii;
use yii\base\Model;
/**
* LoginForm is the model behind the login form.
*
* @property-read User|null $user This property is read-only.
*
*/
class LoginForm extends Model
{
public $username;
public $password;
public $rememberMe = true;
private $_user = false;
/**
* @return array the validation rules.
*/
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
*/
public function getUser()
{
if ($this->_user === false) {
$this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace app\models;
use yii\base\Model;
use app\models\Account;
class RegistrationForm extends Model
{
public $mail;
public $pswd;
public function rules()
{
return [
[['mail', 'pswd'], 'required', 'message' => 'Заполните поле'],
['mail', 'unique', 'targetClass' => Account::class, 'message' => 'Почта уже привязана к другому аккаунту'],
];
}
public function attributeLabels()
{
return [
'mail' => 'Почта',
'pswd' => 'Пароль',
];
}
}

View File

@ -17,7 +17,7 @@ AppAsset::register($this);
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php $this->registerCsrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<title><?= Html::encode($this->title ?? 'SkillParts') ?></title>
<?php $this->head() ?>
</head>
@ -28,13 +28,11 @@ AppAsset::register($this);
<div class="container">
<div class="row mt-3 mt-sm-0 pt-3">
<div class="col-3 col-sm-4 col-md-2 d-flex flex-column justify-content-end logotype">
<img class="img-fluid" src="/img/logos/skillparts.png" alt="SkillParts">
<a href="/"><img class="img-fluid" src="/img/logos/skillparts.png" alt="SkillParts"></a>
</div>
<div class="col ml-auto text-right d-flex flex-column justify-content-end">
<div class="row">
<div class="col">
<p class="m-0"><i class="fas fa-shopping-cart mr-4"></i><i class="fas fa-list mr-4"></i><a>Личный кабинет</a></p>
</div>
<nav id="nav" class="col"></nav>
</div>
</div>
</div>
@ -72,7 +70,7 @@ AppAsset::register($this);
<input id="catalog_search_panel_button_3" class="btn btn-sm5 text-white button_clean" type="radio" name="catalog_search_panel_buttons" value="catalog_search_panel_button_3">
<label class="mb-0 px-3 px-md-4 py-1" for="catalog_search_panel_button_3">Третья кнопка</label> -->
<form class="d-flex catalog_search">
<input type="text" class="form-control col-8 col-lg-10 catalog_search_line" id="productNumber" placeholder="Номер запчасти, например: 45223503481">
<input type="text" class="form-control col-8 col-lg-10 catalog_search_line" id="productNumber" placeholder="Введите номер запчасти, например: 45223503481">
<button type="submit" class="col btn button_clean catalog_search_button">ПОИСК</button>
</form>
</div>
@ -100,9 +98,6 @@ AppAsset::register($this);
<small class="row mb-1"><a>Поставщикам</a></small>
<small class="row mb-1"><a>Партнерская сеть</a></small>
</div>
<!-- <p class="pull-left">&copy; My Company <?= date('Y') ?></p>
<p class="pull-right"><?= Yii::powered() ?></p> -->
</div>
</div>
</footer>

View File

@ -8,35 +8,39 @@ use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
$this->title = 'Login';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-login">
<h1><?= Html::encode($this->title) ?></h1>
<p>Please fill out the following fields to login:</p>
<?php $form = ActiveForm::begin([
'id' => 'login-form',
'id' => 'form_authentication',
'layout' => 'horizontal',
'fieldConfig' => [
'template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>",
'labelOptions' => ['class' => 'col-lg-1 control-label'],
],
'action' => false,
'options' => [
'onsubmit' => 'authentication(this); return false;'
]
]); ?>
<?= $form->field($model, 'username')->textInput(['autofocus' => true]) ?>
<?= $form->field($model, 'mail')->textInput(['autofocus' => true]) ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<?= $form->field($model, 'pswd')->passwordInput() ?>
<?= $form->field($model, 'rememberMe')->checkbox([
'template' => "<div class=\"col-lg-offset-1 col-lg-3\">{input} {label}</div>\n<div class=\"col-lg-8\">{error}</div>",
]) ?>
<?= $form->field($model, 'auto')->checkbox([
'template' => "<div class=\"col-lg-offset-1 col-lg-3\">{input} {label}</div>\n<div class=\"col-lg-8\">{error}</div>",
]) ?>
<div class="form-group">
<div class="col-lg-offset-1 col-lg-11">
<?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
</div>
<div class="form-group">
<div class="col-lg-offset-1 col-lg-11">
<?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
@ -44,4 +48,4 @@ $this->params['breadcrumbs'][] = $this->title;
You may login with <strong>admin/admin</strong> or <strong>demo/demo</strong>.<br>
To modify the username/password, please check out the code <code>app\models\User::$users</code>.
</div>
</div>
</div>

View File

@ -8,7 +8,7 @@ $this->title = 'SkillParts';
<div class="info_panel mb-4">
<div class="container h-100 d-flex flex-column justify-content-center">
<p class="col-lg-8 mb-4 gilroy">Проблема с подбором запчастей?</p>
<button class="text-white btn button_clean button_call">Связаться с менеджером</button>
<a class="text-white btn button_clean button_call" href="/call">Связаться с менеджером</a>
</div>
<div class="h-100 d-flex flex-column justify-content-end">
<img class="img-fluid" src="/img/photos/963K_cutted.webp" alt="Связаться с менеджером">

View File

@ -0,0 +1,21 @@
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
?>
<?php $form = ActiveForm::begin([
'id' => 'form_registration',
'action' => false,
'options' => [
'onsubmit' => 'registration(this); return false;'
]
]) ?>
<?= $form->field($model, 'mail') ?>
<?= $form->field($model, 'pswd')->passwordInput() ?>
<div class="form-group">
<div>
<?= Html::submitButton('Регистрация', ['class' => 'btn btn-success']) ?>
</div>
</div>
<?php ActiveForm::end() ?>

View File

@ -18,15 +18,15 @@ ssl_certificate_key '%sprogdir%/userdata/config/cert_files/server.key'
# ssl_trusted_certificate '';
# Force HTTPS
# add_header Strict-Transport-Security 'max-age=2592000' always;
# if ($scheme ~* ^(?!https).*$) {
# return 301 https://$host$request_uri;
# }
add_header Strict-Transport-Security 'max-age=2592000' always;
if ($scheme ~* ^(?!https).*$) {
return 301 https://$host$request_uri;
}
# Force www.site.com => site.com
# if ($host ~* ^www\.(.+)$) {
# return 301 $scheme://$1$request_uri;
# }
if ($host ~* ^www\.(.+)$) {
return 301 $scheme://$1$request_uri;
}
# Disable access to backup/config/command/log files
# if ($uri ~* ^.+\.(?:bak|co?nf|in[ci]|log|orig|sh|sql|tar|sql|t?gz|cmd|bat)$) {
@ -70,38 +70,6 @@ location / {
include '%sprogdir%/userdata/config/nginx_fastcgi_params.txt';
}
}
# Service configuration (do not edit!)
# ----------------------------
location /openserver/ {
root '%sprogdir%/modules/system/html';
autoindex off;
index index.php index.html index.htm;
%allow%allow all;
allow 127.0.0.0/8;
allow ::1/128;
allow %ips%;
deny all;
location ~* ^/openserver/.+\.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv|svgz?|ttf|ttc|otf|eot|woff2?)$ {
expires 1d;
access_log off;
}
location /openserver/server-status {
stub_status on;
}
location ~ ^/openserver/.*\.php$ {
try_files $fastcgi_script_name =404;
fastcgi_index index.php;
fastcgi_pass backend;
include '%sprogdir%/userdata/config/nginx_fastcgi_params.txt';
}
}
# End service configuration
# ----------------------------
}
# ----------------------------

View File

@ -8,5 +8,5 @@
.bx-wrapper .bx-viewport {
width: 100vw !important;
height: 4rem !important;
height: 2rem !important;
}

View File

@ -0,0 +1,113 @@
function identification() {
$.ajax({
url: '/identification',
type: 'post',
dataType: 'json',
data: { '_csrf': yii.getCsrfToken() },
success: function (data) {
// Обновление документа
document.getElementById('nav').innerHTML = data.menu;
$('meta[name=csrf-token]').prop("content", data._csrf);
// Реинициализация
reinitialization();
}
});
};
function authentication(form) {
if (form == undefined) {
form = { '_csrf': yii.getCsrfToken() };
} else {
form = $(form).serialize();
}
$.ajax({
url: '/authentication',
type: 'post',
dataType: 'json',
data: form,
success: function (data, status) {
// Обновление документа
document.getElementById('nav').innerHTML = data.menu;
document.getElementsByTagName('main')[0].innerHTML = data.form;
$('meta[name=csrf-token]').prop("content", data._csrf);
// Перенаправление
history.pushState({}, document.title, '/');
// Реинициализация
reinitialization();
},
error: function (data, status) {
// Обновление документа
document.getElementsByTagName('main')[0].innerHTML = data.responseJSON.form;
$('meta[name=csrf-token]').prop("content", data.responseJSON._csrf);
if (statis === 403) {
// Перенаправление
history.pushState({}, document.title, '/');
}
// Реинициализация
reinitialization();
}
});
};
function deauthentication() {
$.ajax({
url: '/deauthentication',
type: 'post',
dataType: 'json',
data: { '_csrf': yii.getCsrfToken() },
success: function (data) {
// Обновление документа
document.getElementById('nav').innerHTML = data.menu;
document.getElementsByTagName('main')[0].innerHTML = data.form;
$('meta[name=csrf-token]').prop("content", data._csrf);
// Перенаправление
history.pushState({}, document.title, '/');
// Реинициализация
reinitialization();
}
});
};
function registration(form) {
$.ajax({
url: '/registration',
type: 'post',
dataType: 'json',
data: $(form).serialize(),
success: function (data) {
// Обновление документа
document.getElementById('nav').innerHTML = data.menu;
document.getElementsByTagName('main')[0].innerHTML = data.form;
$('meta[name=csrf-token]').prop("content", data._csrf);
// Перенаправление
history.pushState({}, document.title, '/');
// Реинициализация
reinitialization();
},
error: function (data) {
// Обновление документа
document.getElementsByTagName('main')[0].innerHTML = data.responseJSON.form;
$('meta[name=csrf-token]').prop("content", data.responseJSON._csrf);
if (statis === 403) {
// Перенаправление
history.pushState({}, document.title, '/');
}
// Реинициализация
reinitialization();
}
});
};
document.addEventListener('DOMContentLoaded', identification(), true);

View File

@ -0,0 +1,5 @@
function reinitialization() {
// Функции которые должны быть запущены при инициализации документа
tickerInit('all');
}

View File

@ -1,8 +1,15 @@
$('.ticker').bxSlider({
minSlides: 1,
maxSlides: 18,
slideWidth: 189,
slideMargin: 0,
ticker: true,
speed: 50000
});
function tickerInit(ticker) {
ticker = $('.ticker').bxSlider({
minSlides: 1,
maxSlides: 100,
slideMargin: 0,
ticker: true,
speed: 80000
});
}
function tickerReinit(ticker) {
ticker.reloadSlider();
}
document.addEventListener('DOMContentLoaded', tickerInit(), true);