singleEdit.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace app\validate\admin\user;
  3. use app\model\admin\User;
  4. use think\Validate;
  5. class singleEdit extends Validate
  6. {
  7. //数组顺序就是检测的顺序
  8. protected $rule = [
  9. 'id' => 'require',
  10. 'nickname' => 'require|length:2,30',
  11. 'old_password' => 'length:6,30|checkOldPassword:',
  12. 'password' => 'length:6,30|confirm:re_password',
  13. ];
  14. //定义内置方法检验失败后返回的字符
  15. protected $message = [
  16. 'id.require' => 'ID不能为空',
  17. 'nickname.require' => '昵称不能为空',
  18. 'nickname.length' => '昵称长度2-30',
  19. 'old_password.length' => '旧密码长度6-30',
  20. 'password.length' => '新密码长度6-30',
  21. 'password.confirm' => '两次新密码输入不相同',
  22. ];
  23. //验证旧密码是否正确
  24. protected function checkOldPassword($oldPassword, $rule, $data){
  25. $passwordHash = User::getFieldById($data['id'], 'password');
  26. if(!password_verify(md5($oldPassword), $passwordHash)){
  27. return '旧密码错误';
  28. }
  29. return true;
  30. }
  31. }