PageRenderTime 25ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/01.Source/01.CORE/includes/core/is_user.php

http://creative-portal.googlecode.com/
PHP | 166 lines | 142 code | 14 blank | 10 comment | 21 complexity | b38c49c45a86b77d0df24a5249260337 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.0
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @copyright 2009
  6. * @createdate 12/29/2009 4:15
  7. */
  8. if ( ! defined( 'NV_MAINFILE' ) ) die( 'Stop!!!' );
  9. $user_info = array();
  10. if ( defined( "NV_IS_ADMIN" ) )
  11. {
  12. $user_info = $admin_info;
  13. define( 'NV_IS_USER', true );
  14. }
  15. elseif ( defined( 'NV_IS_USER_FORUM' ) )
  16. {
  17. require_once ( NV_ROOTDIR . '/' . DIR_FORUM . '/nukeviet/is_user.php' );
  18. if ( isset( $user_info['userid'] ) and $user_info['userid'] > 0 )
  19. {
  20. $query = "SELECT * FROM `" . NV_USERS_GLOBALTABLE . "` WHERE `userid` = " . $user_info['userid'] . " AND `active`=1";
  21. $result = $db->sql_query( $query );
  22. $numrows = $db->sql_numrows( $result );
  23. if ( $numrows == 1 )
  24. {
  25. define( 'NV_IS_USER', true );
  26. $row = $db->sql_fetchrow( $result );
  27. $user_info['userid'] = intval( $row['userid'] );
  28. $user_info['username'] = $row['username'];
  29. $user_info['email'] = $row['email'];
  30. $user_info['full_name'] = $row['full_name'];
  31. $user_info['gender'] = $row['gender'];
  32. $user_info['photo'] = $row['photo'];
  33. $user_info['birthday'] = intval( $row['birthday'] );
  34. $user_info['regdate'] = intval( $row['regdate'] );
  35. $user_info['website'] = $row['website'];
  36. $user_info['location'] = $row['location'];
  37. $user_info['yim'] = $row['yim'];
  38. $user_info['telephone'] = $row['telephone'];
  39. $user_info['fax'] = $row['fax'];
  40. $user_info['mobile'] = $row['mobile'];
  41. $user_info['view_mail'] = intval( $row['view_mail'] );
  42. $user_info['remember'] = intval( $row['remember'] );
  43. $user_info['in_groups'] = nv_user_groups( $row['in_groups'] );
  44. $user_info['current_login'] = intval( $row['last_login'] );
  45. // $user_info['last_login'] = intval( $user['last_login'] );
  46. $user_info['current_agent'] = $row['last_agent'];
  47. // $user_info['last_agent'] = $user['last_agent'];
  48. $user_info['current_ip'] = $row['last_ip'];
  49. $user_info['last_openid'] = $row['last_openid'];
  50. //$user_info['last_ip'] = $user['last_ip'];
  51. $user_info['st_login'] = ! empty( $row['password'] ) ? true : false;
  52. //$user_info['current_mode'] = $user['current_mode'];
  53. $user_info['current_mode'] = 1;
  54. $user_info['valid_question'] = true;
  55. }
  56. else
  57. {
  58. $user_info = array();
  59. }
  60. }
  61. }
  62. else
  63. {
  64. if ( $nv_Request->get_bool( 'nvloginhash', 'cookie', false ) )
  65. {
  66. $_user = $nv_Request->get_string( 'nvloginhash', 'cookie', '' );
  67. if ( ! empty( $_user ) and $global_config['allowuserlogin'] )
  68. {
  69. $user = unserialize( nv_base64_decode( $_user ) );
  70. $strlen = ( NV_CRYPT_SHA1 == 1 ) ? 40 : 32;
  71. if ( isset( $user['userid'] ) and is_numeric( $user['userid'] ) and $user['userid'] > 0 )
  72. {
  73. if ( isset( $user['checknum'] ) and preg_match( "/^[a-z0-9]{" . $strlen . "}$/", $user['checknum'] ) )
  74. {
  75. $query = "SELECT * FROM `" . NV_USERS_GLOBALTABLE . "` WHERE `userid` = " . $user['userid'] . " AND `active`=1";
  76. $result = $db->sql_query( $query );
  77. $numrows = $db->sql_numrows( $result );
  78. if ( $numrows == 1 )
  79. {
  80. $row = $db->sql_fetchrow( $result );
  81. $db->sql_freeresult( $result );
  82. if ( strcasecmp( $user['checknum'], $row['checknum'] ) == 0 and //checknum
  83. isset( $user['current_agent'] ) and ! empty( $user['current_agent'] ) and strcasecmp( $user['current_agent'], $row['last_agent'] ) == 0 and //user_agent
  84. isset( $user['current_ip'] ) and ! empty( $user['current_ip'] ) and strcasecmp( $user['current_ip'], $row['last_ip'] ) == 0 and //current IP
  85. isset( $user['current_login'] ) and ! empty( $user['current_login'] ) and strcasecmp( $user['current_login'], intval( $row['last_login'] ) ) == 0 ) //current login
  86. {
  87. $user_info['userid'] = intval( $row['userid'] );
  88. $user_info['username'] = $row['username'];
  89. $user_info['email'] = $row['email'];
  90. $user_info['full_name'] = $row['full_name'];
  91. $user_info['gender'] = $row['gender'];
  92. $user_info['photo'] = $row['photo'];
  93. $user_info['birthday'] = intval( $row['birthday'] );
  94. $user_info['regdate'] = intval( $row['regdate'] );
  95. $user_info['website'] = $row['website'];
  96. $user_info['location'] = $row['location'];
  97. $user_info['yim'] = $row['yim'];
  98. $user_info['telephone'] = $row['telephone'];
  99. $user_info['fax'] = $row['fax'];
  100. $user_info['mobile'] = $row['mobile'];
  101. $user_info['view_mail'] = intval( $row['view_mail'] );
  102. $user_info['remember'] = intval( $row['remember'] );
  103. $user_info['in_groups'] = nv_user_groups( $row['in_groups'] );
  104. $user_info['current_login'] = intval( $row['last_login'] );
  105. $user_info['last_login'] = intval( $user['last_login'] );
  106. $user_info['current_agent'] = $row['last_agent'];
  107. $user_info['last_agent'] = $user['last_agent'];
  108. $user_info['current_ip'] = $row['last_ip'];
  109. $user_info['last_ip'] = $user['last_ip'];
  110. $user_info['current_openid'] = $row['last_openid'];
  111. $user_info['last_openid'] = $user['last_openid'];
  112. $user_info['st_login'] = ! empty( $row['password'] ) ? true : false;
  113. $user_info['valid_question'] = ( ! empty( $row['question'] ) and ! empty( $row['answer'] ) ) ? true : false;
  114. $user_info['current_mode'] = ! empty( $row['last_openid'] ) ? 2 : 1;
  115. if ( ! empty( $row['last_openid'] ) )
  116. {
  117. $query2 = "SELECT * FROM `" . NV_USERS_GLOBALTABLE . "_openid` WHERE `opid`=" . $db->dbescape( $row['last_openid'] );
  118. $result2 = $db->sql_query( $query2 );
  119. $numrows2 = $db->sql_numrows( $result2 );
  120. if ( $numrows2 != 1 )
  121. {
  122. $user_info = array();
  123. }
  124. else
  125. {
  126. $row2 = $db->sql_fetchrow( $result2 );
  127. $db->sql_freeresult( $result2 );
  128. $user_info['openid_id'] = $row2['openid'];
  129. $user_info['openid_email'] = $row2['email'];
  130. $user_info['openid_server'] = parse_url( $row2['openid'] );
  131. $user_info['openid_server'] = $user_info['openid_server']['host'];
  132. $user_info['openid_server'] = preg_replace( "/^([w]{3})\./", "", $user_info['openid_server'] );
  133. }
  134. }
  135. }
  136. }
  137. }
  138. }
  139. }
  140. if ( ! empty( $user_info ) and isset( $user_info['userid'] ) and $user_info['userid'] > 0 )
  141. {
  142. define( 'NV_IS_USER', true );
  143. }
  144. else
  145. {
  146. $nv_Request->unset_request( 'nvloginhash', 'cookie' );
  147. $user_info = array();
  148. }
  149. }
  150. unset( $user, $_user, $query, $result, $numrows, $row, $query2, $result2, $numrows2, $row2 );
  151. }
  152. ?>