1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-22 19:44:02 +08:00

整理代码

This commit is contained in:
xiaochong0302 2020-05-07 20:18:37 +08:00
parent 5384cb8c87
commit d34d73721a
37 changed files with 554 additions and 230 deletions

View File

@ -11,10 +11,10 @@ use Phalcon\Mvc\Model\Resultset;
/** /**
* 直播课程 * 直播课程
* *
* Class IndexLiveCourseList * Class IndexLiveList
* @package App\Caches * @package App\Caches
*/ */
class IndexLiveCourseList extends Cache class IndexLiveList extends Cache
{ {
protected $lifetime = 1 * 86400; protected $lifetime = 1 * 86400;
@ -26,7 +26,7 @@ class IndexLiveCourseList extends Cache
public function getKey($id = null) public function getKey($id = null)
{ {
return 'index_live_course_list'; return 'index_live_list';
} }
public function getContent($id = null) public function getContent($id = null)

View File

@ -2,7 +2,7 @@
namespace App\Http\Admin\Services; namespace App\Http\Admin\Services;
use App\Library\Util\Word as WordUtil; use App\Library\Utils\Word as WordUtil;
use App\Models\Chapter as ChapterModel; use App\Models\Chapter as ChapterModel;
use App\Models\Course as CourseModel; use App\Models\Course as CourseModel;
use App\Repos\Chapter as ChapterRepo; use App\Repos\Chapter as ChapterRepo;

View File

@ -21,22 +21,27 @@ class Session extends Service
public function login() public function login()
{ {
$currentUser = $this->getCurrentUser();
if ($currentUser->id > 0) {
$this->response->redirect(['for' => 'web.index']);
}
$post = $this->request->getPost(); $post = $this->request->getPost();
$accountValidator = new AccountValidator(); $accountValidator = new AccountValidator();
$user = $accountValidator->checkAdminLogin($post['account'], $post['password']); $user = $accountValidator->checkAdminLogin($post['account'], $post['password']);
$setting = new Setting(); $captchaSettings = $this->getSectionSettings('captcha');
$captcha = $setting->getSectionSettings('captcha');
$captchaValidator = new CaptchaValidator();
/** /**
* 验证码是一次性的,放到最后检查,减少第三方调用 * 验证码是一次性的,放到最后检查,减少第三方调用
*/ */
if ($captcha->enabled) { if ($captchaSettings['enabled'] == 1) {
$captchaValidator = new CaptchaValidator();
$captchaValidator->checkCode($post['ticket'], $post['rand']); $captchaValidator->checkCode($post['ticket'], $post['rand']);
} }

View File

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="zh-Hans-CN">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

View File

@ -3,6 +3,10 @@
namespace App\Http\Web\Controllers; namespace App\Http\Web\Controllers;
use App\Http\Web\Services\Account as AccountService; use App\Http\Web\Services\Account as AccountService;
use App\Services\Frontend\Account\EmailUpdate as EmailUpdateService;
use App\Services\Frontend\Account\PasswordReset as PasswordResetService;
use App\Services\Frontend\Account\PasswordUpdate as PasswordUpdateService;
use App\Services\Frontend\Account\PhoneUpdate as PhoneUpdateService;
/** /**
* @RoutePrefix("/account") * @RoutePrefix("/account")
@ -11,17 +15,52 @@ class AccountController extends Controller
{ {
/** /**
* @Post("/register", name="web.account.register") * @Route("/login", name="web.account.login")
*/ */
public function registerAction() public function loginAction()
{ {
if ($this->request->isPost()) {
$service = new AccountService(); $service = new AccountService();
$service->signup(); $service->login();
$location = $this->request->getHTTPReferer(); $location = $this->request->getHTTPReferer();
$this->response->redirect($location); return $this->jsonSuccess(['location' => $location]);
}
}
/**
* @Route("/logout", name="web.account.logout")
*/
public function logoutAction()
{
$service = new AccountService();
$service->logout();
$this->response->redirect(['for' => 'web.index']);
}
/**
* @Route("/register", name="web.account.register")
*/
public function registerAction()
{
if ($this->request->isPost()) {
$service = new AccountService();
$service->register();
$location = $this->request->getHTTPReferer();
return $this->jsonSuccess([
'location' => $location,
'msg' => '注册账户成功',
]);
}
} }
/** /**
@ -29,47 +68,59 @@ class AccountController extends Controller
*/ */
public function resetPasswordAction() public function resetPasswordAction()
{ {
$service = new AccountService(); if ($this->request->isPost()) {
$service->resetPassword(); $service = new PasswordResetService();
return $this->jsonSuccess(); $service->handle();
return $this->jsonSuccess(['msg' => '重置密码成功']);
}
} }
/** /**
* @Post("/phone/update", name="web.account.update_phone") * @Route("/phone/update", name="web.account.update_phone")
*/ */
public function updatePhoneAction() public function updatePhoneAction()
{ {
$service = new AccountService(); if ($this->request->isPost()) {
$service->updateMobile(); $service = new PhoneUpdateService();
return $this->jsonSuccess(); $service->handle();
return $this->jsonSuccess(['msg' => '更新手机成功']);
}
} }
/** /**
* @Post("/email/update", name="web.account.update_email") * @Route("/email/update", name="web.account.update_email")
*/ */
public function updateEmailAction() public function updateEmailAction()
{ {
$service = new AccountService(); if ($this->request->isPost()) {
$service->updateMobile(); $service = new EmailUpdateService();
return $this->jsonSuccess(); $service->handle();
return $this->jsonSuccess(['msg' => '更新邮箱成功']);
}
} }
/** /**
* @Post("/password/update", name="web.account.update_password") * @Route("/password/update", name="web.account.update_password")
*/ */
public function updatePasswordAction() public function updatePasswordAction()
{ {
$service = new AccountService(); if ($this->request->isPost()) {
$service->updatePassword(); $service = new PasswordUpdateService();
return $this->jsonSuccess(); $service->handle();
return $this->jsonSuccess(['msg' => '更新密码成功']);
}
} }
} }

View File

@ -2,11 +2,13 @@
namespace App\Http\Web\Controllers; namespace App\Http\Web\Controllers;
use App\Services\Frontend\Course as CourseService; use App\Http\Web\Services\Course as CourseService;
use App\Services\Frontend\CourseList as CourseListService; use App\Services\Frontend\Course\ConsultList as CourseConsultListService;
use App\Services\Frontend\CourseRelated as CourseRelatedService; use App\Services\Frontend\Course\CourseFavorite as CourseFavoriteService;
use App\Services\Frontend\Favorite as CourseFavoriteService; use App\Services\Frontend\Course\CourseInfo as CourseInfoService;
use App\Services\Frontend\ReviewCreate as CourseReviewService; use App\Services\Frontend\Course\CourseList as CourseListService;
use App\Services\Frontend\Course\CourseRelated as CourseRelatedService;
use App\Services\Frontend\Course\ReviewList as CourseReviewListService;
/** /**
* @RoutePrefix("/course") * @RoutePrefix("/course")
@ -21,10 +23,19 @@ class CourseController extends Controller
{ {
$courseListService = new CourseListService(); $courseListService = new CourseListService();
$pager = $courseListService->getCourses(); $pager = $courseListService->handle();
return $this->jsonSuccess(['pager' => $pager]); $courseService = new CourseService();
$topCategories = $courseService->handleTopCategories();
$subCategories = $courseService->handleSubCategories();
$levels = $courseService->handleLevels();
dd($topCategories, $subCategories, $levels);
$this->view->setVar('top_categories', $topCategories);
$this->view->setVar('sub_categories', $subCategories);
$this->view->setVar('levels', $levels);
$this->view->setVar('pager', $pager); $this->view->setVar('pager', $pager);
} }
@ -33,27 +44,28 @@ class CourseController extends Controller
*/ */
public function showAction($id) public function showAction($id)
{ {
$courseService = new CourseService(); $courseInfoService = new CourseInfoService();
$course = $courseService->getCourse($id); $courseInfo = $courseInfoService->handle($id);
return $this->jsonSuccess(['course' => $course]); $courseRelatedService = new CourseRelatedService();
$this->view->setVar('course', $course); $relatedCourses = $courseRelatedService->handle($id);
$this->view->setVar('course_info', $courseInfo);
$this->view->setVar('related_courses', $relatedCourses);
} }
/** /**
* @Get("/{id:[0-9]+}/related", name="web.course.related") * @Get("/{id:[0-9]+}/consults", name="web.course.consults")
*/ */
public function relatedAction($id) public function consultsAction($id)
{ {
$relatedService = new CourseRelatedService(); $consultListService = new CourseConsultListService();
$courses = $relatedService->getRelated($id); $pager = $consultListService->handle($id);
return $this->jsonSuccess(['courses' => $courses]); $this->view->setVar('pager', $pager);
$this->view->setVar('course', $course);
} }
/** /**
@ -61,11 +73,9 @@ class CourseController extends Controller
*/ */
public function reviewsAction($id) public function reviewsAction($id)
{ {
$reviewService = new CourseReviewService(); $reviewListService = new CourseReviewListService();
$pager = $reviewService->getReviews($id); $pager = $reviewListService->handle($id);
return $this->jsonSuccess(['pager' => $pager]);
$this->view->setVar('pager', $pager); $this->view->setVar('pager', $pager);
} }
@ -77,9 +87,9 @@ class CourseController extends Controller
{ {
$favoriteService = new CourseFavoriteService(); $favoriteService = new CourseFavoriteService();
$favoriteService->saveFavorite($id); $favoriteService->handle($id);
return $this->response->ajaxSuccess(); return $this->jsonSuccess(['msg' => '收藏课程成功']);
} }
} }

View File

@ -2,6 +2,8 @@
namespace App\Http\Web\Controllers; namespace App\Http\Web\Controllers;
use App\Http\Web\Services\Index as IndexService;
class IndexController extends Controller class IndexController extends Controller
{ {
@ -12,6 +14,14 @@ class IndexController extends Controller
{ {
$this->siteSeo->setKeywords($this->siteSettings['keywords']); $this->siteSeo->setKeywords($this->siteSettings['keywords']);
$this->siteSeo->setDescription($this->siteSettings['description']); $this->siteSeo->setDescription($this->siteSettings['description']);
$indexService = new IndexService();
$this->view->setVar('slide_list', $indexService->getSlideList());
$this->view->setVar('live_list', $indexService->getLiveList());
$this->view->setVar('new_course_list', $indexService->getNewCourseList());
$this->view->setVar('free_course_list', $indexService->getFreeCourseList());
$this->view->setVar('vip_course_list', $indexService->getVipCourseList());
} }
} }

View File

@ -1,39 +0,0 @@
<?php
namespace App\Http\Web\Controllers;
use App\Http\Web\Services\Account as AccountService;
/**
* @RoutePrefix("/account")
*/
class SessionController extends Controller
{
/**
* @Route("/login", name="web.account.login")
*/
public function loginAction()
{
$service = new AccountService();
$service->login();
$location = $this->request->getHTTPReferer();
$this->response->redirect($location);
}
/**
* @Get("/logout", name="web.account.logout")
*/
public function logoutAction()
{
$service = new AccountService();
$service->logout();
$this->response->redirect(['for' => 'web.index']);
}
}

View File

@ -0,0 +1,60 @@
<?php
namespace App\Http\Web\Services;
use App\Services\Auth as AuthService;
use App\Services\Frontend\Account\Register as RegisterService;
use App\Validators\Account as AccountValidator;
use App\Validators\Captcha as CaptchaValidator;
class Account extends Service
{
/**
* @var AuthService
*/
protected $auth;
public function __construct()
{
$this->auth = $this->getDI()->get('auth');
}
public function login()
{
$post = $this->request->getPost();
$accountValidator = new AccountValidator();
$user = $accountValidator->checkUserLogin($post['account'], $post['password']);
$captchaSettings = $this->getSectionSettings('captcha');
/**
* 验证码是一次性的,放到最后检查,减少第三方调用
*/
if ($captchaSettings['enabled'] == 1) {
$captchaValidator = new CaptchaValidator();
$captchaValidator->checkCode($post['ticket'], $post['rand']);
}
$this->auth->saveAuthInfo($user);
}
public function logout()
{
$this->auth->clearAuthInfo();
}
public function register()
{
$service = new RegisterService();
$user = $service->handle();
$this->auth->saveAuthInfo($user);
}
}

View File

@ -0,0 +1,161 @@
<?php
namespace App\Http\Web\Services;
use App\Models\Course as CourseModel;
use App\Services\Category as CategoryService;
class Course extends Service
{
public function handleTopCategories()
{
$params = $this->getQueryParams();
if (isset($params['tc'])) {
unset($params['tc']);
}
if (isset($params['sc'])) {
unset($params['sc']);
}
$baseUrl = $this->url->get(['for' => 'web.course.list']);
$defaultItem = [
'id' => 0,
'name' => '全部',
'href' => $baseUrl . $this->buildQueryParams($params),
];
$result = [];
$result[] = $defaultItem;
$categoryService = new CategoryService();
$topCategories = $categoryService->getChildCategories(0);
foreach ($topCategories as $key => $category) {
$params['tc'] = $category['id'];
$result[] = [
'id' => $category['id'],
'name' => $category['name'],
'href' => $baseUrl . $this->buildQueryParams($params),
];
}
return $result;
}
public function handleSubCategories()
{
$params = $this->getQueryParams();
if (empty($params['tc'])) {
return [];
}
$categoryService = new CategoryService();
$subCategories = $categoryService->getChildCategories($params['tc']);
if (empty($subCategories)) {
return [];
}
if (isset($params['sc'])) {
unset($params['sc']);
}
$baseUrl = $this->url->get(['for' => 'web.course.list']);
$defaultItem = [
'id' => 0,
'name' => '全部',
'href' => $baseUrl . $this->buildQueryParams($params),
];
$result = [];
$result[] = $defaultItem;
foreach ($subCategories as $key => $category) {
$params['sc'] = $category['id'];
$result[] = [
'id' => $category['id'],
'name' => $category['name'],
'href' => $baseUrl . $this->buildQueryParams($params),
];
}
return $result;
}
public function handleLevels()
{
$params = $this->getQueryParams();
$defaultParams = $params;
if (isset($defaultParams['level'])) {
unset($defaultParams['level']);
}
$baseUrl = $this->url->get(['for' => 'web.course.list']);
$defaultItem = [
'id' => 0,
'name' => '全部',
'href' => $baseUrl . $this->buildQueryParams($defaultParams),
];
$result = [];
$result[] = $defaultItem;
$levels = CourseModel::levelTypes();
foreach ($levels as $key => $value) {
$params['sc'] = $key;
$result[] = [
'id' => $key,
'name' => $value,
'href' => $baseUrl . $this->buildQueryParams($params),
];
}
return $result;
}
public function handleSorts()
{
}
protected function getQueryParams()
{
$query = $this->request->getQuery();
$params = [];
if (!empty($query['tc'])) {
$params['tc'] = $query['tc'];
}
if (!empty($query['sc'])) {
$params['sc'] = $query['sc'];
}
if (!empty($query['level'])) {
$params['level'] = $query['level'];
}
return $params;
}
protected function buildQueryParams($params)
{
return $params ? '?' . http_build_query($params) : '';
}
}

View File

@ -0,0 +1,49 @@
<?php
namespace App\Http\Web\Services;
use App\Caches\IndexFreeCourseList;
use App\Caches\IndexLiveList;
use App\Caches\IndexNewCourseList;
use App\Caches\IndexSlideList;
use App\Caches\IndexVipCourseList;
class Index extends Service
{
public function getSlideList()
{
$cache = new IndexSlideList();
return $cache->get();
}
public function getLiveList()
{
$cache = new IndexLiveList();
return $cache->get();
}
public function getNewCourseList()
{
$cache = new IndexNewCourseList();
return $cache->get();
}
public function getFreeCourseList()
{
$cache = new IndexFreeCourseList();
return $cache->get();
}
public function getVipCourseList()
{
$cache = new IndexVipCourseList();
return $cache->get();
}
}

View File

@ -0,0 +1 @@
{% extends 'templates/base.volt' %}

View File

@ -2,6 +2,18 @@
{% block content %} {% block content %}
<img src="/qr/img?text=http://ctc.koogua.com"> {%- macro model_info(value) %}
{% if value == 'vod' %}
<span class="layui-badge layui-bg-green">点播{{ request.get('id') }}</span>
{% elseif value == 'live' %}
<span class="layui-badge layui-bg-blue">直播</span>
{% elseif value == 'read' %}
<span class="layui-badge layui-bg-black">图文</span>
{% endif %}
{%- endmacro %}
<div class="model">{{ model_info('vod') }}</div>
<h1>I am body</h1>
<h2>ID:{{ request.get('id') }}</h2>
{% endblock %} {% endblock %}

View File

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="zh-Hans-CN">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

View File

@ -1,6 +1,6 @@
<?php <?php
namespace App\Library\Util; namespace App\Library\Utils;
use Phalcon\Text; use Phalcon\Text;

View File

@ -1,6 +1,6 @@
<?php <?php
namespace App\Library\Util; namespace App\Library\Utils;
class Word class Word
{ {

View File

@ -1,6 +1,6 @@
<?php <?php
namespace App\Library\Validator; namespace App\Library\Validators;
class Common class Common
{ {

View File

@ -1,12 +1,15 @@
<?php <?php
namespace App\Library\Validator; namespace App\Library\Validators;
class IdCard class IdCard
{ {
/* /**
* 验证身份证是否有效 * 验证身份证是否有效
*
* @param string $idCard
* @return bool
*/ */
public function validate($idCard) public function validate($idCard)
{ {
@ -24,8 +27,11 @@ class IdCard
return false; return false;
} }
/* /**
* 计算身份证的最后一位验证码,根据国家标准GB 11643-1999 * 计算身份证的最后一位验证码,根据国家标准GB 11643-1999
*
* @param string $idCardBody
* @return bool|mixed
*/ */
private function calcIdCardCode($idCardBody) private function calcIdCardCode($idCardBody)
{ {
@ -33,10 +39,14 @@ class IdCard
return false; return false;
} }
//加权因子 /**
* 加权因子
*/
$factor = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); $factor = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
//校验码对应值 /**
* 校验码对应值
*/
$code = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); $code = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
$checksum = 0; $checksum = 0;
@ -48,8 +58,11 @@ class IdCard
return $code[$checksum % 11]; return $code[$checksum % 11];
} }
/* /**
* 将15位身份证升级到18位 * 将15位身份证升级到18位
*
* @param string $idCard
* @return bool|string
*/ */
private function convertIdCard15to18($idCard) private function convertIdCard15to18($idCard)
{ {
@ -57,7 +70,9 @@ class IdCard
return false; return false;
} }
// 如果身份证顺序码是996 997 998 999这些是为百岁以上老人的特殊编码 /**
* 如果身份证顺序码是996 997 998 999,这些是为百岁以上老人的特殊编码
*/
if (array_search(substr($idCard, 12, 3), array('996', '997', '998', '999')) !== false) { if (array_search(substr($idCard, 12, 3), array('996', '997', '998', '999')) !== false) {
$idCard = substr($idCard, 0, 6) . '18' . substr($idCard, 6, 9); $idCard = substr($idCard, 0, 6) . '18' . substr($idCard, 6, 9);
} else { } else {
@ -69,8 +84,11 @@ class IdCard
return $idCard; return $idCard;
} }
/* /**
* 18位身份证校验码有效性检查 * 18位身份证校验码有效性检查
*
* @param string $idCard
* @return bool
*/ */
private function check18IdCard($idCard) private function check18IdCard($idCard)
{ {
@ -78,8 +96,8 @@ class IdCard
return false; return false;
} }
$idCardBody = substr($idCard, 0, 17); //身份证主体 $idCardBody = substr($idCard, 0, 17); // 身份证主体
$idCardCode = strtoupper(substr($idCard, 17, 1)); //身份证最后一位的验证码 $idCardCode = strtoupper(substr($idCard, 17, 1)); // 身份证最后一位的验证码
if ($this->calcIdCardCode($idCardBody) != $idCardCode) { if ($this->calcIdCardCode($idCardBody) != $idCardCode) {
return false; return false;

View File

@ -2,7 +2,7 @@
namespace App\Models; namespace App\Models;
use App\Library\Util\Password; use App\Library\Utils\Password;
use Phalcon\Mvc\Model\Behavior\SoftDelete; use Phalcon\Mvc\Model\Behavior\SoftDelete;
class Account extends Model class Account extends Model

View File

@ -47,6 +47,29 @@ class Category extends Service
]; ];
} }
/**
* 获取子节点
*
* @param int $id
* @return array
*/
public function getChildCategories($id = 0)
{
$categoryListCache = new CategoryListCache();
$categories = $categoryListCache->get();
$result = [];
foreach ($categories as $category) {
if ($category['parent_id'] == $id) {
$result[] = $category;
}
}
return $result;
}
/** /**
* 获取子节点ID * 获取子节点ID
* *
@ -71,15 +94,15 @@ class Category extends Service
$categories = $categoryListCache->get(); $categories = $categoryListCache->get();
$nodeIds = []; $result = [];
foreach ($categories as $category) { foreach ($categories as $category) {
if ($category['parent_id'] == $id) { if ($category['parent_id'] == $id) {
$nodeIds[] = $category['id']; $result[] = $category['id'];
} }
} }
return $nodeIds; return $result;
} }
} }

View File

@ -32,7 +32,7 @@ class EmailUpdate extends Service
$verifyValidator = new VerifyValidator(); $verifyValidator = new VerifyValidator();
$verifyValidator->checkEmailCode($post['email'], $post['verify_code']); $verifyValidator->checkCode($post['email'], $post['verify_code']);
$account->email = $email; $account->email = $email;

View File

@ -15,13 +15,13 @@ class PasswordReset extends Service
$accountValidator = new AccountValidator(); $accountValidator = new AccountValidator();
$account = $accountValidator->checkLoginName($post['login_name']); $account = $accountValidator->checkLoginName($post['account']);
$accountValidator->checkPassword($post['new_password']); $accountValidator->checkPassword($post['new_password']);
$verifyValidator = new VerifyValidator(); $verifyValidator = new VerifyValidator();
$verifyValidator->checkCode($post['login_name'], $post['verify_code']); $verifyValidator->checkCode($post['account'], $post['verify_code']);
$account->password = $post['new_password']; $account->password = $post['new_password'];

View File

@ -32,7 +32,7 @@ class PhoneUpdate extends Service
$verifyValidator = new VerifyValidator(); $verifyValidator = new VerifyValidator();
$verifyValidator->checkSmsCode($post['phone'], $post['verify_code']); $verifyValidator->checkCode($post['phone'], $post['verify_code']);
$account->phone = $phone; $account->phone = $phone;

View File

@ -0,0 +1,51 @@
<?php
namespace App\Services\Frontend\Account;
use App\Library\Validators\Common as CommonValidator;
use App\Models\Account as AccountModel;
use App\Repos\User as UserRepo;
use App\Services\Frontend\Service;
use App\Validators\Account as AccountValidator;
use App\Validators\Verify as VerifyValidator;
class Register extends Service
{
public function handle()
{
$post = $this->request->getPost();
$verifyValidator = new VerifyValidator();
$verifyValidator->checkCode($post['account'], $post['verify_code']);
$accountValidator = new AccountValidator();
$data = [];
if (CommonValidator::email($post['account'])) {
$data['email'] = $accountValidator->checkEmail($post['account']);
$accountValidator->checkIfEmailTaken($post['account']);
} elseif (CommonValidator::phone($post['account'])) {
$data['phone'] = $accountValidator->checkPhone($post['account']);
$accountValidator->checkIfPhoneTaken($post['account']);
}
$data['password'] = $accountValidator->checkPassword($post['password']);
$account = new AccountModel();
$account->create($data);
$userRepo = new UserRepo();
return $userRepo->findById($account->id);
}
}

View File

@ -1,37 +0,0 @@
<?php
namespace App\Services\Frontend\Account;
use App\Models\Account as AccountModel;
use App\Services\Frontend\Service;
use App\Validators\Account as AccountValidator;
use App\Validators\Verify as VerifyValidator;
class RegisterByEmail extends Service
{
public function handle()
{
$post = $this->request->getPost();
$verifyValidator = new VerifyValidator();
$verifyValidator->checkEmailCode($post['email'], $post['verify_code']);
$accountValidator = new AccountValidator();
$data = [];
$data['email'] = $accountValidator->checkEmail($post['email']);
$data['password'] = $accountValidator->checkPassword($post['password']);
$accountValidator->checkIfEmailTaken($post['email']);
$account = new AccountModel();
$account->create($data);
return $account;
}
}

View File

@ -1,37 +0,0 @@
<?php
namespace App\Services\Frontend\Account;
use App\Models\Account as AccountModel;
use App\Services\Frontend\Service;
use App\Validators\Account as AccountValidator;
use App\Validators\Verify as VerifyValidator;
class RegisterByPhone extends Service
{
public function handle()
{
$post = $this->request->getPost();
$verifyValidator = new VerifyValidator();
$verifyValidator->checkSmsCode($post['phone'], $post['verify_code']);
$accountValidator = new AccountValidator();
$data = [];
$data['phone'] = $accountValidator->checkPhone($post['phone']);
$data['password'] = $accountValidator->checkPassword($post['password']);
$accountValidator->checkIfPhoneTaken($post['phone']);
$account = new AccountModel();
$account->create($data);
return $account;
}
}

View File

@ -16,13 +16,21 @@ class CourseList extends Service
$params = $pagerQuery->getParams(); $params = $pagerQuery->getParams();
if (!empty($params['category_id'])) { /**
* tc => top_category
* sc => sub_category
*/
if (!empty($params['sc'])) {
$params['category_id'] = $params['sc'];
} elseif (!empty($params['tc'])) {
$categoryService = new CategoryService(); $categoryService = new CategoryService();
$childNodeIds = $categoryService->getChildCategoryIds($params['category_id']); $childCategoryIds = $categoryService->getChildCategoryIds($params['tc']);
$params['category_id'] = $childNodeIds; $params['category_id'] = $childCategoryIds;
} }
$params['published'] = 1; $params['published'] = 1;

View File

@ -36,9 +36,9 @@ class Service extends Component
*/ */
public function getSectionSettings($section) public function getSectionSettings($section)
{ {
$settingCache = new SettingCache(); $cache = new SettingCache();
return $settingCache->get($section); return $cache->get($section);
} }
} }

View File

@ -4,8 +4,8 @@ namespace App\Validators;
use App\Exceptions\BadRequest as BadRequestException; use App\Exceptions\BadRequest as BadRequestException;
use App\Exceptions\Forbidden as ForbiddenException; use App\Exceptions\Forbidden as ForbiddenException;
use App\Library\Util\Password as PasswordUtil; use App\Library\Utils\Password as PasswordUtil;
use App\Library\Validator\Common as CommonValidator; use App\Library\Validators\Common as CommonValidator;
use App\Models\Account as AccountModel; use App\Models\Account as AccountModel;
use App\Repos\Account as AccountRepo; use App\Repos\Account as AccountRepo;
use App\Repos\User as UserRepo; use App\Repos\User as UserRepo;

View File

@ -3,7 +3,7 @@
namespace App\Validators; namespace App\Validators;
use App\Exceptions\BadRequest as BadRequestException; use App\Exceptions\BadRequest as BadRequestException;
use App\Library\Validator\Common as CommonValidator; use App\Library\Validators\Common as CommonValidator;
class ChapterLive extends Validator class ChapterLive extends Validator
{ {

View File

@ -3,7 +3,7 @@
namespace App\Validators; namespace App\Validators;
use App\Exceptions\BadRequest as BadRequestException; use App\Exceptions\BadRequest as BadRequestException;
use App\Library\Validator\Common as CommonValidator; use App\Library\Validators\Common as CommonValidator;
class ChapterVod extends Validator class ChapterVod extends Validator
{ {

View File

@ -5,7 +5,7 @@ namespace App\Validators;
use App\Caches\Course as CourseCache; use App\Caches\Course as CourseCache;
use App\Caches\MaxCourseId as MaxCourseIdCache; use App\Caches\MaxCourseId as MaxCourseIdCache;
use App\Exceptions\BadRequest as BadRequestException; use App\Exceptions\BadRequest as BadRequestException;
use App\Library\Validator\Common as CommonValidator; use App\Library\Validators\Common as CommonValidator;
use App\Models\Course as CourseModel; use App\Models\Course as CourseModel;
use App\Repos\Course as CourseRepo; use App\Repos\Course as CourseRepo;

View File

@ -3,7 +3,7 @@
namespace App\Validators; namespace App\Validators;
use App\Exceptions\BadRequest as BadRequestException; use App\Exceptions\BadRequest as BadRequestException;
use App\Library\Validator\Common as CommonValidator; use App\Library\Validators\Common as CommonValidator;
use App\Repos\Course as CourseRepo; use App\Repos\Course as CourseRepo;
use App\Repos\CourseUser as CourseUserRepo; use App\Repos\CourseUser as CourseUserRepo;
use App\Repos\User as UserRepo; use App\Repos\User as UserRepo;

View File

@ -3,7 +3,7 @@
namespace App\Validators; namespace App\Validators;
use App\Exceptions\BadRequest as BadRequestException; use App\Exceptions\BadRequest as BadRequestException;
use App\Library\Validator\Common as CommonValidator; use App\Library\Validators\Common as CommonValidator;
use App\Models\Nav as NavModel; use App\Models\Nav as NavModel;
use App\Repos\Nav as NavRepo; use App\Repos\Nav as NavRepo;
use Phalcon\Text; use Phalcon\Text;

View File

@ -3,7 +3,7 @@
namespace App\Validators; namespace App\Validators;
use App\Exceptions\BadRequest as BadRequestException; use App\Exceptions\BadRequest as BadRequestException;
use App\Library\Validator\Common as CommonValidator; use App\Library\Validators\Common as CommonValidator;
use App\Models\Course as CourseModel; use App\Models\Course as CourseModel;
use App\Models\Page as PageModel; use App\Models\Page as PageModel;
use App\Models\Slide as SlideModel; use App\Models\Slide as SlideModel;

View File

@ -5,7 +5,7 @@ namespace App\Validators;
use App\Caches\MaxUserId as MaxUserIdCache; use App\Caches\MaxUserId as MaxUserIdCache;
use App\Caches\User as UserCache; use App\Caches\User as UserCache;
use App\Exceptions\BadRequest as BadRequestException; use App\Exceptions\BadRequest as BadRequestException;
use App\Library\Validator\Common as CommonValidator; use App\Library\Validators\Common as CommonValidator;
use App\Models\User as UserModel; use App\Models\User as UserModel;
use App\Repos\Role as RoleRepo; use App\Repos\Role as RoleRepo;
use App\Repos\User as UserRepo; use App\Repos\User as UserRepo;

View File

@ -3,7 +3,7 @@
namespace App\Validators; namespace App\Validators;
use App\Exceptions\BadRequest as BadRequestException; use App\Exceptions\BadRequest as BadRequestException;
use App\Library\Validator\Common as CommonValidator; use App\Library\Validators\Common as CommonValidator;
use App\Services\Verification as VerifyService; use App\Services\Verification as VerifyService;
class Verify extends Validator class Verify extends Validator
@ -27,28 +27,6 @@ class Verify extends Validator
return $email; return $email;
} }
public function checkSmsCode($phone, $code)
{
$service = new VerifyService();
$result = $service->checkSmsCode($phone, $code);
if (!$result) {
throw new BadRequestException('verify.invalid_code');
}
}
public function checkEmailCode($email, $code)
{
$service = new VerifyService();
$result = $service->checkEmailCode($email, $code);
if (!$result) {
throw new BadRequestException('verify.invalid_code');
}
}
public function checkCode($key, $code) public function checkCode($key, $code)
{ {
$service = new VerifyService(); $service = new VerifyService();