MyValidate.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\adminapi\validate;
  20. use app\common\validate\BaseValidate;
  21. use app\common\model\Admin;
  22. use think\facade\Config;
  23. class MyValidate extends BaseValidate
  24. {
  25. protected $rule = [
  26. 'old_password' => 'require|checkOld',
  27. 'new_password' => 'require|length:6,32',
  28. 'new_password_confirm' => 'require|confirm:new_password',
  29. ];
  30. protected $message = [
  31. 'old_password.require' => '原密码不能为空',
  32. 'new_password.require' => '新密码不能为空',
  33. 'new_password.length' => '新密码长度需在6-32个字符之间',
  34. 'new_password_confirm.require' => '确认新密码不能为空',
  35. 'new_password_confirm.confirm' => '两次输入的新密码不一致',
  36. ];
  37. /**
  38. * @notes 校验原密码
  39. * @param $value
  40. * @param $rule
  41. * @param $data
  42. * @return bool|string
  43. * @author Tab
  44. * @date 2021/7/13 12:01
  45. */
  46. public function checkOld($value, $rule, $data)
  47. {
  48. $admin = Admin::findOrEmpty($data['id']);
  49. $passwordSalt = Config::get('project.unique_identification');
  50. $password = create_password($value, $passwordSalt);
  51. if ($admin->password != $password) {
  52. return '原密码错误';
  53. }
  54. return true;
  55. }
  56. }