PageRenderTime 39ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/firstrend/src/admin/Lib/Action/PublicAction.class.php

http://ownerpress.googlecode.com/
PHP | 165 lines | 109 code | 16 blank | 40 comment | 11 complexity | 0063c81d20ac42788725ef993f795235 MD5 | raw file
Possible License(s): Apache-2.0, AGPL-1.0, GPL-2.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ?????????? (Build on ThinkPHP)
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: awfigq <awfigq@qq.com>
  10. // +----------------------------------------------------------------------
  11. /**
  12. +------------------------------------------------------------------------------
  13. * ??
  14. +------------------------------------------------------------------------------
  15. */
  16. class PublicAction extends CommonAction
  17. {
  18. /**
  19. +----------------------------------------------------------
  20. * ????????
  21. +----------------------------------------------------------
  22. */
  23. public function checkUser()
  24. {
  25. if (!isset($_SESSION[C('USER_AUTH_KEY')]))
  26. {
  27. $this->assign('jumpUrl', 'Public/login');
  28. $this->error(L('NOT_LOGIN'));
  29. }
  30. }
  31. /**
  32. +----------------------------------------------------------
  33. * ??????
  34. +----------------------------------------------------------
  35. */
  36. public function login()
  37. {
  38. if (!isset($_SESSION[C('USER_AUTH_KEY')]))
  39. {
  40. $this->display();
  41. }
  42. else
  43. {
  44. $this->redirect('Index/index');
  45. }
  46. }
  47. public function index()
  48. {
  49. //???????????
  50. redirect(__APP__);
  51. }
  52. /**
  53. +----------------------------------------------------------
  54. * ????
  55. +----------------------------------------------------------
  56. */
  57. public function logout()
  58. {
  59. if (isset($_SESSION[C('USER_AUTH_KEY')]))
  60. {
  61. $loginout_success = L('LOGOUT_SUCCESS');
  62. unset($_SESSION[C('USER_AUTH_KEY')]);
  63. unset($_SESSION);
  64. session_destroy();
  65. $this->assign("jumpUrl", U("Public/login"));
  66. $this->success($loginout_success);
  67. }
  68. else
  69. {
  70. $this->error(L('LOGOUT_ALREADY'));
  71. }
  72. }
  73. /**
  74. +----------------------------------------------------------
  75. * ????
  76. +----------------------------------------------------------
  77. */
  78. public function checkLogin()
  79. {
  80. if (empty($_POST['admin_name']))
  81. {
  82. $this->error(L('ADMIN_NAME_REQUIRE'));
  83. }
  84. elseif (empty($_POST['admin_pwd']))
  85. {
  86. $this->error(L('ADMIN_PWD_REQUIRE'));
  87. }
  88. elseif (empty($_POST['verify']))
  89. {
  90. $this->error(L('VERIFY_REQUIRE'));
  91. }
  92. //??????
  93. $map = array();
  94. // ??????????
  95. $map['admin_name'] = $_POST['admin_name'];
  96. $map["status"] = array('gt' , 0);
  97. if ($_SESSION['verify'] != md5($_POST['verify']))
  98. {
  99. $this->error(L('VERIFY_ERROR'));
  100. }
  101. import('@.ORG.RBAC');
  102. $auth_info = RBAC::authenticate($map);
  103. //??????????????????
  104. if (false === $auth_info)
  105. {
  106. $this->saveLog(0, 0);
  107. $this->error(L('ADMIN_NAME_NOT_EXIST'));
  108. }
  109. else
  110. {
  111. if ($auth_info['admin_pwd'] != md5($_POST['admin_pwd']))
  112. {
  113. $this->saveLog(0, 0);
  114. $this->error(L('ADMIN_PWD_ERROR'));
  115. }
  116. Session::setExpire(time() + fanweC("EXPIRED_TIME") * 60);
  117. $_SESSION[C('USER_AUTH_KEY')] = $auth_info['id'];
  118. $_SESSION['admin_name'] = $auth_info['admin_name'];
  119. $_SESSION['last_time'] = $auth_info['last_time'];
  120. $_SESSION['login_count'] = $auth_info['login_count'];
  121. if ($auth_info['admin_name'] == fanweC('SYS_ADMIN'))
  122. {
  123. $_SESSION[C('ADMIN_AUTH_KEY')] = true;
  124. }
  125. //??????
  126. $admin = M(C('USER_AUTH_MODEL'));
  127. $ip = getClientIp();
  128. $time = gmtTime();
  129. $data = array();
  130. $data['id'] = $auth_info['id'];
  131. $data['last_login_time'] = $time;
  132. $data['login_count'] = array('exp' , 'login_count + 1');
  133. $data['last_login_ip'] = $ip;
  134. $admin->save($data);
  135. // ??????
  136. RBAC::saveAccessList();
  137. $this->saveLog(1, 0);
  138. $this->success(L('LOGIN_SUCCESS'));
  139. }
  140. }
  141. public function verify ()
  142. {
  143. $type = isset($_GET['type']) ? $_GET['type'] : 'png';
  144. $type = 'png';
  145. import("@.ORG.Image");
  146. Image::buildImageVerify(4, 1, $type);
  147. }
  148. }
  149. ?>