1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-25 12:09:09 +08:00

1.精简AccountSearchTrait

2.优化CsrfToken
3.优化kg_setting
4.修正CommentInfo
This commit is contained in:
xiaochong0302 2024-12-02 17:14:31 +08:00
parent a0e7bce18b
commit 98cc8da285
9 changed files with 39 additions and 28 deletions

View File

@ -15,31 +15,28 @@ trait AccountSearchTrait
protected function handleAccountSearchParams($params) protected function handleAccountSearchParams($params)
{ {
$key = null;
if (isset($params['user_id'])) {
$key = 'user_id';
} elseif (isset($params['owner_id'])) {
$key = 'owner_id';
}
if ($key == null) return $params;
$accountRepo = new AccountRepo(); $accountRepo = new AccountRepo();
/** /**
* 兼容用户编号|手机号码|邮箱地址查询 * 兼容用户编号|手机号码|邮箱地址查询
*/ */
if (!empty($params['user_id'])) { if (!empty($params[$key])) {
if (CommonValidator::phone($params['user_id'])) { if (CommonValidator::phone($params[$key])) {
$account = $accountRepo->findByPhone($params['user_id']); $account = $accountRepo->findByPhone($params[$key]);
$params['user_id'] = $account ? $account->id : -1000; $params[$key] = $account ? $account->id : -1000;
} elseif (CommonValidator::email($params['user_id'])) { } elseif (CommonValidator::email($params[$key])) {
$account = $accountRepo->findByEmail($params['user_id']); $account = $accountRepo->findByEmail($params[$key]);
$params['user_id'] = $account ? $account->id : -1000; $params[$key] = $account ? $account->id : -1000;
}
}
/**
* 兼容用户编号|手机号码|邮箱地址查询
*/
if (!empty($params['owner_id'])) {
if (CommonValidator::phone($params['owner_id'])) {
$account = $accountRepo->findByPhone($params['owner_id']);
$params['owner_id'] = $account ? $account->id : -1000;
} elseif (CommonValidator::email($params['owner_id'])) {
$account = $accountRepo->findByEmail($params['owner_id']);
$params['owner_id'] = $account ? $account->id : -1000;
} }
} }

View File

@ -15,6 +15,7 @@ use App\Services\Auth\Home as HomeAuth;
use App\Services\Service as AppService; use App\Services\Service as AppService;
use App\Traits\Response as ResponseTrait; use App\Traits\Response as ResponseTrait;
use App\Traits\Security as SecurityTrait; use App\Traits\Security as SecurityTrait;
use Phalcon\Config;
use Phalcon\Mvc\Dispatcher; use Phalcon\Mvc\Dispatcher;
class Controller extends \Phalcon\Mvc\Controller class Controller extends \Phalcon\Mvc\Controller
@ -46,7 +47,7 @@ class Controller extends \Phalcon\Mvc\Controller
protected $contactInfo; protected $contactInfo;
/** /**
* @var array * @var Config
*/ */
protected $websocketInfo; protected $websocketInfo;

View File

@ -36,7 +36,7 @@ class CsrfToken
$content = [ $content = [
$this->getExpiredTime(), $this->getExpiredTime(),
$this->fixed, $this->fixed,
Text::random(8), Text::random(Text::RANDOM_ALNUM, 8),
]; ];
$text = implode($this->delimiter, $content); $text = implode($this->delimiter, $content);

View File

@ -190,9 +190,10 @@ function kg_site_url()
* *
* @param string $section * @param string $section
* @param string $key * @param string $key
* @param mixed $defaultValue
* @return mixed * @return mixed
*/ */
function kg_setting($section, $key = null) function kg_setting($section, $key = null, $defaultValue = null)
{ {
$cache = new SettingCache(); $cache = new SettingCache();
@ -200,7 +201,9 @@ function kg_setting($section, $key = null)
if (!$key) return $settings; if (!$key) return $settings;
return $settings[$key] ?? null; if (isset($settings[$key])) return $settings[$key];
return $defaultValue;
} }
/** /**

View File

@ -40,6 +40,10 @@ class Chapter extends Repository
$query->andWhere('course_id = :course_id:', ['course_id' => $where['course_id']]); $query->andWhere('course_id = :course_id:', ['course_id' => $where['course_id']]);
} }
if (isset($where['model'])) {
$query->andWhere('model = :model:', ['model' => $where['model']]);
}
if (isset($where['published'])) { if (isset($where['published'])) {
$query->andWhere('published = :published:', ['published' => $where['published']]); $query->andWhere('published = :published:', ['published' => $where['published']]);
} }

View File

@ -33,6 +33,8 @@ class Admin extends AuthService
]; ];
$this->session->set($authKey, $authInfo); $this->session->set($authKey, $authInfo);
return $authInfo;
} }
public function clearAuthInfo() public function clearAuthInfo()

View File

@ -36,6 +36,8 @@ class Home extends AuthService
]; ];
$this->session->set($authKey, $authInfo); $this->session->set($authKey, $authInfo);
return $authInfo;
} }
public function clearAuthInfo() public function clearAuthInfo()

View File

@ -9,7 +9,7 @@ namespace App\Services\Logic\Comment;
use App\Models\Comment as CommentModel; use App\Models\Comment as CommentModel;
use App\Models\User as UserModel; use App\Models\User as UserModel;
use App\Repos\AnswerLike as AnswerLikeRepo; use App\Repos\CommentLike as CommentLikeRepo;
use App\Services\Logic\CommentTrait; use App\Services\Logic\CommentTrait;
use App\Services\Logic\Service as LogicService; use App\Services\Logic\Service as LogicService;
use App\Services\Logic\User\ShallowUserInfo; use App\Services\Logic\User\ShallowUserInfo;
@ -84,9 +84,9 @@ class CommentInfo extends LogicService
$me['logged'] = 1; $me['logged'] = 1;
$likeRepo = new AnswerLikeRepo(); $likeRepo = new CommentLikeRepo();
$like = $likeRepo->findAnswerLike($comment->id, $user->id); $like = $likeRepo->findCommentLike($comment->id, $user->id);
if ($like && $like->deleted == 0) { if ($like && $like->deleted == 0) {
$me['liked'] = 1; $me['liked'] = 1;

View File

@ -22,7 +22,7 @@ class Security extends Validator
$postToken = $this->request->getPost('csrf_token'); $postToken = $this->request->getPost('csrf_token');
if (in_array($route->getName(), $this->getCsrfWhitelist())) { if (in_array($route->getName(), $this->getCsrfWhitelist())) {
return; return true;
} }
$service = new CsrfTokenService(); $service = new CsrfTokenService();
@ -38,6 +38,8 @@ class Security extends Validator
if (!$result) { if (!$result) {
throw new BadRequestException('security.invalid_csrf_token'); throw new BadRequestException('security.invalid_csrf_token');
} }
return true;
} }
public function checkHttpReferer() public function checkHttpReferer()