- {% if auth_user %}
+ {% if auth_user.id > 0 %}
diff --git a/app/Library/Validators/Common.php b/app/Library/Validators/Common.php
index 2a4ac053..504d7f45 100644
--- a/app/Library/Validators/Common.php
+++ b/app/Library/Validators/Common.php
@@ -66,7 +66,7 @@ class Common
public static function phone($str)
{
- $pattern = '/^(13[0-9]|15[0-3]|15[5-9]|180|18[5-9])[0-9]{8}$/';
+ $pattern = '/^1(3|4|5|6|7|9)[0-9]{9}$/';
return preg_match($pattern, $str) ? true : false;
}
diff --git a/app/Services/Frontend/Account/PasswordReset.php b/app/Services/Frontend/Account/PasswordReset.php
index 5bb0f853..ff64b76f 100644
--- a/app/Services/Frontend/Account/PasswordReset.php
+++ b/app/Services/Frontend/Account/PasswordReset.php
@@ -15,7 +15,7 @@ class PasswordReset extends FrontendService
$accountValidator = new AccountValidator();
- $account = $accountValidator->checkLoginName($post['account']);
+ $account = $accountValidator->checkAccount($post['account']);
$accountValidator->checkPassword($post['new_password']);
diff --git a/app/Services/Frontend/Account/PasswordResetByEmail.php b/app/Services/Frontend/Account/PasswordResetByEmail.php
index 367b60ac..fb4c4378 100644
--- a/app/Services/Frontend/Account/PasswordResetByEmail.php
+++ b/app/Services/Frontend/Account/PasswordResetByEmail.php
@@ -15,7 +15,7 @@ class PasswordResetByEmail extends FrontendService
$accountValidator = new AccountValidator();
- $account = $accountValidator->checkAccountByEmail($post['email']);
+ $account = $accountValidator->checkAccount($post['email']);
$accountValidator->checkPassword($post['new_password']);
diff --git a/app/Services/Frontend/Account/PasswordResetByPhone.php b/app/Services/Frontend/Account/PasswordResetByPhone.php
index 69f2f038..213b2593 100644
--- a/app/Services/Frontend/Account/PasswordResetByPhone.php
+++ b/app/Services/Frontend/Account/PasswordResetByPhone.php
@@ -15,7 +15,7 @@ class PasswordResetByPhone extends FrontendService
$accountValidator = new AccountValidator();
- $account = $accountValidator->checkAccountByPhone($post['phone']);
+ $account = $accountValidator->checkAccount($post['phone']);
$accountValidator->checkPassword($post['new_password']);
diff --git a/app/Services/Frontend/Account/Register.php b/app/Services/Frontend/Account/Register.php
index 463df9a9..84d2d07e 100644
--- a/app/Services/Frontend/Account/Register.php
+++ b/app/Services/Frontend/Account/Register.php
@@ -21,6 +21,8 @@ class Register extends FrontendService
$accountValidator = new AccountValidator();
+ $accountValidator->checkLoginName($post['account']);
+
$data = [];
if (CommonValidator::phone($post['account'])) {
diff --git a/app/Services/Frontend/Chapter/ChapterInfo.php b/app/Services/Frontend/Chapter/ChapterInfo.php
index 2f230d8e..3476312c 100644
--- a/app/Services/Frontend/Chapter/ChapterInfo.php
+++ b/app/Services/Frontend/Chapter/ChapterInfo.php
@@ -34,9 +34,9 @@ class ChapterInfo extends FrontendService
public function handle($id)
{
- $chapter = $this->checkChapter($id);
+ $chapter = $this->checkChapterCache($id);
- $course = $this->checkCourse($chapter->course_id);
+ $course = $this->checkCourseCache($chapter->course_id);
$this->course = $course;
diff --git a/app/Services/Frontend/Course/ChapterList.php b/app/Services/Frontend/Course/ChapterList.php
index 0c6f5523..134f824e 100644
--- a/app/Services/Frontend/Course/ChapterList.php
+++ b/app/Services/Frontend/Course/ChapterList.php
@@ -35,17 +35,7 @@ class ChapterList extends FrontendService
return [];
}
- if ($user->id == 0) {
- foreach ($chapters as &$chapter) {
- foreach ($chapter['children'] as &$lesson) {
- $lesson['me'] = [
- 'owned' => $this->ownedCourse || $lesson['free'] ? 1 : 0,
- 'progress' => 0,
- 'duration' => 0,
- ];
- }
- }
- } else {
+ if ($user->id > 0 && $this->courseUser) {
$mappings = $this->getLearningMappings($course->id, $user->id, $this->courseUser->plan_id);
foreach ($chapters as &$chapter) {
foreach ($chapter['children'] as &$lesson) {
@@ -56,6 +46,16 @@ class ChapterList extends FrontendService
];
}
}
+ } else {
+ foreach ($chapters as &$chapter) {
+ foreach ($chapter['children'] as &$lesson) {
+ $lesson['me'] = [
+ 'owned' => $this->ownedCourse || $lesson['free'] ? 1 : 0,
+ 'progress' => 0,
+ 'duration' => 0,
+ ];
+ }
+ }
}
return $chapters;
diff --git a/app/Services/Mailer/Verify.php b/app/Services/Mailer/Verify.php
index 2b5ad79b..82cd5c02 100644
--- a/app/Services/Mailer/Verify.php
+++ b/app/Services/Mailer/Verify.php
@@ -22,7 +22,7 @@ class Verify extends MailerService
$minutes = 5;
- $code = $verify->getSmsCode($email, 60 * $minutes);
+ $code = $verify->getEmailCode($email, 60 * $minutes);
$subject = '邮件验证码';
diff --git a/app/Validators/Account.php b/app/Validators/Account.php
index 137245cf..06cdabca 100644
--- a/app/Validators/Account.php
+++ b/app/Validators/Account.php
@@ -15,10 +15,10 @@ class Account extends Validator
public function checkAccount($name)
{
- $accountRepo = new AccountRepo();
-
$account = null;
+ $accountRepo = new AccountRepo();
+
if (CommonValidator::email($name)) {
$account = $accountRepo->findByEmail($name);
} elseif (CommonValidator::phone($name)) {
@@ -34,38 +34,14 @@ class Account extends Validator
return $account;
}
- public function checkAccountByEmail($email)
- {
- $accountRepo = new AccountRepo();
-
- $account = $accountRepo->findByEmail($email);
-
- if (!$account) {
- throw new BadRequestException('account.not_found');
- }
-
- return $account;
- }
-
- public function checkAccountByPhone($phone)
- {
- $accountRepo = new AccountRepo();
-
- $account = $accountRepo->findByPhone($phone);
-
- if (!$account) {
- throw new BadRequestException('account.not_found');
- }
-
- return $account;
- }
-
public function checkLoginName($name)
{
$isPhone = CommonValidator::phone($name);
$isEmail = CommonValidator::email($name);
- if (!$isPhone && !$isEmail) {
+ $loginNameOk = $isPhone || $isEmail;
+
+ if (!$loginNameOk) {
throw new BadRequestException('account.invalid_login_name');
}
}
diff --git a/app/Validators/Validator.php b/app/Validators/Validator.php
index c69a9811..99f95dba 100644
--- a/app/Validators/Validator.php
+++ b/app/Validators/Validator.php
@@ -9,7 +9,7 @@ use Phalcon\Mvc\User\Component;
class Validator extends Component
{
- public function checkAuthUser(array $authUser)
+ public function checkAuthUser($authUser)
{
if (empty($authUser['id'])) {
throw new UnauthorizedException('sys.unauthorized');
diff --git a/app/Validators/Verify.php b/app/Validators/Verify.php
index ba967b82..9c8e4e78 100644
--- a/app/Validators/Verify.php
+++ b/app/Validators/Verify.php
@@ -27,12 +27,14 @@ class Verify extends Validator
return $email;
}
- public function checkCode($name, $code)
+ public function checkCode($identity, $code)
{
- if (CommonValidator::email($name)) {
- $this->checkEmailCode($name, $code);
- } elseif (CommonValidator::phone($name)) {
- $this->checkSmsCode($name, $code);
+ if (CommonValidator::email($identity)) {
+ $this->checkEmailCode($identity, $code);
+ } elseif (CommonValidator::phone($identity)) {
+ $this->checkSmsCode($identity, $code);
+ } else {
+ throw new BadRequestException('verify.unsupported_identity');
}
}
diff --git a/public/static/admin/css/common.css b/public/static/admin/css/common.css
index 83227403..a49d6603 100644
--- a/public/static/admin/css/common.css
+++ b/public/static/admin/css/common.css
@@ -42,7 +42,7 @@
margin-right: 10px;
}
-.kg-btn-verify {
+.kg-verify-btn-ok {
color: green;
}
diff --git a/public/static/web/css/common.css b/public/static/web/css/common.css
index 16d7b420..81d49681 100644
--- a/public/static/web/css/common.css
+++ b/public/static/web/css/common.css
@@ -419,7 +419,7 @@ body {
}
.package-item {
- margin-bottom: 25px;
+ margin-bottom: 20px;
border-bottom: 1px dashed #ccc;
}
@@ -469,7 +469,7 @@ body {
.package-course-list {
width: 580px;
- height: 170px;
+ height: 180px;
overflow-x: auto;
white-space: nowrap;
}
@@ -484,9 +484,11 @@ body {
.package-course-card {
width: 175px;
+ height: 160px;
display: inline-block;
margin-right: 8px;
vertical-align: top;
+ box-shadow: 0 4px 8px 0 rgba(7, 17, 27, 0.1);
}
.package-course-card .cover {
@@ -502,6 +504,8 @@ body {
.package-course-card .title {
font-size: 12px;
+ padding: 0 3px;
+ text-align: center;
white-space: normal;
}
@@ -785,28 +789,30 @@ body {
text-align: center;
}
-.verify-tips-btn {
+.verify-btn-ok {
color: green;
}
-.register-container {
- padding: 40px 30px;
- background-color: #fff;
+.account-form {
+ width: 540px;
}
-.register-container .layui-form {
- width: 50%;
+.account-form .verify-input-inline {
+ width: 308px;
+}
+
+.account-form .verify-btn-inline {
+ margin-right: 0;
+}
+
+.login-container {
+
}
.login-tab {
- padding: 20px 30px;
- background-color: #fff;
+ margin: 0;
}
.login-tab .layui-tab-content {
padding-top: 30px;
-}
-
-.login-tab .layui-form {
- width: 50%;
}
\ No newline at end of file
diff --git a/public/static/web/js/captcha.login.js b/public/static/web/js/captcha.login.js
index 9c9c6678..408b7279 100644
--- a/public/static/web/js/captcha.login.js
+++ b/public/static/web/js/captcha.login.js
@@ -5,11 +5,11 @@ var captcha = new TencentCaptcha(
$('#captcha-btn').attr('data-app-id'),
function (res) {
if (res.ret === 0) {
- $('input[name=ticket]').val(res.ticket);
- $('input[name=rand]').val(res.randstr);
+ $('#ticket').val(res.ticket);
+ $('#rand').val(res.randstr);
$('#captcha-btn').remove();
- $('#submit-btn').removeAttr('disabled');
$('#verify-btn').removeClass('layui-hide');
+ $('#submit-btn').removeClass('layui-btn-disabled').removeAttr('disabled');
}
}
);
\ No newline at end of file
diff --git a/public/static/web/js/captcha.verify.js b/public/static/web/js/captcha.verify.js
index e5a4b122..ff8a4840 100644
--- a/public/static/web/js/captcha.verify.js
+++ b/public/static/web/js/captcha.verify.js
@@ -5,24 +5,41 @@ var captcha = new TencentCaptcha(
$('#cv-captcha-btn').attr('data-app-id'),
function (res) {
if (res.ret === 0) {
- $.ajax({
- type: 'POST',
- url: '/verify/code',
- data: {
- account: $('#cv-account').val(),
- ticket: res.ticket,
- rand: res.randstr
- },
- success: function (res) {
- var icon = res.code === 0 ? 1 : 2;
- if (res.msg) {
- layer.msg(res.msg, {icon: icon});
- }
- }
- });
+ $('#cv-ticket').val(res.ticket);
+ $('#cv-rand').val(res.randstr);
$('#cv-captcha-btn').remove();
- $('#cv-submit-btn').removeAttr('disabled');
$('#cv-verify-btn').removeClass('layui-hide');
+ $('#cv-verify-emit').removeClass('layui-btn-disabled').removeAttr('disabled');
}
}
-);
\ No newline at end of file
+);
+
+$('#cv-verify-emit').on('click', function () {
+ var account = $('#cv-account').val();
+ var regEmail = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
+ var regPhone = /^1(3|4|5|6|7|8|9)\d{9}$/;
+ var isEmail = regEmail.test(account);
+ var isPhone = regPhone.test(account);
+ if (isEmail || isPhone) {
+ var postUrl = null;
+ var postData = {
+ ticket: $('#cv-ticket').val(),
+ rand: $('#cv-rand').val(),
+ };
+ if (isPhone) {
+ postData.phone = account;
+ postUrl = '/verify/sms/code';
+ } else if (isEmail) {
+ postData.email = account;
+ postUrl = '/verify/email/code';
+ }
+ $.post(postUrl, postData, function (res) {
+ if (res.code === 0) {
+ $('#cv-submit-btn').removeClass('layui-btn-disabled').removeAttr('disabled');
+ layer.msg('发送验证码成功', {icon: 1});
+ } else {
+ layer.msg('发送验证码失败', {icon: 2});
+ }
+ });
+ }
+});
\ No newline at end of file