PageRenderTime 54ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/580w/Lib/Action/PublicAction.class.php

http://iiccms.googlecode.com/
PHP | 363 lines | 225 code | 20 blank | 118 comment | 34 complexity | 17c7daac7b7511d29bf4c155087dab19 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. class PublicAction extends Action {
  3. public function _initialize() {
  4. import('ORG.Util.RBAC');
  5. if (C('USER_AUTH_ON') && !in_array(MODULE_NAME,explode(',',C('NOT_AUTH_MODULE')))) {
  6. if (!RBAC::AccessDecision()) {
  7. //???????
  8. if (!$_SESSION [C('USER_AUTH_KEY')]) {
  9. //???????
  10. redirect(PHP_FILE.C('USER_AUTH_GATEWAY'));
  11. }
  12. // ???? ????
  13. if (C ( 'RBAC_ERROR_PAGE' )) {
  14. // ????????
  15. redirect (C('RBAC_ERROR_PAGE' ));
  16. } else {
  17. if (C('GUEST_AUTH_ON' )) {
  18. $this->assign('jumpUrl',PHP_FILE.C('USER_AUTH_GATEWAY'));
  19. }
  20. // ??????
  21. $this->error ('?????');
  22. }
  23. }
  24. }
  25. import("ORG.Util.Page");//?????
  26. import("@.Com.ajaxpage");//??ajax???
  27. }
  28. public function checkLogin() {
  29. if(empty($_POST['account'])) {
  30. $this->error('?????');
  31. }elseif (empty($_POST['password'])){
  32. $this->error('?????');
  33. }elseif (empty($_POST['verify'])){
  34. $this->error('??????');
  35. }
  36. // ???????
  37. $verifyCodeStr = $_POST['verify'];
  38. $verifyCodeNum = array_flip($_SESSION['verifyCode']);
  39. $len = strlen(trim($_POST['verify']));
  40. for($i=0; $i<$len; $i++) {
  41. $verify .= $verifyCodeNum[$verifyCodeStr[$i]];
  42. }
  43. if($verify!='0123456789'){
  44. $this->error('??????');
  45. }
  46. $User = M('User');
  47. //??????
  48. $map = array();
  49. $map["account"] = $_POST['account'];
  50. $map["status"] = array('gt',0);
  51. //$authInfo = $User->find($map);
  52. $authInfo = RBAC::authenticate($map);
  53. //??????????????????
  54. if(false === $authInfo) {
  55. $this->error('??????????');
  56. }else {
  57. if($authInfo['password'] != md5($_POST['password'])) {
  58. $this->error('?????');
  59. }
  60. $_SESSION[C('USER_AUTH_KEY')] = $authInfo['id'];
  61. $_SESSION['email'] = $authInfo['email'];
  62. $_SESSION['loginUserName'] = $authInfo['nickname'];
  63. $_SESSION['lastLoginTime'] = $authInfo['last_login_time'];
  64. $_SESSION['login_count'] = $authInfo['login_count'];
  65. if($authInfo['account']=='admin') {
  66. $_SESSION['administrator'] = true;
  67. }
  68. //??????
  69. $User = M('User');
  70. $ip = get_client_ip();
  71. $time = time();
  72. $data = array();
  73. $data['id'] = $authInfo['id'];
  74. $data['last_login_time'] = $time;
  75. $data['login_count'] = array('exp','login_count+1');
  76. $data['last_login_ip'] = $ip;
  77. $User->save($data);
  78. // ??????
  79. RBAC::saveAccessList();
  80. $this->success('?????');
  81. }
  82. }
  83. public function login() {
  84. if(!isset($_SESSION[C('USER_AUTH_KEY')])) {
  85. $this->display();
  86. }else{
  87. $this->redirect('/Index/index');
  88. }
  89. }
  90. public function logout()
  91. {
  92. if(isset($_SESSION[C('USER_AUTH_KEY')])) {
  93. unset($_SESSION['menu'.$_SESSION[C('USER_AUTH_KEY')]]);
  94. unset($_SESSION[C('USER_AUTH_KEY')]);
  95. unset($_SESSION['administrator']);
  96. $this->assign("jumpUrl",__URL__.'/login/');
  97. $this->success('?????');
  98. }else {
  99. $this->error( '?????');
  100. }
  101. }
  102. /**
  103. +----------------------------------------------------------
  104. * ?????
  105. +----------------------------------------------------------
  106. * @access public
  107. +----------------------------------------------------------
  108. * @return void
  109. +----------------------------------------------------------
  110. * @throws FcsException
  111. +----------------------------------------------------------
  112. */
  113. function verify(){
  114. import("ORG.Util.Image");
  115. Image::showAdvVerify();
  116. }
  117. /**
  118. +----------------------------------------------------------
  119. * ???????????URL??
  120. * ?????????????
  121. * ???action??????
  122. +----------------------------------------------------------
  123. * @access public
  124. +----------------------------------------------------------
  125. * @return string
  126. +----------------------------------------------------------
  127. * @throws ThinkExecption
  128. +----------------------------------------------------------
  129. */
  130. function getReturnUrl()
  131. {
  132. return __URL__.'?'.C('VAR_MODULE').'='.MODULE_NAME.'&'.C('VAR_ACTION').'='.C('DEFAULT_ACTION');
  133. }
  134. /**
  135. +----------------------------------------------------------
  136. * ??????????
  137. * ??????
  138. +----------------------------------------------------------
  139. * @access protected
  140. +----------------------------------------------------------
  141. * @param string $name ??????
  142. +----------------------------------------------------------
  143. * @return HashMap
  144. +----------------------------------------------------------
  145. * @throws ThinkExecption
  146. +----------------------------------------------------------
  147. */
  148. protected function _search($name='')
  149. {
  150. //??????
  151. if(empty($name)) {
  152. $name = $this->name;
  153. }
  154. $model = D($name);
  155. $map = array();
  156. foreach($model->getDbFields() as $key=>$val) {
  157. if(isset($_REQUEST[$val]) && $_REQUEST[$val]!='') {
  158. $map[$val] = $_REQUEST[$val];
  159. }
  160. }
  161. return $map;
  162. }
  163. /**
  164. +----------------------------------------------------------
  165. * ??????????
  166. * ??????
  167. +----------------------------------------------------------
  168. * @access protected
  169. +----------------------------------------------------------
  170. * @param Model $model ????
  171. * @param HashMap $map ????
  172. * @param string $sortBy ??
  173. * @param boolean $asc ????
  174. +----------------------------------------------------------
  175. * @return void
  176. +----------------------------------------------------------
  177. * @throws ThinkExecption
  178. +----------------------------------------------------------
  179. */
  180. protected function _list($model,$map,$sortBy='',$asc=true)
  181. {
  182. //???? ??????
  183. if(isset($_REQUEST['order'])) {
  184. $order = $_REQUEST['order'];
  185. }else {
  186. $order = !empty($sortBy)? $sortBy: $model->getPk();
  187. }
  188. //????????????
  189. //?? sost?? 0 ???? ?0? ????
  190. if(isset($_REQUEST['sort'])) {
  191. $sort = $_REQUEST['sort']?'asc':'desc';
  192. }else {
  193. $sort = $asc?'asc':'desc';
  194. }
  195. //??????????
  196. $count = $model->count($map);
  197. if($count>0) {
  198. import("ORG.Util.Page");
  199. //??????
  200. if(!empty($_REQUEST['listRows'])) {
  201. $listRows = $_REQUEST['listRows'];
  202. }else {
  203. $listRows = '';
  204. }
  205. $p = new Page($count,$listRows);
  206. //??????
  207. $voList = $model->where($map)->order($order.' '.$sort)->limit($p->firstRow.','.$p->listRows)->findAll();
  208. //?????????????
  209. foreach($map as $key=>$val) {
  210. if(is_array($val)) {
  211. foreach ($val as $t){
  212. $p->parameter .= $key.'[]='.urlencode($t)."&";
  213. }
  214. }else{
  215. $p->parameter .= "$key=".urlencode($val)."&";
  216. }
  217. }
  218. //????
  219. $page = $p->show();
  220. //??????
  221. $sortImg = $sort ; //????
  222. $sortAlt = $sort == 'desc'?'????':'????'; //????
  223. $sort = $sort == 'desc'? 1:0; //????
  224. //??????
  225. $this->assign('list', $voList);
  226. $this->assign('sort', $sort);
  227. $this->assign('order', $order);
  228. $this->assign('sortImg', $sortImg);
  229. $this->assign('sortType', $sortAlt);
  230. $this->assign("page", $page);
  231. }
  232. return ;
  233. }
  234. function update() {
  235. $model = D($this->name);
  236. if(false === $vo = $model->create()) {
  237. $this->error($model->getError());
  238. }
  239. $result = $model->save();
  240. if($result) {
  241. //????
  242. $this->success('?????');
  243. }else {
  244. //????
  245. $this->error('?????');
  246. }
  247. }
  248. /**
  249. +----------------------------------------------------------
  250. * ??????
  251. +----------------------------------------------------------
  252. * @access public
  253. +----------------------------------------------------------
  254. * @return string
  255. +----------------------------------------------------------
  256. * @throws ThinkExecption
  257. +----------------------------------------------------------
  258. */
  259. public function delete()
  260. {
  261. //??????
  262. $model = D($this->name);
  263. if(!empty($model)) {
  264. $id = $_REQUEST['id'];
  265. if(isset($id)) {
  266. if($model->delete($id)){
  267. $this->success('?????');
  268. }else {
  269. $this->error('?????');
  270. }
  271. }else {
  272. $this->error('????');
  273. }
  274. }
  275. }
  276. /**
  277. +----------------------------------------------------------
  278. * ??????
  279. *
  280. +----------------------------------------------------------
  281. * @access public
  282. +----------------------------------------------------------
  283. * @return void
  284. +----------------------------------------------------------
  285. * @throws FcsException
  286. +----------------------------------------------------------
  287. */
  288. function sort()
  289. {
  290. $thismodel=$this->name;
  291. $list = D($thismodel);
  292. if(!$_REQUEST['pid']){
  293. $sortList = $list->order('seqNo asc')->findall();
  294. }else{
  295. $sortList = $list->where('pid='.$_REQUEST['pid'])->field('*')->order('seqNo asc')->findall();
  296. }
  297. //dump($sortList);
  298. $this->assign("thismodel",$thismodel);
  299. $this->assign("sortList",$sortList);
  300. $this->display('Public:sort');
  301. return ;
  302. }
  303. /**
  304. +----------------------------------------------------------
  305. * ????????
  306. *
  307. +----------------------------------------------------------
  308. * @access public
  309. +----------------------------------------------------------
  310. * @return void
  311. +----------------------------------------------------------
  312. * @throws FcsException
  313. +----------------------------------------------------------
  314. */
  315. function saveSort()
  316. {
  317. $seqNoList = $_POST['sortvaue'];
  318. if(!empty($seqNoList)) {
  319. //??????
  320. $thismodel=$this->name;
  321. $list = D($thismodel);
  322. $col = explode(',',$seqNoList);
  323. $i=1;
  324. foreach($col as $val) {
  325. $data['id'] =$val;
  326. $data['seqNo'] =$i;
  327. $list->data($data)->save();
  328. $i++;
  329. }
  330. }
  331. }
  332. protected function checkUser() {
  333. if(!isset($_SESSION[C('USER_AUTH_KEY')])) {
  334. $this->assign ('jumpUrl', PHP_FILE . C('USER_AUTH_GATEWAY') );
  335. $this->error('????');
  336. }
  337. }
  338. public function Switchframe(){
  339. //??
  340. $this->display();
  341. }
  342. }
  343. ?>