FIX: Видимость удаленного сайта
+ уберем валидацию из контроллеров (тестирование)
This commit is contained in:
parent
775ce7516a
commit
57b65c6ac6
|
@ -5,9 +5,9 @@ namespace App\Controllers\User;
|
||||||
use Hleb\Constructor\Handlers\Request;
|
use Hleb\Constructor\Handlers\Request;
|
||||||
use App\Controllers\Controller;
|
use App\Controllers\Controller;
|
||||||
use App\Models\User\{SettingModel, UserModel};
|
use App\Models\User\{SettingModel, UserModel};
|
||||||
use UploadImage, Validation, Meta, UserData, Img;
|
use UploadImage, Meta, UserData, Img;
|
||||||
|
|
||||||
use App\Validation\RulesEditSetting;
|
use App\Validate\RulesUserSetting;
|
||||||
|
|
||||||
class SettingController extends Controller
|
class SettingController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -53,7 +53,7 @@ class SettingController extends Controller
|
||||||
// Profile setup form
|
// Profile setup form
|
||||||
// Форма настройки профиля
|
// Форма настройки профиля
|
||||||
function settingForm()
|
function settingForm()
|
||||||
{
|
{
|
||||||
return $this->render(
|
return $this->render(
|
||||||
'/user/setting/setting',
|
'/user/setting/setting',
|
||||||
'base',
|
'base',
|
||||||
|
@ -70,7 +70,7 @@ class SettingController extends Controller
|
||||||
{
|
{
|
||||||
$data = Request::getPost();
|
$data = Request::getPost();
|
||||||
|
|
||||||
RulesEditSetting::rules($data);
|
RulesUserSetting::rulesSetting($data);
|
||||||
|
|
||||||
$user = UserModel::getUser($this->user['id'], 'id');
|
$user = UserModel::getUser($this->user['id'], 'id');
|
||||||
|
|
||||||
|
@ -144,27 +144,11 @@ class SettingController extends Controller
|
||||||
|
|
||||||
function securityEdit()
|
function securityEdit()
|
||||||
{
|
{
|
||||||
$password = Request::getPost('password');
|
$data = Request::getPost();
|
||||||
$password2 = Request::getPost('password2');
|
|
||||||
$password3 = Request::getPost('password3');
|
RulesUserSetting::rulesSecurity($data, $this->user['email']);
|
||||||
|
|
||||||
$redirect = '/setting/security';
|
$newpass = password_hash($data['password2'], PASSWORD_BCRYPT);
|
||||||
if ($password2 != $password3) {
|
|
||||||
is_return(__('msg.pass_match_err'), 'error', $redirect);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (substr_count($password2, ' ') > 0) {
|
|
||||||
is_return(__('msg.password_spaces'), 'error', $redirect);
|
|
||||||
}
|
|
||||||
|
|
||||||
Validation::length($password2, 8, 32, 'password', $redirect);
|
|
||||||
|
|
||||||
$userInfo = UserModel::userInfo($this->user['email']);
|
|
||||||
if (!password_verify($password, $userInfo['password'])) {
|
|
||||||
is_return(__('msg.old_error'), 'error', $redirect);
|
|
||||||
}
|
|
||||||
|
|
||||||
$newpass = password_hash($password2, PASSWORD_BCRYPT);
|
|
||||||
|
|
||||||
SettingModel::editPassword(['id' => $this->user['id'], 'password' => $newpass]);
|
SettingModel::editPassword(['id' => $this->user['id'], 'password' => $newpass]);
|
||||||
|
|
||||||
|
|
|
@ -39,15 +39,15 @@ class UserAreaModel extends \Hleb\Scheme\App\Models\MainModel
|
||||||
GROUP BY relation_item_id
|
GROUP BY relation_item_id
|
||||||
) AS rel
|
) AS rel
|
||||||
ON rel.relation_item_id = item_id
|
ON rel.relation_item_id = item_id
|
||||||
WHERE item_user_id = :user_id ORDER BY item_id DESC
|
WHERE item_user_id = :user_id AND item_is_deleted = 0
|
||||||
LIMIT :start, :limit ";
|
ORDER BY item_id DESC LIMIT :start, :limit ";
|
||||||
|
|
||||||
return DB::run($sql, ['user_id' => $user_id, 'start' => $start, 'limit' => $limit])->fetchAll();
|
return DB::run($sql, ['user_id' => $user_id, 'start' => $start, 'limit' => $limit])->fetchAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getUserSitesCount($user_id)
|
public static function getUserSitesCount($user_id)
|
||||||
{
|
{
|
||||||
$sql = "SELECT item_id, item_is_deleted FROM items WHERE item_user_id = :user_id ORDER BY item_id DESC";
|
$sql = "SELECT item_id, item_is_deleted FROM items WHERE item_user_id = :user_id AND item_is_deleted = 0 ORDER BY item_id DESC";
|
||||||
|
|
||||||
return DB::run($sql, ['user_id' => $user_id])->rowCount();
|
return DB::run($sql, ['user_id' => $user_id])->rowCount();
|
||||||
}
|
}
|
||||||
|
|
44
app/Validate/RulesUserSetting.php
Normal file
44
app/Validate/RulesUserSetting.php
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Validate;
|
||||||
|
|
||||||
|
use App\Models\User\UserModel;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
if ($data['public_email']) {
|
||||||
|
self::email($data['public_email'], $redirect);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function rulesSecurity($data, $email)
|
||||||
|
{
|
||||||
|
$redirect = '/setting/security';
|
||||||
|
|
||||||
|
if ($data['password2'] != $data['password3']) {
|
||||||
|
is_return(__('msg.pass_match_err'), 'error', $redirect);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (substr_count($data['password2'], ' ') > 0) {
|
||||||
|
is_return(__('msg.password_spaces'), 'error', $redirect);
|
||||||
|
}
|
||||||
|
|
||||||
|
self::length($data['password2'], 8, 32, 'password', $redirect);
|
||||||
|
|
||||||
|
$userInfo = UserModel::userInfo($email);
|
||||||
|
if (!password_verify($data['password'], $userInfo['password'])) {
|
||||||
|
is_return(__('msg.old_error'), 'error', $redirect);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Validation;
|
namespace App\Validate;
|
||||||
|
|
||||||
class Validation
|
class Validator
|
||||||
{
|
{
|
||||||
// Validation::email
|
|
||||||
public static function email($email, $redirect)
|
public static function email($email, $redirect)
|
||||||
{
|
{
|
||||||
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
|
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
|
||||||
|
@ -13,7 +12,6 @@ class Validation
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validation::url
|
|
||||||
public static function url($url, $redirect)
|
public static function url($url, $redirect)
|
||||||
{
|
{
|
||||||
if (filter_var($url, FILTER_VALIDATE_URL) === false) {
|
if (filter_var($url, FILTER_VALIDATE_URL) === false) {
|
||||||
|
@ -22,7 +20,6 @@ class Validation
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validation::length
|
|
||||||
public static function length($content, $min, $max, $name, $redirect = '/')
|
public static function length($content, $min, $max, $name, $redirect = '/')
|
||||||
{
|
{
|
||||||
if (self::getStrlen($content) < $min || self::getStrlen($content) > $max) {
|
if (self::getStrlen($content) < $min || self::getStrlen($content) > $max) {
|
|
@ -1,20 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Validation;
|
|
||||||
|
|
||||||
class RulesEditSetting extends Validation
|
|
||||||
{
|
|
||||||
public static function rules($data)
|
|
||||||
{
|
|
||||||
$redirect = url('setting');
|
|
||||||
|
|
||||||
self::length($data['name'], 5, 11, 'name', $redirect);
|
|
||||||
self::length($data['about'], 5, 255, 'about', $redirect);
|
|
||||||
|
|
||||||
if ($data['public_email']) {
|
|
||||||
self::email($data['public_email'], $redirect);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue