Auth.php 737 B

123456789101112131415161718192021222324252627
  1. <?php namespace Manage\Lib;
  2. use Dever;
  3. use Dever\Helper\Secure;
  4. use Dever\Helper\Env;
  5. class Auth
  6. {
  7. protected $login = true;
  8. protected $uid;
  9. protected $user;
  10. public $data = array();
  11. public function __construct()
  12. {
  13. $auth = Env::header('authorization');
  14. if (!$auth) {
  15. $info['uid'] = 1;
  16. //Dever::error('请先登录');
  17. } else {
  18. $auth = ltrim($auth, 'Bearer ');
  19. $info = Secure::checkLogin($auth, 86400*7);
  20. if (!$info && $this->login) {
  21. Dever::error('请先登录');
  22. }
  23. }
  24. $this->uid = $info['uid'];
  25. $this->user = Dever::db('admin')->find($this->uid);
  26. }
  27. }