/phpcms/modules/member/classes/foreground.class.php

https://github.com/hxzyzz/ddc · PHP · 76 lines · 61 code · 8 blank · 7 comment · 20 complexity · 4930dc12a4b08decd190e410449d98b1 MD5 · raw file

  1. <?php
  2. class foreground {
  3. public $db, $memberinfo;
  4. private $_member_modelinfo;
  5. public function __construct() {
  6. $this->db = pc_base::load_model('member_model');
  7. //ajaxÑéÖ¤ÐÅÏ¢²»ÐèÒªµÇ¼
  8. if(substr(ROUTE_A, 0, 7) != 'public_') {
  9. self::check_member();
  10. }
  11. }
  12. /**
  13. * ÅжÏÓû§ÊÇ·ñÒѾ­µÇ½
  14. */
  15. final public function check_member() {
  16. $phpcms_auth = param::get_cookie('auth');
  17. if(ROUTE_M =='member' && ROUTE_C =='index' && in_array(ROUTE_A, array('login', 'register', 'mini'))) {
  18. if ($phpcms_auth && ROUTE_A != 'mini') {
  19. showmessage(L('login_success', '', 'member'), 'index.php?m=member&c=index');
  20. } else {
  21. return true;
  22. }
  23. } else {
  24. //ÅжÏÊÇ·ñ´æÔÚauth cookie
  25. if ($phpcms_auth) {
  26. $auth_key = md5(pc_base::load_config('system', 'auth_key').str_replace('7.0' ,'8.0',$_SERVER['HTTP_USER_AGENT']));
  27. list($userid, $password) = explode("\t", sys_auth($phpcms_auth, 'DECODE', $auth_key));
  28. //ÑéÖ¤Óû§£¬»ñÈ¡Óû§ÐÅÏ¢
  29. $this->memberinfo = $this->db->get_one(array('userid'=>$userid));
  30. //»ñÈ¡Óû§Ä£ÐÍÐÅÏ¢
  31. $this->db->set_model($this->memberinfo['modelid']);
  32. $this->_member_modelinfo = $this->db->get_one(array('userid'=>$userid));
  33. $this->_member_modelinfo = $this->_member_modelinfo ? $this->_member_modelinfo : array();
  34. $this->db->set_model();
  35. if(is_array($this->memberinfo)) {
  36. $this->memberinfo = array_merge($this->memberinfo, $this->_member_modelinfo);
  37. }
  38. if($this->memberinfo && $this->memberinfo['password'] === $password) {
  39. if (!defined('SITEID')) {
  40. define('SITEID', $this->memberinfo['siteid']);
  41. }
  42. if($this->memberinfo['groupid'] == 1) {
  43. param::set_cookie('auth', '');
  44. param::set_cookie('_userid', '');
  45. param::set_cookie('_username', '');
  46. param::set_cookie('_groupid', '');
  47. showmessage(L('userid_banned_by_administrator', '', 'member'), 'index.php?m=member&c=index&a=login');
  48. } elseif($this->memberinfo['groupid'] == 7) {
  49. param::set_cookie('auth', '');
  50. param::set_cookie('_userid', '');
  51. param::set_cookie('_groupid', '');
  52. param::set_cookie('email', $this->memberinfo['email']);
  53. showmessage(L('need_emial_authentication', '', 'member'), 'index.php?m=member&c=index&a=register&t=2');
  54. }
  55. } else {
  56. param::set_cookie('auth', '');
  57. param::set_cookie('_userid', '');
  58. param::set_cookie('_username', '');
  59. param::set_cookie('_groupid', '');
  60. }
  61. unset($userid, $password, $phpcms_auth, $auth_key);
  62. } else {
  63. $forward= isset($_GET['forward']) ? urlencode($_GET['forward']) : urlencode(get_url());
  64. showmessage(L('please_login', '', 'member'), 'index.php?m=member&c=index&a=login&forward='.$forward);
  65. }
  66. }
  67. }
  68. }