diff --git a/app/Http/Home/Controllers/AccountController.php b/app/Http/Home/Controllers/AccountController.php
index 320cb9c5..2c5fa763 100644
--- a/app/Http/Home/Controllers/AccountController.php
+++ b/app/Http/Home/Controllers/AccountController.php
@@ -51,25 +51,6 @@ class AccountController extends Controller
$this->view->setVar('captcha', $captcha);
}
- /**
- * @Post("/register", name="home.account.do_register")
- */
- public function doRegisterAction()
- {
- $service = new AccountService();
-
- $service->register();
-
- $returnUrl = $this->request->getPost('return_url', 'string');
-
- $content = [
- 'location' => $returnUrl ?: '/',
- 'msg' => '注册成功',
- ];
-
- return $this->jsonSuccess($content);
- }
-
/**
* @Get("/login", name="home.account.login")
*/
@@ -103,38 +84,6 @@ class AccountController extends Controller
$this->view->setVar('captcha', $captcha);
}
- /**
- * @Post("/password/login", name="home.account.pwd_login")
- */
- public function loginByPasswordAction()
- {
- $service = new AccountService();
-
- $service->loginByPassword();
-
- $returnUrl = $this->request->getPost('return_url', 'string');
-
- $location = $returnUrl ?: $this->url->get(['for' => 'home.index']);
-
- return $this->jsonSuccess(['location' => $location]);
- }
-
- /**
- * @Post("/verify/login", name="home.account.verify_login")
- */
- public function loginByVerifyAction()
- {
- $service = new AccountService();
-
- $service->loginByVerify();
-
- $returnUrl = $this->request->getPost('return_url', 'string');
-
- $location = $returnUrl ?: $this->url->get(['for' => 'home.index']);
-
- return $this->jsonSuccess(['location' => $location]);
- }
-
/**
* @Get("/logout", name="home.account.logout")
*/
@@ -172,6 +121,57 @@ class AccountController extends Controller
$this->view->setVar('captcha', $captcha);
}
+ /**
+ * @Post("/register", name="home.account.do_register")
+ */
+ public function doRegisterAction()
+ {
+ $service = new AccountService();
+
+ $service->register();
+
+ $returnUrl = $this->request->getPost('return_url', 'string');
+
+ $content = [
+ 'location' => $returnUrl ?: '/',
+ 'msg' => '注册成功',
+ ];
+
+ return $this->jsonSuccess($content);
+ }
+
+ /**
+ * @Post("/password/login", name="home.account.pwd_login")
+ */
+ public function loginByPasswordAction()
+ {
+ $service = new AccountService();
+
+ $service->loginByPassword();
+
+ $returnUrl = $this->request->getPost('return_url', 'string');
+
+ $location = $returnUrl ?: $this->url->get(['for' => 'home.index']);
+
+ return $this->jsonSuccess(['location' => $location]);
+ }
+
+ /**
+ * @Post("/verify/login", name="home.account.verify_login")
+ */
+ public function loginByVerifyAction()
+ {
+ $service = new AccountService();
+
+ $service->loginByVerify();
+
+ $returnUrl = $this->request->getPost('return_url', 'string');
+
+ $location = $returnUrl ?: $this->url->get(['for' => 'home.index']);
+
+ return $this->jsonSuccess(['location' => $location]);
+ }
+
/**
* @Post("/password/reset", name="home.account.reset_pwd")
*/
diff --git a/app/Http/Home/Services/Account.php b/app/Http/Home/Services/Account.php
index 0c3f0dfc..02e771db 100644
--- a/app/Http/Home/Services/Account.php
+++ b/app/Http/Home/Services/Account.php
@@ -47,6 +47,15 @@ class Account extends Service
{
$post = $this->request->getPost();
+ /**
+ * 使用[account|phone|email]做账户名字段兼容
+ */
+ if (isset($post['phone'])) {
+ $post['account'] = $post['phone'];
+ } elseif (isset($post['email'])) {
+ $post['account'] = $post['email'];
+ }
+
$validator = new AccountValidator();
$user = $validator->checkUserLogin($post['account'], $post['password']);
@@ -74,6 +83,15 @@ class Account extends Service
{
$post = $this->request->getPost();
+ /**
+ * 使用[account|phone|email]做账户名字段兼容
+ */
+ if (isset($post['phone'])) {
+ $post['account'] = $post['phone'];
+ } elseif (isset($post['email'])) {
+ $post['account'] = $post['email'];
+ }
+
$validator = new AccountValidator();
$user = $validator->checkVerifyLogin($post['account'], $post['verify_code']);
diff --git a/app/Http/Home/Views/account/forget.volt b/app/Http/Home/Views/account/forget.volt
index 8056110f..78c3b2eb 100644
--- a/app/Http/Home/Views/account/forget.volt
+++ b/app/Http/Home/Views/account/forget.volt
@@ -6,7 +6,6 @@
@@ -26,9 +25,9 @@
@@ -37,6 +36,7 @@
{% block include_js %}
{{ js_include('https://ssl.captcha.qq.com/TCaptcha.js',false) }}
- {{ js_include('home/js/captcha.verify.js') }}
+ {{ js_include('home/js/captcha.verify.phone.js') }}
+ {{ js_include('home/js/captcha.verify.email.js') }}
{% endblock %}
\ No newline at end of file
diff --git a/app/Http/Home/Views/account/forget_by_email.volt b/app/Http/Home/Views/account/forget_by_email.volt
index 2a61dff4..c203d6bd 100644
--- a/app/Http/Home/Views/account/forget_by_email.volt
+++ b/app/Http/Home/Views/account/forget_by_email.volt
@@ -1,7 +1,7 @@
\ No newline at end of file
diff --git a/app/Http/Home/Views/account/forget_by_phone.volt b/app/Http/Home/Views/account/forget_by_phone.volt
index fc766c82..f70b6c69 100644
--- a/app/Http/Home/Views/account/forget_by_phone.volt
+++ b/app/Http/Home/Views/account/forget_by_phone.volt
@@ -1,7 +1,7 @@
\ No newline at end of file
diff --git a/app/Http/Home/Views/account/login.volt b/app/Http/Home/Views/account/login.volt
index e2746070..5bbcc1f1 100644
--- a/app/Http/Home/Views/account/login.volt
+++ b/app/Http/Home/Views/account/login.volt
@@ -4,8 +4,7 @@
@@ -24,7 +23,7 @@
diff --git a/app/Http/Home/Views/account/register.volt b/app/Http/Home/Views/account/register.volt
index 6e72d254..ab4329cc 100644
--- a/app/Http/Home/Views/account/register.volt
+++ b/app/Http/Home/Views/account/register.volt
@@ -8,8 +8,7 @@
@@ -28,7 +27,7 @@
@@ -39,6 +38,7 @@
{% block include_js %}
{{ js_include('https://ssl.captcha.qq.com/TCaptcha.js',false) }}
- {{ js_include('home/js/captcha.verify.js') }}
+ {{ js_include('home/js/captcha.verify.phone.js') }}
+ {{ js_include('home/js/captcha.verify.email.js') }}
{% endblock %}
diff --git a/app/Http/Home/Views/account/register_by_email.volt b/app/Http/Home/Views/account/register_by_email.volt
index cc4d917c..75471e99 100644
--- a/app/Http/Home/Views/account/register_by_email.volt
+++ b/app/Http/Home/Views/account/register_by_email.volt
@@ -2,7 +2,7 @@
diff --git a/app/Http/Home/Views/account/register_by_phone.volt b/app/Http/Home/Views/account/register_by_phone.volt
index dd5104a5..e08f494a 100644
--- a/app/Http/Home/Views/account/register_by_phone.volt
+++ b/app/Http/Home/Views/account/register_by_phone.volt
@@ -2,7 +2,7 @@
diff --git a/app/Http/Home/Views/user/console/account_email.volt b/app/Http/Home/Views/user/console/account_email.volt
index 0f549223..92835d5f 100644
--- a/app/Http/Home/Views/user/console/account_email.volt
+++ b/app/Http/Home/Views/user/console/account_email.volt
@@ -19,7 +19,7 @@
@@ -28,16 +28,16 @@
-
+
diff --git a/app/Http/Home/Views/user/console/account_phone.volt b/app/Http/Home/Views/user/console/account_phone.volt
index f2475cd2..be966aa2 100644
--- a/app/Http/Home/Views/user/console/account_phone.volt
+++ b/app/Http/Home/Views/user/console/account_phone.volt
@@ -19,7 +19,7 @@
@@ -28,16 +28,16 @@
-
+
diff --git a/app/Services/Logic/Account/PasswordReset.php b/app/Services/Logic/Account/PasswordReset.php
index 57f71008..cdc2e635 100644
--- a/app/Services/Logic/Account/PasswordReset.php
+++ b/app/Services/Logic/Account/PasswordReset.php
@@ -19,6 +19,15 @@ class PasswordReset extends LogicService
{
$post = $this->request->getPost();
+ /**
+ * 使用[account|phone|email]做账户名字段兼容
+ */
+ if (isset($post['phone'])) {
+ $post['account'] = $post['phone'];
+ } elseif (isset($post['email'])) {
+ $post['account'] = $post['email'];
+ }
+
$accountValidator = new AccountValidator();
$account = $accountValidator->checkAccount($post['account']);
diff --git a/app/Services/Logic/Account/Register.php b/app/Services/Logic/Account/Register.php
index e2c36e02..449e7030 100644
--- a/app/Services/Logic/Account/Register.php
+++ b/app/Services/Logic/Account/Register.php
@@ -21,6 +21,15 @@ class Register extends LogicService
{
$post = $this->request->getPost();
+ /**
+ * 使用[account|phone|email]做账户名字段兼容
+ */
+ if (isset($post['phone'])) {
+ $post['account'] = $post['phone'];
+ } elseif (isset($post['email'])) {
+ $post['account'] = $post['email'];
+ }
+
$verifyValidator = new VerifyValidator();
$verifyValidator->checkCode($post['account'], $post['verify_code']);
diff --git a/public/static/home/js/captcha.verify.email.js b/public/static/home/js/captcha.verify.email.js
new file mode 100644
index 00000000..8ab8f11b
--- /dev/null
+++ b/public/static/home/js/captcha.verify.email.js
@@ -0,0 +1,80 @@
+layui.use(['jquery', 'layer', 'util', 'helper'], function () {
+
+ var $ = layui.jquery;
+ var layer = layui.layer;
+ var util = layui.util;
+ var helper = layui.helper;
+
+ var timeCounting = false;
+ var $account = $('#cv-email');
+ var $emit = $('#cv-email-emit-btn');
+ var $submit = $('#cv-email-submit-btn');
+
+ if ($('#cv-email-captcha-enabled').val() === '1') {
+ var captcha = new TencentCaptcha(
+ $emit[0],
+ $('#cv-email-captcha-appId').val(),
+ function (res) {
+ if (res.ret === 0) {
+ $('#cv-email-captcha-ticket').val(res.ticket);
+ $('#cv-email-captcha-rand').val(res.randstr);
+ sendVerifyCode();
+ }
+ }
+ );
+ } else {
+ $emit.on('click', function () {
+ sendVerifyCode();
+ });
+ }
+
+ $account.on('keyup', function () {
+ var account = $(this).val();
+ var accountOk = helper.isEmail(account);
+ if (accountOk && !timeCounting) {
+ $emit.removeClass('layui-btn-disabled').removeAttr('disabled');
+ } else {
+ $emit.addClass('layui-btn-disabled').attr('disabled', 'disabled');
+ }
+ });
+
+ function sendVerifyCode() {
+ if (helper.isEmail($account.val())) {
+ var postUrl = '/verify/mail/code';
+ var postData = {
+ email: $account.val(),
+ captcha: {
+ ticket: $('#cv-email-captcha-ticket').val(),
+ rand: $('#cv-email-captcha-rand').val(),
+ }
+ };
+ $.ajax({
+ type: 'POST',
+ url: postUrl,
+ data: postData,
+ success: function () {
+ layer.msg('发送验证码成功', {icon: 1});
+ }
+ });
+ $submit.removeClass('layui-btn-disabled').removeAttr('disabled');
+ $emit.addClass('layui-btn-disabled').attr('disabled', 'disabled');
+ showCountDown($emit);
+ }
+ }
+
+ function showCountDown() {
+ var serverTime = new Date().getTime();
+ var endTime = serverTime + 60 * 1000;
+ util.countdown(endTime, serverTime, function (date, serverTime, timer) {
+ var left = date[0] * 86400 + date[1] * 3600 + date[2] * 60 + date[3];
+ $emit.text(left + '秒');
+ if (left === 0) {
+ $emit.removeClass('layui-btn-disabled').removeAttr('disabled').text('重新发送');
+ clearInterval(timer);
+ timeCounting = false;
+ }
+ });
+ timeCounting = true;
+ }
+
+});
\ No newline at end of file
diff --git a/public/static/home/js/captcha.verify.js b/public/static/home/js/captcha.verify.js
index 5340f9fb..a8bcf813 100644
--- a/public/static/home/js/captcha.verify.js
+++ b/public/static/home/js/captcha.verify.js
@@ -1,8 +1,9 @@
-layui.use(['jquery', 'layer', 'util'], function () {
+layui.use(['jquery', 'layer', 'util', 'helper'], function () {
var $ = layui.jquery;
var layer = layui.layer;
var util = layui.util;
+ var helper = layui.helper;
var timeCounting = false;
var $account = $('#cv-account');
@@ -28,16 +29,8 @@ layui.use(['jquery', 'layer', 'util'], function () {
}
$account.on('keyup', function () {
- var accountOk;
- var type = $(this).data('type');
var account = $(this).val();
- if (type === 'phone') {
- accountOk = isPhone(account);
- } else if (type === 'email') {
- accountOk = isEmail(account);
- } else {
- accountOk = isPhone(account) || isEmail(account);
- }
+ var accountOk = helper.isPhone(account) || helper.isEmail(account);
if (accountOk && !timeCounting) {
$emit.removeClass('layui-btn-disabled').removeAttr('disabled');
} else {
@@ -46,7 +39,7 @@ layui.use(['jquery', 'layer', 'util'], function () {
});
function sendVerifyCode() {
- if (isEmail($account.val()) || isPhone($account.val())) {
+ if (helper.isEmail($account.val()) || helper.isPhone($account.val())) {
var postUrl;
var postData = {
captcha: {
@@ -54,10 +47,10 @@ layui.use(['jquery', 'layer', 'util'], function () {
rand: $('#cv-captcha-rand').val(),
}
};
- if (isPhone($account.val())) {
+ if (helper.isPhone($account.val())) {
postData.phone = $account.val();
postUrl = '/verify/sms/code';
- } else if (isEmail($account.val())) {
+ } else if (helper.isEmail($account.val())) {
postData.email = $account.val();
postUrl = '/verify/mail/code';
}
@@ -90,12 +83,4 @@ layui.use(['jquery', 'layer', 'util'], function () {
timeCounting = true;
}
- function isEmail(email) {
- return /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(email);
- }
-
- function isPhone(phone) {
- return /^1(3|4|5|6|7|8|9)\d{9}$/.test(phone);
- }
-
});
\ No newline at end of file
diff --git a/public/static/home/js/captcha.verify.phone.js b/public/static/home/js/captcha.verify.phone.js
new file mode 100644
index 00000000..95f0a731
--- /dev/null
+++ b/public/static/home/js/captcha.verify.phone.js
@@ -0,0 +1,80 @@
+layui.use(['jquery', 'layer', 'util', 'helper'], function () {
+
+ var $ = layui.jquery;
+ var layer = layui.layer;
+ var util = layui.util;
+ var helper = layui.helper;
+
+ var timeCounting = false;
+ var $account = $('#cv-phone');
+ var $emit = $('#cv-phone-emit-btn');
+ var $submit = $('#cv-phone-submit-btn');
+
+ if ($('#cv-phone-captcha-enabled').val() === '1') {
+ var captcha = new TencentCaptcha(
+ $emit[0],
+ $('#cv-phone-captcha-appId').val(),
+ function (res) {
+ if (res.ret === 0) {
+ $('#cv-phone-captcha-ticket').val(res.ticket);
+ $('#cv-phone-captcha-rand').val(res.randstr);
+ sendVerifyCode();
+ }
+ }
+ );
+ } else {
+ $emit.on('click', function () {
+ sendVerifyCode();
+ });
+ }
+
+ $account.on('keyup', function () {
+ var account = $(this).val();
+ var accountOk = helper.isPhone(account);
+ if (accountOk && !timeCounting) {
+ $emit.removeClass('layui-btn-disabled').removeAttr('disabled');
+ } else {
+ $emit.addClass('layui-btn-disabled').attr('disabled', 'disabled');
+ }
+ });
+
+ function sendVerifyCode() {
+ if (helper.isPhone($account.val())) {
+ var postUrl = '/verify/sms/code';
+ var postData = {
+ phone: $account.val(),
+ captcha: {
+ ticket: $('#cv-phone-captcha-ticket').val(),
+ rand: $('#cv-phone-captcha-rand').val(),
+ }
+ };
+ $.ajax({
+ type: 'POST',
+ url: postUrl,
+ data: postData,
+ success: function () {
+ layer.msg('发送验证码成功', {icon: 1});
+ }
+ });
+ $submit.removeClass('layui-btn-disabled').removeAttr('disabled');
+ $emit.addClass('layui-btn-disabled').attr('disabled', 'disabled');
+ showCountDown($emit);
+ }
+ }
+
+ function showCountDown() {
+ var serverTime = new Date().getTime();
+ var endTime = serverTime + 60 * 1000;
+ util.countdown(endTime, serverTime, function (date, serverTime, timer) {
+ var left = date[0] * 86400 + date[1] * 3600 + date[2] * 60 + date[3];
+ $emit.text(left + '秒');
+ if (left === 0) {
+ $emit.removeClass('layui-btn-disabled').removeAttr('disabled').text('重新发送');
+ clearInterval(timer);
+ timeCounting = false;
+ }
+ });
+ timeCounting = true;
+ }
+
+});
\ No newline at end of file
diff --git a/public/static/lib/layui/extends/helper.js b/public/static/lib/layui/extends/helper.js
index 2c3c686b..336d1b36 100644
--- a/public/static/lib/layui/extends/helper.js
+++ b/public/static/lib/layui/extends/helper.js
@@ -6,6 +6,14 @@ layui.define(['jquery', 'layer'], function (exports) {
var helper = {};
+ helper.isEmail = function (email) {
+ return /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(email);
+ };
+
+ helper.isPhone = function (phone) {
+ return /^1(3|4|5|6|7|8|9)\d{9}$/.test(phone);
+ };
+
helper.getRequestId = function () {
var id = Date.now().toString(36);
id += Math.random().toString(36).substr(3);