LoginValidate.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\kefuapi\validate;
  20. use app\common\cache\KefuAccountSafeCache;
  21. use app\common\model\Kefu;
  22. use app\common\validate\BaseValidate;
  23. use think\facade\Config;
  24. /**
  25. * 客服登录验证
  26. * Class LoginValidate
  27. * @package app\kefuapi\validate
  28. */
  29. class LoginValidate extends BaseValidate
  30. {
  31. protected $rule = [
  32. 'terminal' => 'require',
  33. 'account' => 'require',
  34. 'password' => 'require|checkPassword',
  35. ];
  36. protected $message = [
  37. 'account.require' => '请输入账号',
  38. 'password.require' => '请输入密码',
  39. 'password.checkPassword' => '账号或密码错误',
  40. 'terminal.require' => '客户端参数缺失'
  41. ];
  42. /**
  43. * @notes 密码验证
  44. * @param $password
  45. * @param $other
  46. * @param $data
  47. * @return bool|string
  48. * @author 段誉
  49. * @date 2022/3/9 18:54
  50. */
  51. public function checkPassword($password, $other, $data)
  52. {
  53. //后台账号安全机制,连续输错后锁定,防止账号密码暴力破解
  54. $SafeCache = new KefuAccountSafeCache();
  55. if (!$SafeCache->isSafe()) {
  56. return '密码连续' . $SafeCache->count . '次输入错误,请' . $SafeCache->minute . '分钟后重试';
  57. }
  58. $kefu = Kefu::alias('k')->field([
  59. 'a.password',
  60. 'a.disable' => 'admin_disable',
  61. 'k.disable' => 'kefu_disable'
  62. ])
  63. ->join('admin a', 'k.admin_id = a.id')
  64. ->where(['a.account' => $data['account']])
  65. ->findOrEmpty();
  66. if ($kefu->isEmpty()) {
  67. return '用户不存在';
  68. }
  69. if ($kefu['admin_disable'] || $kefu['kefu_disable']) {
  70. return '账号已禁用';
  71. }
  72. if (empty($kefu['password'])) {
  73. $SafeCache->record();
  74. return '客服不存在';
  75. }
  76. $passwordSalt = Config::get('project.unique_identification');
  77. if ($kefu['password'] !== create_password($password, $passwordSalt)) {
  78. $SafeCache->record();
  79. return '密码错误';
  80. }
  81. $SafeCache->relieve();
  82. return true;
  83. }
  84. }