diff --git a/app/Http/Admin/Views/public/login.volt b/app/Http/Admin/Views/public/login.volt index 7f26dfca..1eaca7ff 100644 --- a/app/Http/Admin/Views/public/login.volt +++ b/app/Http/Admin/Views/public/login.volt @@ -22,7 +22,7 @@
- 点击完成验证 + 点击完成验证 验证成功
@@ -55,7 +55,7 @@ var $ = layui.jquery; var captcha = new TencentCaptcha( $('#captcha-btn')[0], - $('#captcha-btn').attr('app-id'), + $('#captcha-btn').attr('data-app-id'), function (res) { if (res.ret === 0) { $('input[name=ticket]').val(res.ticket); diff --git a/app/Http/Web/Controllers/AccountController.php b/app/Http/Web/Controllers/AccountController.php index 18c1c60e..14a8b409 100644 --- a/app/Http/Web/Controllers/AccountController.php +++ b/app/Http/Web/Controllers/AccountController.php @@ -4,7 +4,6 @@ namespace App\Http\Web\Controllers; 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; @@ -18,6 +17,21 @@ class AccountController extends Controller * @Get("/register", name="web.account.register") */ public function registerAction() + { + $service = new AccountService(); + + $captcha = $service->getSectionSettings('captcha'); + + $returnUrl = $this->request->getHTTPReferer(); + + $this->view->setVar('return_url', $returnUrl); + $this->view->setVar('captcha', $captcha); + } + + /** + * @Post("/register", name="web.account.do_register") + */ + public function doRegisterAction() { } @@ -27,7 +41,38 @@ class AccountController extends Controller */ public function loginAction() { + $service = new AccountService(); + $captcha = $service->getSectionSettings('captcha'); + + $returnUrl = $this->request->getHTTPReferer(); + + $this->view->setVar('return_url', $returnUrl); + $this->view->setVar('captcha', $captcha); + } + + /** + * @Post("/password/login", name="web.account.pwd_login") + */ + public function loginByPasswordAction() + { + $service = new AccountService(); + + $service->loginByPassword(); + + return $this->jsonSuccess(); + } + + /** + * @Post("/verify/login", name="web.account.verify_login") + */ + public function loginByVerifyAction() + { + $service = new AccountService(); + + $service->loginByVerify(); + + return $this->jsonSuccess(); } /** @@ -46,89 +91,21 @@ class AccountController extends Controller * @Get("/password/reset", name="web.account.reset_pwd") */ public function resetPasswordAction() - { - - } - - /** - * @Post("/phone/register", name="web.account.register_by_phone") - */ - public function registerByPhoneAction() { $service = new AccountService(); - $service->registerByPhone(); + $captcha = $service->getSectionSettings('captcha'); - $content = [ - 'location' => $this->request->getHTTPReferer(), - 'msg' => '注册账户成功', - ]; - - return $this->jsonSuccess($content); + $this->view->pick('account/reset_password'); + $this->view->setVar('captcha', $captcha); } /** - * @Post("/email/register", name="web.account.register_by_email") + * @Post("/password/reset", name="web.account.do_reset_pwd") */ - public function registerByEmailAction() + public function doResetPasswordAction() { - $service = new AccountService(); - $service->registerByPhone(); - - $content = [ - 'msg' => '注册账户成功', - ]; - - return $this->jsonSuccess($content); - } - - /** - * @Post("/password/login", name="web.account.login_by_pwd") - */ - public function loginByPasswordAction() - { - $service = new AccountService(); - - $service->loginByPassword(); - - return $this->jsonSuccess(); - } - - /** - * @Post("/verify/login", name="web.account.login_by_verify") - */ - public function loginByVerifyAction() - { - $service = new AccountService(); - - $service->loginByVerify(); - - return $this->jsonSuccess(); - } - - /** - * @Post("/password/email/reset", name="web.account.reset_pwd_by_email") - */ - public function resetPasswordByEmailAction() - { - $service = new PasswordResetService(); - - $service->handle(); - - return $this->jsonSuccess(['msg' => '重置密码成功']); - } - - /** - * @Post("/password/phone/reset", name="web.account.reset_pwd_by_phone") - */ - public function resetPasswordByPhoneAction() - { - $service = new PasswordResetService(); - - $service->handle(); - - return $this->jsonSuccess(['msg' => '重置密码成功']); } /** @@ -156,7 +133,7 @@ class AccountController extends Controller } /** - * @Post("/password/update", name="web.account.update_password") + * @Post("/password/update", name="web.account.update_pwd") */ public function updatePasswordAction() { diff --git a/app/Http/Web/Controllers/VerifyController.php b/app/Http/Web/Controllers/VerifyController.php index 88bdbf47..e391328a 100644 --- a/app/Http/Web/Controllers/VerifyController.php +++ b/app/Http/Web/Controllers/VerifyController.php @@ -4,6 +4,7 @@ namespace App\Http\Web\Controllers; use App\Services\Frontend\Verify\EmailCode as EmailCodeService; use App\Services\Frontend\Verify\SmsCode as SmsCodeService; +use App\Services\Frontend\Verify\VerifyCode as VerifyCodeService; use App\Traits\Response as ResponseTrait; /** @@ -14,6 +15,18 @@ class VerifyController extends \Phalcon\Mvc\Controller use ResponseTrait; + /** + * @Post("/code", name="verify.code") + */ + public function verifyCodeAction() + { + $service = new VerifyCodeService(); + + $service->handle(); + + return $this->jsonSuccess(); + } + /** * @Post("/sms/code", name="verify.sms_code") */ diff --git a/app/Http/Web/Services/Account.php b/app/Http/Web/Services/Account.php index bf9fefe5..578e605f 100644 --- a/app/Http/Web/Services/Account.php +++ b/app/Http/Web/Services/Account.php @@ -2,7 +2,9 @@ namespace App\Http\Web\Services; +use App\Repos\User as UserRepo; use App\Services\Auth as AuthService; +use App\Services\Frontend\Account\Register as RegisterService; use App\Services\Frontend\Account\RegisterByEmail as RegisterByEmailService; use App\Services\Frontend\Account\RegisterByPhone as RegisterByPhoneService; use App\Validators\Account as AccountValidator; @@ -21,6 +23,19 @@ class Account extends Service $this->auth = $this->getDI()->get('auth'); } + public function register() + { + $service = new RegisterService(); + + $account = $service->handle(); + + $userRepo = new UserRepo(); + + $user = $userRepo->findById($account->id); + + $this->auth->saveAuthInfo($user); + } + public function registerByEmail() { $service = new RegisterByEmailService(); diff --git a/app/Http/Web/Views/account/login.volt b/app/Http/Web/Views/account/login.volt new file mode 100644 index 00000000..d9b7595f --- /dev/null +++ b/app/Http/Web/Views/account/login.volt @@ -0,0 +1,20 @@ +{% extends 'templates/base.volt' %} + +{% block content %} + +
+ +
+
+ {{ partial('account/login_by_password') }} +
+
+ {{ partial('account/login_by_verify') }} +
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/app/Http/Web/Views/account/login_by_password.volt b/app/Http/Web/Views/account/login_by_password.volt new file mode 100644 index 00000000..1ac69fdb --- /dev/null +++ b/app/Http/Web/Views/account/login_by_password.volt @@ -0,0 +1,35 @@ +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ 点击完成验证 + 验证成功 +
+
+
+
+ + + + +
+
+
\ No newline at end of file diff --git a/app/Http/Web/Views/account/login_by_verify.volt b/app/Http/Web/Views/account/login_by_verify.volt new file mode 100644 index 00000000..1fbd05e4 --- /dev/null +++ b/app/Http/Web/Views/account/login_by_verify.volt @@ -0,0 +1,29 @@ +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ 点击完成验证 + 验证成功 +
+
+
+
+ + + + +
+
+
\ No newline at end of file diff --git a/app/Http/Web/Views/account/register.volt b/app/Http/Web/Views/account/register.volt new file mode 100644 index 00000000..5c0d9573 --- /dev/null +++ b/app/Http/Web/Views/account/register.volt @@ -0,0 +1,81 @@ +{% extends 'templates/base.volt' %} + +{% block content %} + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ 点击完成验证 + 验证成功 +
+
+
+
+ + + + +
+
+
+
+{% endblock %} + +{% block inline_js %} + + + + + +{% endblock %} \ No newline at end of file diff --git a/app/Http/Web/Views/account/reset_password.volt b/app/Http/Web/Views/account/reset_password.volt new file mode 100644 index 00000000..861be26f --- /dev/null +++ b/app/Http/Web/Views/account/reset_password.volt @@ -0,0 +1,80 @@ +{% extends 'templates/base.volt' %} + +{% block content %} + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ 点击完成验证 + 验证成功 +
+
+
+
+ + + +
+
+
+
+{% endblock %} + +{% block inline_js %} + + + + + +{% endblock %} \ No newline at end of file diff --git a/app/Http/Web/Views/course/list.volt b/app/Http/Web/Views/course/list.volt index 23de18fa..8e382625 100644 --- a/app/Http/Web/Views/course/list.volt +++ b/app/Http/Web/Views/course/list.volt @@ -2,10 +2,11 @@ {% block content %} + {{ partial('partials/macro_course') }} + {{ partial('course/list_filter') }}
- {{ partial('partials/macro_course') }} {% for item in pager.items %} {{ course_card(item) }} {% endfor %} diff --git a/app/Http/Web/Views/templates/base.volt b/app/Http/Web/Views/templates/base.volt index 0a38ae3e..02da4987 100644 --- a/app/Http/Web/Views/templates/base.volt +++ b/app/Http/Web/Views/templates/base.volt @@ -26,23 +26,8 @@ {{ partial('partials/footer') }}
-{{ js_include('lib/layui/layui.js') }} - - +{{ js_include('lib/layui/layui.all.js') }} +{{ js_include('web/js/common.js') }} {% block include_js %}{% endblock %} diff --git a/app/Services/Frontend/Account/Register.php b/app/Services/Frontend/Account/Register.php new file mode 100644 index 00000000..463df9a9 --- /dev/null +++ b/app/Services/Frontend/Account/Register.php @@ -0,0 +1,48 @@ +request->getPost(); + + $verifyValidator = new VerifyValidator(); + + $verifyValidator->checkCode($post['account'], $post['verify_code']); + + $accountValidator = new AccountValidator(); + + $data = []; + + if (CommonValidator::phone($post['account'])) { + + $data['phone'] = $accountValidator->checkPhone($post['account']); + + $accountValidator->checkIfPhoneTaken($post['account']); + + } elseif (CommonValidator::email($post['account'])) { + + $data['email'] = $accountValidator->checkEmail($post['account']); + + $accountValidator->checkIfEmailTaken($post['account']); + } + + $data['password'] = $accountValidator->checkPassword($post['password']); + + $account = new AccountModel(); + + $account->create($data); + + return $account; + } + +} diff --git a/app/Services/Frontend/Verify/VerifyCode.php b/app/Services/Frontend/Verify/VerifyCode.php new file mode 100644 index 00000000..cbf46898 --- /dev/null +++ b/app/Services/Frontend/Verify/VerifyCode.php @@ -0,0 +1,36 @@ +request->getPost(); + + $captchaValidator = new CaptchaValidator(); + + $captchaValidator->checkCode($post['ticket'], $post['rand']); + + if (CommonValidator::phone($post['account'])) { + + $service = new VerifySmserService(); + + $service->handle($post['account']); + + } elseif (CommonValidator::email($post['account'])) { + + $service = new VerifyMailerService(); + + $service->handle($post['account']); + } + } + +} diff --git a/app/Validators/Account.php b/app/Validators/Account.php index a0a2bf94..137245cf 100644 --- a/app/Validators/Account.php +++ b/app/Validators/Account.php @@ -13,11 +13,19 @@ use App\Repos\User as UserRepo; class Account extends Validator { - public function checkAccount($id) + public function checkAccount($name) { $accountRepo = new AccountRepo(); - $account = $accountRepo->findById($id); + $account = null; + + if (CommonValidator::email($name)) { + $account = $accountRepo->findByEmail($name); + } elseif (CommonValidator::phone($name)) { + $account = $accountRepo->findByPhone($name); + } else { + $account = $accountRepo->findById($name); + } if (!$account) { throw new BadRequestException('account.not_found'); @@ -52,6 +60,16 @@ class Account extends Validator return $account; } + public function checkLoginName($name) + { + $isPhone = CommonValidator::phone($name); + $isEmail = CommonValidator::email($name); + + if (!$isPhone && !$isEmail) { + throw new BadRequestException('account.invalid_login_name'); + } + } + public function checkPhone($phone) { if (!CommonValidator::phone($phone)) { @@ -110,32 +128,13 @@ class Account extends Validator } } - public function checkLoginName($name) - { - $accountRepo = new AccountRepo(); - - $account = null; - - if (CommonValidator::email($name)) { - $account = $accountRepo->findByEmail($name); - } elseif (CommonValidator::phone($name)) { - $account = $accountRepo->findByPhone($name); - } - - if (!$account) { - throw new BadRequestException('account.login_name_incorrect'); - } - - return $account; - } - public function checkVerifyLogin($name, $code) { $verify = new Verify(); $verify->checkCode($name, $code); - $account = $this->checkLoginName($name); + $account = $this->checkAccount($name); $userRepo = new UserRepo(); @@ -144,7 +143,7 @@ class Account extends Validator public function checkUserLogin($name, $password) { - $account = $this->checkLoginName($name); + $account = $this->checkAccount($name); $hash = PasswordUtil::hash($password, $account->salt); diff --git a/config/errors.php b/config/errors.php index 301601fb..8e3542b0 100644 --- a/config/errors.php +++ b/config/errors.php @@ -40,8 +40,8 @@ $error['captcha.invalid_code'] = '无效的验证码'; */ $error['account.not_found'] = '账号不存在'; $error['account.login_block'] = '账号被锁定,无法登录'; -$error['account.login_name_incorrect'] = '登录账号不正确'; $error['account.login_password_incorrect'] = '登录密码不正确'; +$error['account.invalid_login_name'] = '无效的登录账户名'; $error['account.invalid_email'] = '无效的电子邮箱'; $error['account.invalid_phone'] = '无效的手机号'; $error['account.invalid_password'] = '无效的密码(字母或数字6-16位)'; diff --git a/public/static/web/css/common.css b/public/static/web/css/common.css index 335f4908..b2cd394a 100644 --- a/public/static/web/css/common.css +++ b/public/static/web/css/common.css @@ -51,8 +51,11 @@ body { } .search .layui-input { + border: none; height: 30px; font-size: 12px; + color: rgba(255, 255, 255, 0.5); + background-color: rgba(255, 255, 255, 0.05); } #main { @@ -310,4 +313,30 @@ body { .course-body .sidebar { float: left; width: 320px; +} + +.btn-verify { + color: green; +} + +.register-container { + padding: 50px 30px; + background-color: #fff; +} + +.register-container .layui-form { + width: 50%; +} + +.login-tab { + padding: 30px; + background-color: #fff; +} + +.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/common.js b/public/static/web/js/common.js new file mode 100644 index 00000000..75ef8f1f --- /dev/null +++ b/public/static/web/js/common.js @@ -0,0 +1,79 @@ +var $ = layui.jquery; +var element = layui.element; +var form = layui.form; +var layer = layui.layer; +var util = layui.util; + +$.ajaxSetup({ + beforeSend: function (xhr) { + xhr.setRequestHeader('X-Csrf-Token', $('meta[name="csrf-token"]').attr('content')); + } +}); + +util.fixbar({ + bar1: true, + click: function (type) { + console.log(type); + if (type === 'bar1') { + alert('点击了bar1'); + } + } +}); + +form.on('submit(go)', function (data) { + var submit = $(this); + submit.attr('disabled', true).addClass('layui-btn-disabled'); + $.ajax({ + type: 'POST', + url: data.form.action, + data: data.field, + success: function (res) { + var icon = res.code === 0 ? 1 : 2; + if (res.msg) { + layer.msg(res.msg, {icon: icon}); + } + if (res.location) { + setTimeout(function () { + window.location.href = res.location; + }, 1500); + } else { + submit.attr('disabled', false).removeClass('layui-btn-disabled'); + } + }, + error: function (xhr) { + var json = JSON.parse(xhr.responseText); + layer.msg(json.msg, {icon: 2}); + submit.attr('disabled', false).removeClass('layui-btn-disabled'); + } + }); + return false; +}); + +$('.kg-delete').on('click', function () { + var url = $(this).attr('data-url'); + var tips = '确定要删除吗?'; + layer.confirm(tips, function () { + $.ajax({ + type: 'POST', + url: url, + success: function (res) { + layer.msg(res.msg, {icon: 1}); + if (res.location) { + setTimeout(function () { + window.location.href = res.location; + }, 1500); + } else { + window.location.reload(); + } + }, + error: function (xhr) { + var json = JSON.parse(xhr.responseText); + layer.msg(json.msg, {icon: 2}); + } + }); + }); +}); + +$('.kg-back').on('click', function () { + window.history.back(); +}); \ No newline at end of file