PageRenderTime 58ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/code/apps/home/Lib/Action/PublicAction.class.php

http://thinksns-2.googlecode.com/
PHP | 945 lines | 701 code | 143 blank | 101 comment | 133 complexity | b4abcf7f4002656a0bf1368512b9ce55 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. class PublicAction extends Action{
  3. public function _initialize() {
  4. }
  5. public function adminlogin() {
  6. if ( service('Passport')->isLoggedAdmin() ) {
  7. redirect(U('admin/Index/index'));
  8. }
  9. $this->display();
  10. }
  11. public function doAdminLogin() {
  12. // ?????
  13. if ( md5($_POST['verify']) != $_SESSION['verify'] ) {
  14. $this->error('?????');
  15. }
  16. // ????
  17. if ( empty($_POST['password']) ) {
  18. $this->error('??????');
  19. }
  20. if ( isset($_POST['email']) && ! isValidEmail($_POST['email']) ) {
  21. $this->error('email????');
  22. }
  23. // ????/??
  24. $is_logged = false;
  25. if ( isset($_POST['email']) ) {
  26. $is_logged = service('Passport')->loginAdmin(NULL, $_POST['email'], $_POST['password']);
  27. }else if ( $this->mid > 0 ) {
  28. $is_logged = service('Passport')->loginAdmin($this->mid, NULL, $_POST['password']);
  29. }else {
  30. $this->error('????');
  31. }
  32. // ?????????
  33. $this->assign('isAdmin','1');
  34. if ($is_logged) {
  35. $this->assign('jumpUrl', U('admin/Index/index'));
  36. $this->success('????');
  37. }else {
  38. $this->assign('jumpUrl', U('home/Public/adminlogin'));
  39. $this->error('????');
  40. }
  41. }
  42. public function login() {
  43. // ???
  44. if ( service('Passport')->isLogged() ) {
  45. U('home/Space/index','',true);
  46. }
  47. unset($_SESSION['sina'], $_SESSION['key'], $_SESSION['douban'], $_SESSION['open_platform_type']);
  48. //???
  49. $opt_verify = model('Xdata')->lget('siteopt');
  50. $opt_verify = $opt_verify['site_verify'];
  51. $opt_verify = in_array('login', $opt_verify);
  52. if ($opt_verify) {
  53. $this->assign('register_verify_on', 1);
  54. }
  55. $data['email'] = t($_REQUEST['email']);
  56. $data['uid'] = t($_REQUEST['uid']);
  57. $data['list'] = D('Operate','weibo')->getIndex(3);
  58. // ????
  59. include_once SITE_PATH.'/addons/plugins/login/douban.class.php';
  60. $douban = new douban();
  61. $this->assign('doubanurl', $douban->getUrl());
  62. // ????
  63. include_once( SITE_PATH.'/addons/plugins/login/sina.class.php' );
  64. $sina = new sina();
  65. $this->assign('sinaurl',$sina->getUrl());
  66. $this->assign($data);
  67. $this->assign('regInfo',model('Xdata')->lget('register'));
  68. $this->display();
  69. }
  70. //??????
  71. public function otherlogin(){
  72. if ( !in_array($_SESSION['open_platform_type'], array('sina', 'douban')) ) {
  73. $this->error('????');
  74. }
  75. $type = $_SESSION['open_platform_type'];
  76. include_once( SITE_PATH."/addons/plugins/login/{$type}.class.php" );
  77. $platform = new $type();
  78. $userinfo = $platform->userInfo();
  79. // ????????????
  80. if ( !is_numeric($userinfo['id']) || !is_string($userinfo['uname']) ) {
  81. $this->assign('jumpUrl', SITE_URL);
  82. $this->error('????????');
  83. }
  84. if ( $info = M('login')->where("type_uid=".$userinfo['id']." AND type='{$type}'")->find() ) {
  85. $user = M('user')->where("uid=".$info['uid'])->find();
  86. if (empty($user)) {
  87. // ??????????, ????????,???????
  88. M('login')->where("type_uid=".$userinfo['id']." AND type='{$type}'")->delete();
  89. }else {
  90. if ( $info['oauth_token'] == '' ) {
  91. $syncdata['login_id'] = $info['login_id'];
  92. $syncdata['oauth_token'] = $_SESSION[$type]['access_token']['oauth_token'];
  93. $syncdata['oauth_token_secret'] = $_SESSION[$type]['access_token']['oauth_token_secret'];
  94. M('login')->save($syncdata);
  95. }
  96. $this->setSessionAndCookie($user['uid'], $user['uname'], '', FALSE );
  97. $this->recordLogin($user['uid']);
  98. redirect(U('home/User/index'));
  99. }
  100. }
  101. $this->assign('user',$userinfo);
  102. $this->assign('type',$type);
  103. $this->display();
  104. }
  105. // ??????
  106. public function initotherlogin(){
  107. if ( ! in_array($_POST['type'], array('douban','sina')) ) {
  108. $this->error('????');
  109. }
  110. $type = $_POST['type'];
  111. include_once( SITE_PATH."/addons/plugins/login/{$type}.class.php" );
  112. $platform = new $type();
  113. $userinfo = $platform->userInfo();
  114. // ????????????
  115. if ( !is_numeric($userinfo['id']) || !is_string($userinfo['uname']) ) {
  116. $this->assign('jumpUrl', SITE_URL);
  117. $this->error('????????');
  118. }
  119. // ?????????
  120. $map['type_uid'] = $userinfo['id'];
  121. $map['type'] = $type;
  122. if ( ($local_uid = M('login')->where($map)->getField('uid')) && (M('user')->where('uid='.$local_uid)->find()) ) {
  123. $this->assign('jumpUrl', SITE_URL);
  124. $this->success('???????');
  125. }
  126. // ???????, ????
  127. $data['uname'] = $userinfo['uname'];
  128. $data['province'] = intval($userinfo['province']);
  129. $data['city'] = intval($userinfo['city']);
  130. $data['location'] = $userinfo['location'];
  131. $data['sex'] = intval($userinfo['sex']);
  132. $data['is_active'] = 1;
  133. $data['is_init'] = 1;
  134. $data['is_synchronizing'] = ($type == 'sina') ? '1' : '0'; // ????????. ??????????
  135. if ( $id = M('user')->add($data) ) {
  136. // ????????
  137. $syncdata['uid'] = $id;
  138. $syncdata['type_uid'] = $userinfo['id'];
  139. $syncdata['type'] = $type;
  140. $syncdata['oauth_token'] = $_SESSION[$type]['access_token']['oauth_token'];
  141. $syncdata['oauth_token_secret'] = $_SESSION[$type]['access_token']['oauth_token_secret'];
  142. M('login')->add($syncdata);
  143. //????
  144. D('Avatar')->saveAvatar($id,$userinfo['userface']);
  145. // ??????myop_userlog???????????????
  146. $userlog = array(
  147. 'uid' => $id,
  148. 'action' => 'add',
  149. 'type' => '0',
  150. 'dateline' => time(),
  151. );
  152. M('myop_userlog')->add($userlog);
  153. $this->recordLogin($id);
  154. $this->setSessionAndCookie($id, $data['uname'], '', FALSE );
  155. $this->registerRelation($id);
  156. redirect( U('home/public/followuser') );
  157. }else{
  158. $this->error('????????');
  159. }
  160. }
  161. public function bindaccount() {
  162. if ( ! in_array($_POST['type'], array('douban','sina')) ) {
  163. $this->error('????');
  164. }
  165. $psd = ($_POST['passwd']) ? $_POST['passwd'] : true;
  166. $type = $_POST['type'];
  167. if ( $user = service('Passport')->getLocalUser($_POST['email'], $psd) ) {
  168. include_once( SITE_PATH."/addons/plugins/login/{$type}.class.php" );
  169. $platform = new $type();
  170. $userinfo = $platform->userInfo();
  171. // ????????????
  172. if ( !is_numeric($userinfo['id']) || !is_string($userinfo['uname']) ) {
  173. $this->assign('jumpUrl', SITE_URL);
  174. $this->error('????????');
  175. }
  176. // ?????????
  177. $map['type_uid'] = $userinfo['id'];
  178. $map['type'] = $type;
  179. if ( ($local_uid = M('login')->where($map)->getField('uid')) && (M('user')->where('uid='.$local_uid)->find()) ) {
  180. $this->assign('jumpUrl', SITE_URL);
  181. $this->success('???????');
  182. }
  183. $syncdata['uid'] = $user['uid'];
  184. $syncdata['type_uid'] = $userinfo['id'];
  185. $syncdata['type'] = $type;
  186. if ( M('login')->add($syncdata) ) {
  187. $this->setSessionAndCookie($user['uid'], $user['uname'], '', FALSE );
  188. $this->recordLogin($user['uid']);
  189. $this->assign('jumpUrl', U('home/User/index'));
  190. $this->success('????');
  191. }else {
  192. $this->assign('jumpUrl', SITE_URL);
  193. $this->error('????');
  194. }
  195. }else {
  196. $this->error('??????');
  197. }
  198. }
  199. //
  200. public function callback(){
  201. include_once( SITE_PATH.'/addons/plugins/login/sina.class.php' );
  202. $sina = new sina();
  203. $sina->checkUser();
  204. redirect(U('home/public/otherlogin'));
  205. }
  206. public function doubanCallback() {
  207. if ( !isset($_GET['oauth_token']) ) {
  208. $this->error('Error: No oauth_token detected.');
  209. exit;
  210. }
  211. require_once SITE_PATH . '/addons/plugins/login/douban.class.php';
  212. $douban = new douban();
  213. if ( $douban->checkUser($_GET['oauth_token']) ) {
  214. redirect(U('home/Public/otherlogin'));
  215. }else {
  216. $this->assign('jumpUrl', SITE_URL);
  217. $this->error('????');
  218. }
  219. }
  220. public function doLogin($username = '', $password = '') {
  221. //?????
  222. $opt_verify = model('Xdata')->lget('siteopt');
  223. $opt_verify = $opt_verify['site_verify'];
  224. $opt_verify = in_array('login', $opt_verify);
  225. if ($opt_verify && md5($_POST['verify'])!=$_SESSION['verify']) {
  226. $this->error('?????');
  227. }
  228. $username = empty($username) ? $_POST['email'] : $username;
  229. $password = empty($password) ? $_POST['password'] : $password;
  230. if(!$password){
  231. $this->error('?????');
  232. }
  233. $passport = service('Passport');
  234. $user = $passport->getLocalUser($username,$password);
  235. if($user) {
  236. //??????
  237. if ($user['is_active'] == 0) {
  238. redirect(U('home/public/login',array('t'=>'unactive','email'=>$username,'uid'=>$user['uid'])));
  239. exit;
  240. /**
  241. //????Email??
  242. $opt_email_activate = model('Xdata')->lget('register');
  243. $opt_email_activate = $opt_email_activate['register_email_activate'];
  244. if ($opt_email_activate == 1) {
  245. $this->activate($user['uid'], $user['email'], '', 1);
  246. exit;
  247. }else {
  248. //????
  249. $map['uid'] = $user['uid'];
  250. M('user')->where($map)->setField('is_active', 1);
  251. }
  252. **/
  253. }
  254. $this->setSessionAndCookie($user['uid'], $user['uname'], $user['email'], intval($_POST['remember']) === 1);
  255. $this->recordLogin($user['uid']);
  256. //?????????url
  257. if ( $_SESSION['refer_url'] != '' ) {
  258. $refer_url = $_SESSION['refer_url'];
  259. unset($_SESSION['refer_url']);
  260. }else {
  261. $refer_url = U('home/User/index');
  262. }
  263. $this->assign('jumpUrl',$refer_url);
  264. $this->success($username.' ????');
  265. }else {
  266. $this->error('????');
  267. }
  268. }
  269. public function logout() {
  270. service('Passport')->logoutLocal();
  271. $this->assign('jumpUrl',U('home/index'));
  272. $this->success('????');
  273. }
  274. public function logoutAdmin() {
  275. // ?????????
  276. $this->assign('isAdmin','1');
  277. service('Passport')->logoutLocal();
  278. $this->assign('jumpUrl',U('home/Public/adminlogin'));
  279. $this->success('????');
  280. }
  281. public function register() {
  282. //????????
  283. $opt_register = model('Xdata')->lget('register');
  284. $opt_register = $opt_register['register_type'];
  285. if ( $opt_register === 'closed' ) {
  286. $this->error('??????????');
  287. } else if ( $opt_register === 'invite' ) {
  288. // if ( empty($_GET['validationid']) || empty($_GET['validationcode']) ) {
  289. // $this->error('???????????????????????????');
  290. // }else if ( ! $invite = service('Validation')->getValidation() ) {
  291. // $this->error('????????');
  292. // }
  293. $invite = h($_REQUEST['invite']);
  294. $inviteSet = model('Invite')->getSet();
  295. if($inviteSet['invite_set']=='close'){
  296. $this->error('?????????');
  297. }elseif ($inviteSet['invite_set']=='common') {
  298. if ( !$invite ) {
  299. $this->error('???????????????????????????');
  300. }else {
  301. // ?????????(???????ID)
  302. if( ! M('user')->where('`uid`='.intval($invite))->find() ) {
  303. $this->error('????????');
  304. }
  305. }
  306. }elseif ($inviteSet['invite_set']=='invitecode'){
  307. if ( !$invite ) {
  308. $this->error('???????????????????????????');
  309. }else{
  310. $info = model('Invite')->checkInviteCode($invite);
  311. if(!$info){
  312. $this->error('????????');
  313. }
  314. if($info['is_used']==1){
  315. $this->error('???????');
  316. }
  317. $this->assign('inviteinfo',$info);
  318. }
  319. }
  320. }
  321. if ($invite) {
  322. $this->assign('invite', $invite);
  323. }
  324. //???
  325. $opt_verify = model('Xdata')->lget('siteopt');
  326. $opt_verify = $opt_verify['site_verify'];
  327. $opt_verify = in_array('register', $opt_verify);
  328. if ($opt_verify) {
  329. $this->assign('register_verify_on', 1);
  330. }
  331. $this->display();
  332. }
  333. // ????
  334. public function doRegister() {
  335. //$invite = service('Validation')->getValidation();
  336. //????????
  337. $opt_register = model('Xdata')->lget('register');
  338. $opt_register = $opt_register['register_type'];
  339. if ( $opt_register === 'closed' ) {
  340. $this->error('??????????');
  341. } else if ( $opt_register === 'invite' ) {
  342. // if ( empty($_POST['validationid']) || empty($_POST['validationcode']) ) {
  343. // $this->error('???????????????????????????');
  344. // }else if ( !$invite ) {
  345. // $this->error('????????');
  346. // }
  347. $invite = h($_REQUEST['invitecode']);
  348. $inviteSet = model('Invite')->getSet();
  349. if($inviteSet['invite_set']=='close'){
  350. $this->error('????????');
  351. }elseif($inviteSet['invite_set']=='common'){
  352. $inviteinfo['uid'] = $invite;
  353. }else{
  354. $inviteinfo = model('Invite')->checkInviteCode($invite);
  355. if(!$inviteinfo){
  356. $this->error('????????');
  357. }
  358. if($inviteinfo['is_used']==1){
  359. $this->error('???????');
  360. }
  361. }
  362. }
  363. //???????
  364. $required_field = array(
  365. 'email' => 'Email',
  366. 'password' => '??',
  367. 'repassword'=> '??',
  368. );
  369. foreach ($required_field as $k => $v) {
  370. if ( empty($_POST[$k]) ) $this->error($v . '????');
  371. }
  372. //???
  373. $opt_verify = model('Xdata')->lget('siteopt');
  374. $opt_verify = $opt_verify['site_verify'];
  375. $opt_verify = in_array('register', $opt_verify);
  376. if ( $opt_verify && md5($_POST['verify'])!=$_SESSION['verify'] ) {
  377. $this->error('?????');
  378. }
  379. if ( ! $this->isValidEmail($_POST['email']) ) {
  380. $this->error('Email??????????');
  381. }
  382. if( strlen($_POST['password']) < 6 || strlen($_POST['password']) > 16 || $_POST['password'] != $_POST['repassword'] ) {
  383. $this->error('?????6-16?????????');
  384. }
  385. if ( ! $this->isEmailAvailable($_POST['email']) ) {
  386. $this->error('Email???????????');
  387. }
  388. // ????Email??
  389. $opt_email_activate = model('Xdata')->lget('register');
  390. $opt_email_activate = $opt_email_activate['register_email_activate'];
  391. // ??
  392. $_POST['password'] = md5($_POST['password']);
  393. $_POST['ctime'] = time();
  394. $_POST['is_active'] = $opt_email_activate == 1 ? 0 : 1;
  395. $dao = M('user');
  396. $uid = $dao->add($_POST);
  397. if (!$uid) $this->error('?????????????');
  398. // ??????myop_userlog???????????????
  399. $userlog = array(
  400. 'uid' => $uid,
  401. 'action' => 'add',
  402. 'type' => '0',
  403. 'dateline' => time(),
  404. );
  405. M('myop_userlog')->add($userlog);
  406. // ????????
  407. model('Invite')->setInviteCodeUsed($invite);
  408. // ??????
  409. if ( $inviteinfo['uid'] ) {
  410. D('Follow','weibo')->dofollow($uid,$inviteinfo['uid']);
  411. D('Follow','weibo')->dofollow($inviteinfo['uid'],$uid);
  412. //???????
  413. X('Credit')->setUserCredit($inviteinfo['uid'],'invite_friend');
  414. }
  415. // ????
  416. if ( $opt_email_activate == 1 ) {
  417. $this->activate($uid, $_POST['email'], $invite);
  418. }else {
  419. $this->setSessionAndCookie($uid, $_POST['uname'], $_POST['email']);
  420. $this->recordLogin($uid);
  421. // ????
  422. $this->registerRelation($uid, $invite);
  423. //service('Validation')->unsetValidation();
  424. //?????????????
  425. redirect( U('home/public/userinfo') );
  426. }
  427. }
  428. //??????
  429. function userinfo(){
  430. if( $_POST ){
  431. $data['uname'] = t( $_POST['nickname'] );
  432. if(mb_strlen($data['uname'],'UTF8')>10){
  433. $this->error('??????10???');
  434. }
  435. $data['sex'] = intval( $_POST['sex'] );
  436. $data['province'] = intval( $_POST['area_province'] );
  437. $data['city'] = intval( $_POST['area_city'] );
  438. $data['location'] = getLocation($data['province'],$data['city']);
  439. $data['is_init'] = 1;
  440. M('user')->where('uid='.$this->mid)->data($data)->save();
  441. redirect( U('home/public/followuser') );
  442. }else{
  443. $this->display();
  444. }
  445. }
  446. //??????
  447. function followuser(){
  448. if($_POST){
  449. if($_POST['followuid']){
  450. foreach ($_POST['followuid'] as $value){
  451. D('Follow','weibo')->dofollow($this->mid,$value,0);
  452. }
  453. }
  454. if($_POST['doajax']){
  455. echo '1';
  456. }else{
  457. redirect(U('home/user/index'));
  458. }
  459. }else{
  460. //$data['commenduser'] = M('user')->where('is_active=1 AND is_init=1 AND uid<>'.$this->mid)->limit(12)->findall();
  461. $data['commenduser'] = M()->query("SELECT fid,count(uid) as count FROM ts_weibo_follow WHERE fid NOT IN(SELECT fid FROM ts_weibo_follow WHERE uid={$this->mid} AND type=0) AND fid<>{$this->mid} AND type=0 GROUP BY fid ORDER by count(uid) DESC LIMIT 12");
  462. foreach ($data['commenduser'] as $key=>$value){
  463. $data['commenduser'][$key] = M('user')->where('uid='.$value['fid'])->find();
  464. if(!$data['commenduser'][$key]['is_init']) {
  465. unset($data['commenduser'][$key]);
  466. continue;
  467. }
  468. $data['commenduser'][$key]['follower_count'] = $value['count'];
  469. $data['commenduser'][$key]['followstate'] = getFollowState($this->mid, $value['fid']);
  470. }
  471. $this->assign( $data );
  472. $this->display();
  473. }
  474. }
  475. //???????
  476. public function inviteRegister() {
  477. if ( ! $invite = service('Validation')->getValidation() ) {
  478. $this->error('?????');
  479. }
  480. if ( "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"] != $invite['target_url'] ) {
  481. $this->error('URL??');
  482. }
  483. $this->assign('invite', $invite);
  484. $invite['data'] = unserialize($invite['data']);
  485. $map['tpl_record_id'] = $invite['data']['tpl_record_id'];
  486. $tpl_record = model('Template')->getTemplateRecordByMap($map, '', 1);
  487. $tpl_record = $tpl_record['data'][0]['data'];
  488. $this->assign('template', $tpl_record);
  489. //??????
  490. $friend = model('Friend')->getFriendList($invite['from_uid'], null, 9);
  491. $this->assign($friend);
  492. $this->display('invite');
  493. }
  494. public function resendEmail() {
  495. $invite = service('Validation')->getValidation();
  496. $this->activate(intval($_GET['uid']), $_GET['email'], $invite, 1);
  497. }
  498. //??????
  499. public function activate($uid, $email, $invite = '', $is_resend = 0) {
  500. //??????
  501. $activate_url = service('Validation')->addValidation($uid, '', U('home/Public/doActivate'), 'register_activate', serialize($invite));
  502. if ($invite) {
  503. $this->assign('invite', $invite);
  504. }
  505. $this->assign('url',$activate_url);
  506. //??????
  507. $body = <<<EOD
  508. ??????!<br>
  509. ?????????????????????<br>
  510. <a href="$activate_url" target='_blank'>$activate_url</a><br/>
  511. ???????????????????????????????????<br/>
  512. ???????????????????????????????????????
  513. EOD;
  514. // ????
  515. global $ts;
  516. $email_sent = service('Mail')->send_email($email, "??{$ts['site']['site_name']}??",$body);
  517. // ????
  518. if ($email_sent) {
  519. $email_info = explode("@", $email);
  520. switch ($email_info[1]) {
  521. case "qq.com" : $email_url = "mail.qq.com";break;
  522. case "163.com" : $email_url = "mail.163.com";break;
  523. case "126.com" : $email_url = "mail.126.com";break;
  524. case "gmail.com" : $email_url = "mail.google.com";break;
  525. default : $email_url = "mail.".$email_info[1];
  526. }
  527. $this->assign("uid",$uid);
  528. $this->assign('email', $email);
  529. $this->assign('is_resend', $is_resend);
  530. $this->assign("email_url",$email_url);
  531. $this->display('activate');
  532. }else {
  533. $this->assign('jumpUrl', U('home/Index/index'));
  534. $this->error('???????????????');
  535. }
  536. }
  537. public function doActivate() {
  538. $invite = service('Validation')->getValidation();
  539. if (!$invite) {
  540. $this->assign('jumpUrl', U('home/Public/register'));
  541. $this->error('??????????????');
  542. }
  543. $uid = $invite['from_uid'];
  544. $user = M('user')->where("`uid`=$uid")->find();
  545. if ($user['is_active'] == 1) {
  546. $this->assign('jumpUrl', U('home/Public/login'));
  547. $this->success('???????');
  548. exit;
  549. } else if ($user['is_active'] == 0) {
  550. //????
  551. $res = M('user')->where("`uid`=$uid")->setField('is_active', 1);
  552. if (!$res) $this->error('???????');
  553. $this->setSessionAndCookie($user['uid'], $user['uname'], $user['email']);
  554. $this->recordLogin($user['uid']);
  555. //????
  556. $this->registerRelation($user['uid'], $invite);
  557. service('Validation')->unsetValidation();
  558. $this->assign('jumpUrl', U('home/Account/index'));
  559. $this->success("???????");
  560. } else {
  561. $this->assign('jumpUrl', U('home/Public/register'));
  562. $this->error('??????????????');
  563. }
  564. }
  565. public function sendPassword() {
  566. $this->display();
  567. }
  568. public function doSendPassword() {
  569. $_POST["email"] = t($_POST["email"]);
  570. if ( !$this->isValidEmail($_POST['email']) )
  571. $this->error('??????');
  572. $user = M("user")->where('`email`="' . $_POST['email'] . '"')->find();
  573. if(!$user) {
  574. $this->error("???????");
  575. }else {
  576. $code = base64_encode( $user["uid"] . "." . md5($user["uid"] . '+' . $user["password"]) );
  577. $url = U('home/Public/resetPassword', array('code'=>$code));
  578. $body = <<<EOD
  579. <strong>{$user["uname"]}????</strong><br/>
  580. ???????????????????<br/>
  581. <a href="$url">$url</a><br/>
  582. ???????????????????????????????????<br/>
  583. ???????????????????????????????????????
  584. EOD;
  585. global $ts;
  586. $email_sent = service('Mail')->send_email($user['email'], "??{$ts['site']['site_name']}??", $body);
  587. if ($email_sent) {
  588. $this->assign('jumpUrl', SITE_URL);
  589. $this->success("???????????$email???????");
  590. }else {
  591. $this->error('???????????????');
  592. }
  593. }
  594. }
  595. public function resetPassword() {
  596. $code = explode('.', base64_decode($_GET['code']));
  597. $user = M('user')->where('`uid`=' . $code[0])->find();
  598. if ( $code[1] == md5($code[0].'+'.$user["password"]) ) {
  599. $this->assign('email',$user["email"]);
  600. $this->assign('code', $_GET['code']);
  601. $this->display();
  602. }else {
  603. $this->error("???????");
  604. }
  605. }
  606. public function doResetPassword() {
  607. if($_POST["password"] != $_POST["repassword"]) {
  608. $this->error("?????????????????");
  609. }
  610. $code = explode('.', base64_decode($_POST['code']));
  611. $user = M('user')->where('`uid`=' . $code[0])->find();
  612. if ( $code[1] == md5($code[0] . '+' . $user["password"]) ) {
  613. $user['password'] = md5($_POST['password']);
  614. $res = M('user')->save($user);
  615. if ($res) {
  616. $this->assign('jumpUrl', U('home/Public/login'));
  617. $this->success('????');
  618. }else {
  619. $this->error('?????????????');
  620. }
  621. }else {
  622. $this->error("????????");
  623. }
  624. }
  625. public function doModifyEmail() {
  626. if ( !$validation = service('Validation')->getValidation() ) {
  627. $this->error('?????');
  628. }
  629. if ( "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"] != $validation['target_url'] ) {
  630. $this->error('URL??');
  631. }
  632. $validation['data'] = unserialize($validation['data']);
  633. $map['uid'] = $validation['from_uid'];
  634. $map['email'] = $validation['data']['oldemail'];
  635. if ( M('user')->where($map)->setField('email', $validation['data']['email']) ) {
  636. service('Validation')->unsetValidation();
  637. service('Passport')->logoutLocal();
  638. $this->assign('jumpUrl', SITE_URL);
  639. $this->success('???Email????????');
  640. }else {
  641. $this->error('??????Email??');
  642. }
  643. }
  644. //??Email??????
  645. public function isValidEmail($email) {
  646. return preg_match("/[_a-zA-Z\d\-\.]+@[_a-zA-Z\d\-]+(\.[_a-zA-Z\d\-]+)+$/i", $email) !== 0;
  647. }
  648. //??Email????
  649. public function isEmailAvailable($email = null) {
  650. $return_type = empty($email) ? 'ajax' : 'return';
  651. $email = empty($email) ? $_POST['email'] : $email;
  652. $res = M('user')->where('`email`="'.$email.'"')->find();
  653. if ( !$res ) {
  654. if ($return_type === 'ajax') echo 'success';
  655. else return true;
  656. }else {
  657. if ($return_type === 'ajax') echo '??????';
  658. else return false;
  659. }
  660. }
  661. //?????????
  662. public function isValidNickName( $name ){
  663. $name = empty($name) ? t($_POST['nickname']) : $name;
  664. $res = M('user')->where("uname='{$name}'")->count();
  665. if ( !$res ) {
  666. echo 'success';
  667. }else {
  668. if ($return_type === 'ajax') echo '?????????';
  669. else return false;
  670. }
  671. }
  672. //???????????ajax?return
  673. public function isValidRealName($name = null, $opt_register = null) {
  674. $return_type = empty($name) ? 'ajax' : 'return';
  675. $name = empty($name) ? t($_POST['uname']) : $name;
  676. $opt_register = empty($opt_register) ? model('Xdata')->lget('register') : $opt_register;
  677. if ($opt_register['register_realname_check'] == 1) {
  678. $lastname = explode(',', $opt_register['register_lastname']);
  679. $res = in_array( substr($name, 0, 3), $lastname ) || in_array( substr($name, 0, 6), $lastname );
  680. }else {
  681. $res = true;
  682. }
  683. if ($res) {
  684. if ($return_type === 'ajax') echo 'success';
  685. else return true;
  686. }else {
  687. if ($return_type === 'ajax') echo 'fail';
  688. else return false;
  689. }
  690. }
  691. public function isValidInviteCode($invitecode) {
  692. return true;
  693. }
  694. //????????Session?Cookie
  695. public function setSessionAndCookie($uid, $uname, $email, $remember = false) {
  696. $_SESSION['mid'] = $uid;
  697. $_SESSION['uname'] = $uname;
  698. $remember ?
  699. cookie('LOGGED_USER',base64_encode('thinksns.'.$uid),(3600*24*365)) :
  700. cookie('LOGGED_USER',base64_encode('thinksns.'.$uid),(3600*2));
  701. }
  702. //????
  703. public function recordLogin($uid) {
  704. $data['uid'] = $uid;
  705. $data['ip'] = get_client_ip();
  706. $data['place'] = convert_ip($data['ip']);
  707. $data['ctime'] = time();
  708. M('login_record')->add($data);
  709. //????
  710. X('Credit')->setUserCredit($uid,'user_login');
  711. }
  712. //???????
  713. public function registerRelation($uid, $invite = '') {
  714. if ( empty($uid) ) return ;
  715. // ???????????????
  716. // ???????
  717. $dao = D('Follow','weibo');
  718. $auto_freind = model('Xdata')->lget('register');
  719. $auto_freind['register_auto_friend'] = explode(',', $auto_freind['register_auto_friend']);
  720. foreach($auto_freind['register_auto_friend'] as $v) {
  721. if ( ($v = intval($v)) <= 0 )
  722. continue ;
  723. $dao->dofollow($v,$uid);
  724. $dao->dofollow($uid,$v);
  725. }
  726. // ???????
  727. // ????
  728. // ??????
  729. $data['uid'] = $uid;
  730. model('Space')->add($data);
  731. //???? ????
  732. X('Credit')->setUserCredit($uid,'init_default');
  733. }
  734. public function verify() {
  735. require_once(SITE_PATH.'/addons/libs/Image.class.php');
  736. require_once(SITE_PATH.'/addons/libs/String.class.php');
  737. Image::buildImageVerify();
  738. }
  739. //????
  740. public function uploadpic(){
  741. if( $_FILES['pic'] ){
  742. //??????
  743. $savePath = $this->getSaveTempPath();
  744. $filename = md5( time().'teste' ).'.'.substr($_FILES['pic']['name'],strpos($_FILES['pic']['name'],'.')+1);
  745. if(@copy($_FILES['pic']['tmp_name'], $savePath.'/'.$filename) || @move_uploaded_file($_FILES['pic']['tmp_name'], $savePath.'/'.$filename))
  746. {
  747. $result['boolen'] = 1;
  748. $result['type_data'] = 'temp/'.$filename;
  749. $result['picurl'] = __UPLOAD__.'/temp/'.$filename;
  750. } else {
  751. $result['boolen'] = 0;
  752. $result['message'] = '????';
  753. }
  754. }else{
  755. $result['boolen'] = 0;
  756. $result['message'] = '????';
  757. }
  758. exit( json_encode( $result ) );
  759. }
  760. //??????
  761. public function getSaveTempPath(){
  762. $savePath = SITE_PATH.'/data/uploads/temp';
  763. if( !file_exists( $savePath ) ) mk_dir( $savePath );
  764. return $savePath;
  765. }
  766. // ????
  767. public function getArea() {
  768. echo json_encode(model('Area')->getAreaTree());
  769. }
  770. /** ?? **/
  771. public function document() {
  772. $list = array();
  773. $detail = array();
  774. $res = M('document')->where('`is_active`=1')->order('`display_order` ASC,`document_id` ASC')->findAll();
  775. // ??content?url?????????
  776. global $ts;
  777. $ids_has_url = array();
  778. foreach($ts['footer_document'] as $v)
  779. if( !empty($v['url']) )
  780. $ids_has_url[] = $v['document_id'];
  781. $_GET['id'] = intval($_GET['id']);
  782. foreach($res as $v) {
  783. // ???content?url?????????
  784. if ( in_array($v['document_id'], $ids_has_url) )
  785. continue ;
  786. $list[] = array('document_id'=>$v['document_id'], 'title'=>$v['title']);
  787. // ???ID???ID????????????url?????????????????
  788. if ( $v['document_id'] == $_GET['id'] || empty($detail) ) {
  789. $v['content'] = htmlspecialchars_decode($v['content']);
  790. $detail = $v;
  791. }
  792. }
  793. unset($res);
  794. $this->assign('detail', $detail);
  795. $this->assign('list', $list);
  796. $this->display();
  797. }
  798. /** ???? **/
  799. public function error404() {
  800. $this->display('404');
  801. }
  802. }