暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ModuleInitBehavior.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\admin\behavior;
  3. use think\Config;
  4. /**
  5. * 系统行为扩展:
  6. */
  7. class ModuleInitBehavior {
  8. protected static $actionName;
  9. protected static $controllerName;
  10. protected static $moduleName;
  11. protected static $method;
  12. /**
  13. * 构造方法
  14. * @param Request $request Request对象
  15. * @access public
  16. */
  17. public function __construct()
  18. {
  19. }
  20. // 行为扩展的执行入口必须是run
  21. public function run(&$params){
  22. self::$actionName = request()->action();
  23. self::$controllerName = request()->controller();
  24. self::$moduleName = request()->module();
  25. self::$method = request()->method();
  26. $this->_initialize();
  27. }
  28. private function _initialize() {
  29. $this->vertifyCode();
  30. }
  31. /**
  32. * 登录 - 验证码
  33. * @param array $params 传入参数
  34. * @access public
  35. */
  36. private function vertifyCode()
  37. {
  38. /*只有相应的控制器和操作名才执行,以便提高性能*/
  39. $ctlActArr = array(
  40. 'Admin@login',
  41. 'Admin@vertify',
  42. );
  43. $ctlActStr = self::$controllerName.'@'.self::$actionName;
  44. if (in_array($ctlActStr, $ctlActArr)) {
  45. $row = tpSetting('system.system_vertify');
  46. // 获取验证码配置信息
  47. $row = json_decode($row, true);
  48. $baseConfig = Config::get("captcha");
  49. if (!empty($row)) {
  50. foreach ($row['captcha'] as $key => $val) {
  51. if ('default' == $key) {
  52. $baseConfig[$key] = array_merge($baseConfig[$key], $val);
  53. } else {
  54. $baseConfig[$key]['is_on'] = $val['is_on'];
  55. $baseConfig[$key]['config'] = array_merge($baseConfig['default'], $val['config']);
  56. }
  57. }
  58. }
  59. Config::set('captcha', $baseConfig);
  60. }
  61. }
  62. }