DEV: Рефакторинг контроллеров (первая часть)
This commit is contained in:
parent
ff742e6152
commit
a41b6c68c4
|
@ -5,41 +5,21 @@ namespace App\Controllers\Auth;
|
|||
use Hleb\Constructor\Handlers\Request;
|
||||
use App\Controllers\Controller;
|
||||
use App\Models\User\UserModel;
|
||||
use Meta, Validation;
|
||||
use Meta;
|
||||
|
||||
use App\Validate\RulesLogin;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$email = Request::getPost('email');
|
||||
$password = Request::getPost('password');
|
||||
$rememberMe = Request::getPostInt('rememberme');
|
||||
$redirect = url('login');
|
||||
$data = Request::getPost();
|
||||
|
||||
Validation::email($email = Request::getPost('email'), $redirect);
|
||||
$user = RulesLogin::rules($data);
|
||||
|
||||
$user = UserModel::userInfo($email);
|
||||
|
||||
if (empty($user['id'])) {
|
||||
is_return(__('msg.no_user'), 'error', $redirect);
|
||||
}
|
||||
|
||||
// Находится ли в бан- листе
|
||||
if (UserModel::isBan($user['id'])) {
|
||||
is_return(__('msg.account_verified'), 'error', $redirect);
|
||||
}
|
||||
|
||||
// Активирован ли E-mail
|
||||
if (!UserModel::isActivated($user['id'])) {
|
||||
is_return(__('msg.not_activated'), 'error', $redirect);
|
||||
}
|
||||
|
||||
if (!password_verify($password, $user['password'])) {
|
||||
is_return(__('msg.not_correct'), 'error', $redirect);
|
||||
}
|
||||
|
||||
// Если нажал "Запомнить"
|
||||
// Устанавливает сеанс пользователя и регистрирует его
|
||||
// If you clicked "Remember", it establishes a user session and registers it
|
||||
// Если нажал "Запомнить", то устанавливает сеанс пользователя и регистрирует его
|
||||
$rememberMe = $data['rememberMe'] ?? false;
|
||||
if ($rememberMe == 1) {
|
||||
(new \App\Controllers\Auth\RememberController())->rememberMe($user['id']);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,9 @@ namespace App\Controllers\Facets;
|
|||
use Hleb\Constructor\Handlers\Request;
|
||||
use App\Controllers\Controller;
|
||||
use App\Models\{FacetModel, SubscriptionModel};
|
||||
use Validation, Meta, UserData;
|
||||
use Meta;
|
||||
|
||||
use App\Validate\RulesFacet;
|
||||
|
||||
class AddFacetController extends Controller
|
||||
{
|
||||
|
@ -27,55 +29,20 @@ class AddFacetController extends Controller
|
|||
// Add topic | blog | category
|
||||
public function create($facet_type)
|
||||
{
|
||||
$facet_title = Request::getPost('facet_title');
|
||||
$facet_description = Request::getPost('facet_description');
|
||||
$facet_short_description = Request::getPost('facet_short_description');
|
||||
$facet_slug = Request::getPost('facet_slug');
|
||||
$facet_seo_title = Request::getPost('facet_seo_title');
|
||||
|
||||
$data = Request::getPost();
|
||||
|
||||
$redirect = ($facet_type == 'category') ? url('web') : url('content.add', ['type' => $facet_type]);
|
||||
|
||||
if ($facet_type == 'blog') {
|
||||
if (!UserData::checkAdmin()) {
|
||||
if (in_array($facet_slug, config('stop-blog'))) {
|
||||
is_return(__('msg.went_wrong'), 'error', $redirect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Validation::Length($facet_title, 3, 64, 'title', $redirect);
|
||||
Validation::Length($facet_description, 34, 225, 'meta_description', $redirect);
|
||||
Validation::Length($facet_short_description, 9, 160, 'short_description', $redirect);
|
||||
Validation::Length($facet_seo_title, 4, 225, 'slug', $redirect);
|
||||
|
||||
// Slug
|
||||
Validation::Length($facet_slug, 3, 43, 'slug', $redirect);
|
||||
|
||||
if (!preg_match('/^[a-zA-Z0-9-]+$/u', $facet_slug)) {
|
||||
is_return(__('msg.slug_correctness', ['name' => '«' . __('msg.slug') . '»']), 'error', $redirect);
|
||||
}
|
||||
|
||||
if (FacetModel::uniqueSlug($facet_slug, $facet_type)) {
|
||||
is_return(__('msg.repeat_url'), 'error', $redirect);
|
||||
}
|
||||
|
||||
if (preg_match('/\s/', $facet_slug) || strpos($facet_slug, ' ')) {
|
||||
is_return(__('msg.url_gaps'), 'error', $redirect);
|
||||
}
|
||||
RulesFacet::rulesAdd($data, $facet_type);
|
||||
|
||||
$type = $facet_type ?? 'topic';
|
||||
$facet_slug = strtolower($facet_slug);
|
||||
|
||||
$new_facet_id = FacetModel::add(
|
||||
[
|
||||
'facet_title' => $facet_title,
|
||||
'facet_description' => $facet_description,
|
||||
'facet_short_description' => $facet_short_description,
|
||||
'facet_slug' => $facet_slug,
|
||||
'facet_title' => $data['facet_title'],
|
||||
'facet_description' => $data['facet_description'],
|
||||
'facet_short_description' => $data['facet_short_description'],
|
||||
'facet_slug' => strtolower($data['facet_slug']),
|
||||
'facet_img' => 'facet-default.png',
|
||||
'facet_seo_title' => $facet_seo_title,
|
||||
'facet_seo_title' => $data['facet_seo_title'],
|
||||
'facet_user_id' => $this->user['id'],
|
||||
'facet_type' => $type,
|
||||
]
|
||||
|
|
|
@ -6,11 +6,13 @@ use Hleb\Constructor\Handlers\Request;
|
|||
use App\Controllers\Controller;
|
||||
use App\Models\User\UserModel;
|
||||
use App\Models\{FacetModel, PostModel};
|
||||
use Validation, UploadImage, Meta, UserData;
|
||||
use UploadImage, Meta, UserData;
|
||||
|
||||
use App\Traits\Author;
|
||||
use App\Traits\Related;
|
||||
|
||||
use App\Validate\RulesFacet;
|
||||
|
||||
class EditFacetController extends Controller
|
||||
{
|
||||
use Author;
|
||||
|
@ -52,63 +54,16 @@ class EditFacetController extends Controller
|
|||
{
|
||||
$data = Request::getPost();
|
||||
|
||||
// Хакинг формы (тип фасета)
|
||||
// ['topic', 'blog', 'category', 'section']
|
||||
if (!in_array($data['facet_type'], config('facets.permitted'))) {
|
||||
is_return(__('msg.went_wrong'), 'error');
|
||||
}
|
||||
|
||||
// Получим массив данных существующего фасета и проверим его наличие
|
||||
$facet = FacetModel::uniqueById((int)$data['facet_id'] ?? 0);
|
||||
if ($facet == false) {
|
||||
is_return(__('msg.went_wrong'), 'error');
|
||||
}
|
||||
|
||||
$redirect = url('content.edit', ['type' => $facet['facet_type'], 'id' => $facet['facet_id']]);
|
||||
|
||||
// Доступ получает только автор и админ
|
||||
if ($facet['facet_user_id'] != $this->user['id'] && !UserData::checkAdmin()) {
|
||||
is_return(__('msg.went_wrong'), 'error', $redirect);
|
||||
}
|
||||
|
||||
// Изменять тип темы может только персонал
|
||||
$new_type = $facet['facet_type'];
|
||||
if ($data['facet_type'] != $facet['facet_type']) {
|
||||
if (UserData::checkAdmin()) $new_type = $data['facet_type'];
|
||||
}
|
||||
|
||||
// Проверка длины
|
||||
Validation::Length($data['facet_title'], 3, 64, 'title', $redirect);
|
||||
Validation::Length($data['facet_description'], 34, 225, 'meta_description', $redirect);
|
||||
Validation::Length($data['facet_short_description'], 9, 160, 'short_description', $redirect);
|
||||
Validation::Length($data['facet_seo_title'], 4, 225, 'slug', $redirect);
|
||||
Validation::Length($data['facet_seo_title'], 0, 225, 'info', $redirect);
|
||||
|
||||
// Slug
|
||||
Validation::Length($data['facet_slug'], 3, 43, 'slug', $redirect);
|
||||
|
||||
if (!preg_match('/^[a-zA-Z0-9-]+$/u', $data['facet_slug'])) {
|
||||
is_return(__('msg.slug_correctness', ['name' => '«' . __('msg.slug') . '»']), 'error', $redirect);
|
||||
}
|
||||
|
||||
if (preg_match('/\s/', $data['facet_slug']) || strpos($data['facet_slug'], ' ')) {
|
||||
is_return(__('msg.url_gaps'), 'error', $redirect);
|
||||
}
|
||||
$new_type = RulesFacet::rulesEdit($data, $facet, $this->user['id']);
|
||||
|
||||
UploadImage::set($_FILES, $facet['facet_id'], 'facet');
|
||||
|
||||
$facet_user_id = $this->editAuthor($facet['facet_user_id'], Request::getPost('user_id'));
|
||||
|
||||
// Проверим повтор URL
|
||||
if ($data['facet_slug'] != $facet['facet_slug']) {
|
||||
if (FacetModel::uniqueSlug($data['facet_slug'], $new_type)) {
|
||||
is_return(__('msg.repeat_url'), 'error', $redirect);
|
||||
}
|
||||
}
|
||||
|
||||
$post_related = $this->relatedPost();
|
||||
$facet_slug = strtolower($data['facet_slug']);
|
||||
|
||||
$facet_top_level = $data['facet_top_level'] ?? false;
|
||||
$facet_view_policy = $data['facet_view_policy'] ?? false;
|
||||
|
||||
|
@ -119,7 +74,7 @@ class EditFacetController extends Controller
|
|||
'facet_description' => $data['facet_description'],
|
||||
'facet_short_description' => $data['facet_short_description'],
|
||||
'facet_info' => $data['facet_info'],
|
||||
'facet_slug' => $facet_slug,
|
||||
'facet_slug' => strtolower($data['facet_slug']),
|
||||
'facet_seo_title' => $data['facet_seo_title'],
|
||||
'facet_view_policy' => $facet_view_policy == 'on' ? 1 : 0,
|
||||
'facet_user_id' => $facet_user_id,
|
||||
|
|
|
@ -6,8 +6,9 @@ use Hleb\Constructor\Handlers\Request;
|
|||
use App\Controllers\Controller;
|
||||
use App\Models\Item\{WebModel, UserAreaModel};
|
||||
use App\Models\{SubscriptionModel, ActionModel, FacetModel, NotificationModel};
|
||||
use Utopia\Domains\Domain;
|
||||
use UserData, Meta, Validation, Access;
|
||||
use UserData, Meta, Access;
|
||||
|
||||
use App\Validate\RulesItem;
|
||||
|
||||
class AddItemController extends Controller
|
||||
{
|
||||
|
@ -39,28 +40,9 @@ class AddItemController extends Controller
|
|||
// Checks and directly adding
|
||||
public function create()
|
||||
{
|
||||
$url = Request::getPost('url');
|
||||
$redirect = url('content.add', ['type' => 'item']);
|
||||
$data = Request::getPost();
|
||||
|
||||
Validation::url($url, $redirect);
|
||||
|
||||
// Check if the domain exists in the system
|
||||
// Проверим наличие домена в системе
|
||||
if ($domain = self::getDomain($url)) {
|
||||
is_return(__('web.site_replay'), 'error', $redirect);
|
||||
}
|
||||
|
||||
// Get a first level domain
|
||||
// Получим данные домена первого уровня
|
||||
$basic_host = self::domain($url);
|
||||
|
||||
// Check the length of the site name
|
||||
// Проверим длину названия сайта
|
||||
Validation::length(Request::getPost('title'), 14, 250, 'title', $redirect);
|
||||
|
||||
// Make the description optional for publication (it will still be rewritten)
|
||||
// Сделать описание необязательным для публикации (оно все равно будет переписано)
|
||||
$content = Request::getPost('content') ?? __('web.desc_formed');
|
||||
$basic_host = RulesItem::rulesAdd($data);
|
||||
|
||||
// Instant accommodation for staff only
|
||||
// Мгновенное размещение только для персонала
|
||||
|
@ -69,10 +51,10 @@ class AddItemController extends Controller
|
|||
|
||||
$item_last = WebModel::add(
|
||||
[
|
||||
'item_url' => $url,
|
||||
'item_url' => $data['url'],
|
||||
'item_domain' => $basic_host,
|
||||
'item_title' => Request::getPost('title'),
|
||||
'item_content' => $content,
|
||||
'item_title' => $data['title'],
|
||||
'item_content' => $data['content'] ?? __('web.desc_formed'),
|
||||
'item_published' => $published,
|
||||
'item_user_id' => $this->user['id'],
|
||||
'item_close_replies' => Request::getPost('close_replies') == 'on' ? 1 : null,
|
||||
|
@ -119,19 +101,4 @@ class AddItemController extends Controller
|
|||
|
||||
is_return(__('web.site_added'), 'success', url('web'));
|
||||
}
|
||||
|
||||
public static function getDomain($url)
|
||||
{
|
||||
$basic_host = self::domain($url);
|
||||
|
||||
return WebModel::getItemOne($basic_host, 1);
|
||||
}
|
||||
|
||||
public static function domain($url)
|
||||
{
|
||||
$parse = parse_url($url);
|
||||
$domain = new Domain($parse['host']);
|
||||
|
||||
return $domain->getRegisterable();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,13 @@ use App\Controllers\Controller;
|
|||
use App\Models\Item\WebModel;
|
||||
use App\Models\{FacetModel, PostModel, NotificationModel};
|
||||
use App\Models\User\UserModel;
|
||||
use Validation, UserData, Meta, Access;
|
||||
use UserData, Meta, Access;
|
||||
|
||||
use App\Traits\Author;
|
||||
use App\Traits\Related;
|
||||
|
||||
use App\Validate\RulesItem;
|
||||
|
||||
class EditItemController extends Controller
|
||||
{
|
||||
use Author;
|
||||
|
@ -59,12 +61,8 @@ class EditItemController extends Controller
|
|||
public function change()
|
||||
{
|
||||
$data = Request::getPost();
|
||||
$redirect = url('content.add', ['type' => 'item']);
|
||||
|
||||
$item = WebModel::getItemId($data['item_id']);
|
||||
if (!$item) {
|
||||
return true;
|
||||
}
|
||||
$item = RulesItem::rulesEdit($data);
|
||||
|
||||
// Only the site author and staff can edit
|
||||
// Редактировать может только автор сайта и персонал
|
||||
|
@ -72,13 +70,6 @@ class EditItemController extends Controller
|
|||
return true;
|
||||
}
|
||||
|
||||
// Check the length
|
||||
// Проверим длину
|
||||
Validation::length($data['title'], 14, 250, 'title', $redirect);
|
||||
Validation::length($data['content'], 24, 1500, 'description', $redirect);
|
||||
|
||||
Validation::url($data['url'], $redirect);
|
||||
|
||||
// Связанные посты
|
||||
$json_post = $data['post_select'] ?? [];
|
||||
$arr_post = json_decode($json_post, true);
|
||||
|
@ -91,7 +82,8 @@ class EditItemController extends Controller
|
|||
|
||||
// If not staff, then we make the site inactive
|
||||
// Если не персонал, то делаем сайт не активным
|
||||
$published = $data['published'] == 'on' ? 1 : 0;
|
||||
$published = $data['published'] ?? false;
|
||||
$published = $published == 'on' ? 1 : 0;
|
||||
$published = UserData::checkAdmin() ? $published : 0;
|
||||
|
||||
$new_user_id = $this->editAuthor($item['item_user_id'], Request::getPost('user_id'));
|
||||
|
@ -106,13 +98,13 @@ class EditItemController extends Controller
|
|||
'item_content_soft' => $data['content_soft'] ?? '',
|
||||
'item_published' => $published,
|
||||
'item_user_id' => $new_user_id,
|
||||
'item_close_replies' => self::toggle($data['close_replies']),
|
||||
'item_is_forum' => self::toggle($data['forum']),
|
||||
'item_is_portal' => self::toggle($data['portal']),
|
||||
'item_is_blog' => self::toggle($data['blog']),
|
||||
'item_is_reference' => self::toggle($data['reference']),
|
||||
'item_is_soft' => self::toggle($data['soft']),
|
||||
'item_is_github' => self::toggle($data['github']),
|
||||
'item_close_replies' => self::toggle($data['close_replies'] ?? false),
|
||||
'item_is_forum' => self::toggle($data['forum'] ?? false),
|
||||
'item_is_portal' => self::toggle($data['portal'] ?? false),
|
||||
'item_is_blog' => self::toggle($data['blog'] ?? false),
|
||||
'item_is_reference' => self::toggle($data['reference'] ?? false),
|
||||
'item_is_soft' => self::toggle($data['soft'] ?? false),
|
||||
'item_is_github' => self::toggle($data['github'] ?? false),
|
||||
'item_post_related' => $post_related ?? null,
|
||||
'item_github_url' => $data['github_url'] ?? null,
|
||||
]
|
||||
|
@ -138,18 +130,15 @@ class EditItemController extends Controller
|
|||
foreach ($topics as $row) {
|
||||
$arr[] = $row;
|
||||
}
|
||||
|
||||
|
||||
FacetModel::addItemFacets($arr, $item['item_id']);
|
||||
}
|
||||
|
||||
is_return(__('msg.change_saved'), 'success', url('web'));
|
||||
}
|
||||
|
||||
|
||||
public static function toggle($value)
|
||||
{
|
||||
$data = $value ?? false;
|
||||
|
||||
return $data == 'on' ? 1 : null;
|
||||
return $value == 'on' ? 1 : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,9 +6,10 @@ use Hleb\Constructor\Handlers\Request;
|
|||
use App\Controllers\Controller;
|
||||
use App\Models\Item\WebModel;
|
||||
use App\Models\{SubscriptionModel, ActionModel, PostModel, FacetModel, NotificationModel};
|
||||
use Content, UploadImage, Discord, Validation, URLScraper, Meta, UserData;
|
||||
use Content, UploadImage, Discord, URLScraper, Meta, UserData;
|
||||
|
||||
use Utopia\Domains\Domain;
|
||||
use App\Validate\RulesPost;
|
||||
|
||||
use App\Traits\Slug;
|
||||
use App\Traits\Related;
|
||||
|
@ -66,12 +67,10 @@ class AddPostController extends Controller
|
|||
// Проверим стоп слова, url
|
||||
$trigger = (new \App\Controllers\AuditController())->prohibitedContent($content);
|
||||
|
||||
$post_title = str_replace(" ", '', $fields['post_title']);
|
||||
Validation::length($post_title, 6, 250, 'title', $redirect);
|
||||
Validation::length($content, 6, 25000, 'content', $redirect);
|
||||
RulesPost::rules($fields['post_title'], $content, $redirect);
|
||||
|
||||
if ($post_url) {
|
||||
$site = $this->addUrl($post_url, $post_title);
|
||||
$site = $this->addUrl($post_url, $fields['post_title']);
|
||||
}
|
||||
|
||||
// Обложка поста
|
||||
|
@ -79,7 +78,7 @@ class AddPostController extends Controller
|
|||
$post_img = UploadImage::coverPost($_FILES['images'], 0, $redirect, $this->user['id']);
|
||||
}
|
||||
|
||||
if (PostModel::getSlug($slug = $this->getSlug($post_title))) {
|
||||
if (PostModel::getSlug($slug = $this->getSlug($fields['post_title']))) {
|
||||
$slug = $slug . "-";
|
||||
}
|
||||
|
||||
|
@ -93,7 +92,7 @@ class AddPostController extends Controller
|
|||
|
||||
$last_id = PostModel::create(
|
||||
[
|
||||
'post_title' => $post_title,
|
||||
'post_title' => $fields['post_title'],
|
||||
'post_content' => $content,
|
||||
'post_content_img' => $post_img ?? '',
|
||||
'post_thumb_img' => $site['og_img'] ?? '',
|
||||
|
@ -134,7 +133,7 @@ class AddPostController extends Controller
|
|||
|
||||
if (config('integration.discord')) {
|
||||
if ($fields['content_tl'] == 0 && $fields['post_draft'] == 0) {
|
||||
Discord::AddWebhook($content, $post_title, $redirect);
|
||||
Discord::AddWebhook($content, $fields['post_title'], $redirect);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,12 +6,14 @@ use Hleb\Constructor\Handlers\Request;
|
|||
use App\Controllers\Controller;
|
||||
use App\Models\User\UserModel;
|
||||
use App\Models\{FacetModel, PostModel};
|
||||
use UploadImage, Meta, Validation, Access, UserData;
|
||||
use UploadImage, Meta, Access, UserData;
|
||||
|
||||
use App\Traits\Slug;
|
||||
use App\Traits\Author;
|
||||
use App\Traits\Related;
|
||||
|
||||
use App\Validate\RulesPost;
|
||||
|
||||
class EditPostController extends Controller
|
||||
{
|
||||
use Slug;
|
||||
|
@ -69,9 +71,7 @@ class EditPostController extends Controller
|
|||
|
||||
$redirect = url('content.edit', ['type' => $post['post_type'], 'id' => $post_id]);
|
||||
|
||||
$title = str_replace(" ", '', Request::getPost('post_title'));
|
||||
Validation::length($title, 6, 250, 'title', $redirect);
|
||||
Validation::length($content, 6, 25000, 'content', $redirect);
|
||||
RulesPost::rules($title = Request::getPost('post_title'), $content, $redirect);
|
||||
|
||||
// Form hacking
|
||||
if ($post['post_draft'] == 0) {
|
||||
|
|
95
app/Validate/RulesFacet.php
Normal file
95
app/Validate/RulesFacet.php
Normal file
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
namespace App\Validate;
|
||||
|
||||
use App\Models\FacetModel;
|
||||
use UserData;
|
||||
|
||||
class RulesFacet extends Validator
|
||||
{
|
||||
public static function rulesAdd($data, $facet_type)
|
||||
{
|
||||
$redirect = ($facet_type == 'category') ? url('web') : url('content.add', ['type' => $facet_type]);
|
||||
|
||||
if ($facet_type == 'blog') {
|
||||
if (!UserData::checkAdmin()) {
|
||||
if (in_array($data['facet_slug'], config('stop-blog'))) {
|
||||
is_return(__('msg.went_wrong'), 'error', $redirect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self::Length($data['facet_title'], 3, 64, 'title', $redirect);
|
||||
self::Length($data['facet_description'], 34, 225, 'meta_description', $redirect);
|
||||
self::Length($data['facet_short_description'], 9, 160, 'short_description', $redirect);
|
||||
self::Length($data['facet_seo_title'], 4, 225, 'slug', $redirect);
|
||||
|
||||
// Slug
|
||||
self::Length($data['facet_slug'], 3, 43, 'slug', $redirect);
|
||||
|
||||
if (!preg_match('/^[a-zA-Z0-9-]+$/u', $data['facet_slug'])) {
|
||||
is_return(__('msg.slug_correctness', ['name' => '«' . __('msg.slug') . '»']), 'error', $redirect);
|
||||
}
|
||||
|
||||
if (FacetModel::uniqueSlug($data['facet_slug'], $facet_type)) {
|
||||
is_return(__('msg.repeat_url'), 'error', $redirect);
|
||||
}
|
||||
|
||||
if (preg_match('/\s/', $data['facet_slug']) || strpos($data['facet_slug'], ' ')) {
|
||||
is_return(__('msg.url_gaps'), 'error', $redirect);
|
||||
}
|
||||
}
|
||||
|
||||
public static function rulesEdit($data, $facet, $user_id)
|
||||
{
|
||||
// Хакинг формы (тип фасета)
|
||||
// ['topic', 'blog', 'category', 'section']
|
||||
if (!in_array($data['facet_type'], config('facets.permitted'))) {
|
||||
is_return(__('msg.went_wrong'), 'error');
|
||||
}
|
||||
|
||||
if ($facet == false) {
|
||||
is_return(__('msg.went_wrong'), 'error');
|
||||
}
|
||||
|
||||
$redirect = url('content.edit', ['type' => $facet['facet_type'], 'id' => $facet['facet_id']]);
|
||||
|
||||
// Доступ получает только автор и админ
|
||||
if ($facet['facet_user_id'] != $user_id && !UserData::checkAdmin()) {
|
||||
is_return(__('msg.went_wrong'), 'error', $redirect);
|
||||
}
|
||||
|
||||
// Изменять тип темы может только персонал
|
||||
$new_type = $facet['facet_type'];
|
||||
if ($data['facet_type'] != $facet['facet_type']) {
|
||||
if (UserData::checkAdmin()) $new_type = $data['facet_type'];
|
||||
}
|
||||
|
||||
// Проверка длины
|
||||
self::Length($data['facet_title'], 3, 64, 'title', $redirect);
|
||||
self::Length($data['facet_description'], 34, 225, 'meta_description', $redirect);
|
||||
self::Length($data['facet_short_description'], 9, 160, 'short_description', $redirect);
|
||||
self::Length($data['facet_seo_title'], 4, 225, 'slug', $redirect);
|
||||
self::Length($data['facet_seo_title'], 0, 225, 'info', $redirect); // ??????????????????????????????????
|
||||
|
||||
// Slug
|
||||
self::Length($data['facet_slug'], 3, 43, 'slug', $redirect);
|
||||
|
||||
if (!preg_match('/^[a-zA-Z0-9-]+$/u', $data['facet_slug'])) {
|
||||
is_return(__('msg.slug_correctness', ['name' => '«' . __('msg.slug') . '»']), 'error', $redirect);
|
||||
}
|
||||
|
||||
if (preg_match('/\s/', $data['facet_slug']) || strpos($data['facet_slug'], ' ')) {
|
||||
is_return(__('msg.url_gaps'), 'error', $redirect);
|
||||
}
|
||||
|
||||
// Проверим повтор URL
|
||||
if ($data['facet_slug'] != $facet['facet_slug']) {
|
||||
if (FacetModel::uniqueSlug($data['facet_slug'], $new_type)) {
|
||||
is_return(__('msg.repeat_url'), 'error', $redirect);
|
||||
}
|
||||
}
|
||||
|
||||
return $new_type;
|
||||
}
|
||||
}
|
58
app/Validate/RulesItem.php
Normal file
58
app/Validate/RulesItem.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace App\Validate;
|
||||
|
||||
use App\Models\Item\WebModel;
|
||||
use Utopia\Domains\Domain;
|
||||
|
||||
class RulesItem extends Validator
|
||||
{
|
||||
public static function rulesAdd($data)
|
||||
{
|
||||
$redirect = url('content.add', ['type' => 'item']);
|
||||
|
||||
self::url($data['url'], $redirect);
|
||||
|
||||
if ($domain = self::getDomain($data['url'])) {
|
||||
is_return(__('web.site_replay'), 'error', $redirect);
|
||||
}
|
||||
|
||||
self::length($data['title'], 14, 250, 'title', $redirect);
|
||||
|
||||
$basic_host = self::domain($data['url']);
|
||||
|
||||
return $basic_host;
|
||||
}
|
||||
|
||||
public static function rulesEdit($data)
|
||||
{
|
||||
$redirect = url('content.add', ['type' => 'item']);
|
||||
|
||||
$item = WebModel::getItemId($data['item_id']);
|
||||
if (!$item) {
|
||||
return true;
|
||||
}
|
||||
|
||||
self::length($data['title'], 14, 250, 'title', $redirect);
|
||||
self::length($data['content'], 24, 1500, 'description', $redirect);
|
||||
|
||||
self::url($data['url'], $redirect);
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getDomain($url)
|
||||
{
|
||||
$basic_host = self::domain($url);
|
||||
|
||||
return WebModel::getItemOne($basic_host, 1);
|
||||
}
|
||||
|
||||
public static function domain($url)
|
||||
{
|
||||
$parse = parse_url($url);
|
||||
$domain = new Domain($parse['host']);
|
||||
|
||||
return $domain->getRegisterable();
|
||||
}
|
||||
}
|
37
app/Validate/RulesLogin.php
Normal file
37
app/Validate/RulesLogin.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace App\Validate;
|
||||
|
||||
use App\Models\User\UserModel;
|
||||
|
||||
class RulesLogin extends Validator
|
||||
{
|
||||
public static function rules($data)
|
||||
{
|
||||
$redirect = url('login');
|
||||
|
||||
self::email($data['email'], $redirect);
|
||||
|
||||
$user = UserModel::userInfo($data['email']);
|
||||
|
||||
if (empty($user['id'])) {
|
||||
is_return(__('msg.no_user'), 'error', $redirect);
|
||||
}
|
||||
|
||||
// Is it on the ban list
|
||||
// Находится ли в бан- листе
|
||||
if (UserModel::isBan($user['id'])) {
|
||||
is_return(__('msg.account_verified'), 'error', $redirect);
|
||||
}
|
||||
|
||||
if (!UserModel::isActivated($user['id'])) {
|
||||
is_return(__('msg.not_activated'), 'error', $redirect);
|
||||
}
|
||||
|
||||
if (!password_verify($data['password'], $user['password'])) {
|
||||
is_return(__('msg.not_correct'), 'error', $redirect);
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
16
app/Validate/RulesPost.php
Normal file
16
app/Validate/RulesPost.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace App\Validate;
|
||||
|
||||
class RulesPost extends Validator
|
||||
{
|
||||
public static function rules($title, $content, $redirect)
|
||||
{
|
||||
$title = str_replace(" ", '', $title);
|
||||
|
||||
self::length($title, 6, 250, 'title', $redirect);
|
||||
self::length($content, 6, 25000, 'content', $redirect);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -30,5 +30,4 @@ class RulesUserInvitation extends Validator
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ class RulesUserSetting extends Validator
|
|||
public static function rulesSetting($data)
|
||||
{
|
||||
$redirect = url('setting');
|
||||
|
||||
|
||||
self::length($data['name'], 5, 11, 'name', $redirect);
|
||||
self::length($data['about'], 5, 255, 'about', $redirect);
|
||||
|
||||
|
@ -19,11 +19,11 @@ class RulesUserSetting extends Validator
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static function rulesSecurity($data, $email)
|
||||
{
|
||||
$redirect = '/setting/security';
|
||||
|
||||
|
||||
if ($data['password2'] != $data['password3']) {
|
||||
is_return(__('msg.pass_match_err'), 'error', $redirect);
|
||||
}
|
||||
|
|
|
@ -64,7 +64,9 @@
|
|||
</div>
|
||||
|
||||
<?php if ($post['post_thumb_img']) : ?>
|
||||
<?= Img::image($post['post_thumb_img'], $post['post_title'], 'thumb max-w-100', 'post', 'thumbnails'); ?>
|
||||
<div class="img-preview">
|
||||
<?= Img::image($post['post_thumb_img'], $post['post_title'], 'medium-zoom-image', 'post', 'thumbnails'); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="post-body max-w780 full">
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<main>
|
||||
<div class="box">
|
||||
<h1 class="mb10 text-2xl font-normal"><?= __('app.invite'); ?></h1>
|
||||
<form class="" action="/invite" method="post">
|
||||
<form action="/invite" method="post">
|
||||
<?php csrf_field(); ?>
|
||||
<fieldset>
|
||||
<label for="invite"><?= __('app.code'); ?></label>
|
||||
|
|
Loading…
Reference in a new issue