PageRenderTime 46ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://thinksns-2.googlecode.com/
PHP | 416 lines | 326 code | 56 blank | 34 comment | 52 complexity | e4b3dde3069f23c7779810509b4356e5 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * ??????
  4. * @author Nonant
  5. *
  6. */
  7. class AccountAction extends Action{
  8. var $pUser;
  9. function _initialize(){
  10. $this->pUser = D('UserProfile');
  11. $this->pUser->uid = $this->mid;
  12. // ?????????
  13. $is_domain_on = model('Xdata')->lget('siteopt');
  14. $is_domain_on = $is_domain_on['site_user_domain_on'];
  15. $menu[] = array( 'url' => 'index', 'name' => '????' );
  16. $menu[] = array( 'url' => 'privacy', 'name' => '????' );
  17. if ($is_domain_on == 1)
  18. $menu[] = array( 'url' => 'domain', 'name' => '?????' );
  19. $menu[] = array( 'url' => 'security', 'name' => '????' );
  20. $menu[] = array( 'url' => 'medal', 'name' => '????');
  21. $menu[] = array( 'url' => 'bind', 'name' => '????' );
  22. $menu[] = array( 'url' => 'credit', 'name' => '????' );
  23. $this->assign('accountmenu',$menu);
  24. }
  25. //????
  26. function index(){
  27. $data['userInfo'] = $this->pUser->getUserInfo();
  28. $data['userTag'] = D('UserTag')->getUserTagList($this->mid);
  29. $data['userFavTag'] = D('UserTag')->getFavTageList($this->mid);
  30. $this->assign( $data );
  31. $this->display();
  32. }
  33. //????
  34. function update(){
  35. exit( json_encode($this->pUser->upDate( t($_REQUEST['dotype']) )) );
  36. }
  37. //????
  38. function bind(){
  39. $sinabind = M('login')->where('type="sina" AND uid='.$this->mid)->findall();
  40. $data['sina'] = $sinabind;
  41. $user = M('user')->where('uid='.$this->mid)->field('email')->find();
  42. $replace = substr($user['email'],2,-3);
  43. for ($i=1;$i<=strlen($replace);$i++){
  44. $replacestring.='*';
  45. }
  46. $data['email'] = str_replace( $replace, $replacestring ,$user['email'] );
  47. $this->assign($data);
  48. $this->display();
  49. }
  50. //???????
  51. function addproject(){
  52. $pUserProfile = D('UserProfile');
  53. $pUserProfile->uid = $this->mid;
  54. $strType = t( $_POST['addtype'] );
  55. if( $strType =='education' ){
  56. $data['school'] = t($_POST['school']);
  57. $data['classes'] = t($_POST['classes']);
  58. $data['year'] = t($_POST['year']);
  59. if( empty( $data['school'] ) ){
  60. $return['message'] = '????????';
  61. $return['boolen'] = "0";
  62. exit( json_encode($return) );
  63. }
  64. }elseif ($strType == 'career' ){
  65. $data['company'] = t($_POST['company']);
  66. $data['position'] = t($_POST['position']);
  67. $data['begintime'] = intval( $_POST['beginyear'] ).'-'.intval($_POST['beginmonth']);
  68. $data['endtime'] = ( $_POST['nowworkflag'] ) ? '??' : intval( $_POST['endyear'] ).'-'.intval($_POST['endmonth']);
  69. if( empty( $data['company'] ) ){
  70. $return['message'] = '????????';
  71. $return['boolen'] = "0";
  72. exit( json_encode($return) );
  73. }
  74. }
  75. $data['id'] = $pUserProfile->dosave($strType,$data,'list',true);
  76. if($data['id']){
  77. $data['addtype'] = $strType;
  78. $return['message'] = '????????';
  79. $return['boolen'] = "1";
  80. $return['data'] = $data;
  81. exit( json_encode($return) );
  82. }
  83. }
  84. //????
  85. function doUserTag(){
  86. $strType = h($_REQUEST['type']);
  87. if($strType=='addByname'){
  88. $_POST['tagname'] = str_replace('?', ',', $_POST['tagname']);
  89. echo D('UserTag')->addUserTagByName( $_POST['tagname'] ,$this->mid);
  90. }elseif ($strType=='deltag'){
  91. echo D('UserTag')->doDel(intval($_POST['tagid']),$this->mid);
  92. }elseif ($strType=='addByid'){
  93. echo D('UserTag')->addUserTagById( $_POST['tagid'] ,$this->mid);
  94. }
  95. }
  96. //????
  97. function avatar(){
  98. $type = $_REQUEST['t'];
  99. $pAvatar = D('Avatar');
  100. $pAvatar ->uid = $this->mid;
  101. if( $type == 'upload' ){
  102. echo $pAvatar->upload();
  103. }elseif ( $type == 'save'){
  104. $pAvatar->dosave($this->mid);
  105. }elseif ( $type == 'camera'){
  106. $pAvatar->getcamera();
  107. }else{
  108. $this->display();
  109. }
  110. }
  111. //??
  112. public function invite() {
  113. if($_POST){
  114. if( model('Invite')->getReceiveCode( $this->mid ) ){
  115. $this->assign('jumpUrl',U('home/Account/invite'));
  116. $this->success('???????');
  117. redirect( U('home/Account/invite') );
  118. }else{
  119. $this->error('???????');
  120. }
  121. }else{
  122. $invitecode = model('Invite')->getInviteCode( $this->mid );
  123. $receivecount = model('Invite')->getReceiveCount( $this->mid );
  124. $this->assign('receivecount',$receivecount);
  125. $this->assign('list',$invitecode);
  126. $this->display();
  127. }
  128. }
  129. public function doInvite() {
  130. $_POST['email'] = t($_POST['email']);
  131. if ( !isValidEmail($_POST['email']) ) {
  132. echo -1; //???Email??
  133. return ;
  134. }
  135. $map['email'] = $_POST['email'];
  136. $map['is_active'] = 1;
  137. if ( $user = M('user')->where($map)->find() ) {
  138. echo $user['id']; //???????
  139. return ;
  140. }
  141. unset($map);
  142. //?????? ?1
  143. $validation = service('Validation')->addValidation($this->mid, $_POST['email'], U('home/Public/inviteRegister'), 'test_invite');
  144. if (!$validation) {
  145. echo 0;
  146. return ;
  147. }
  148. //??????
  149. global $ts;
  150. $data['title'] = array(
  151. 'actor_name' => $ts['user']['uname'],
  152. 'site_name' => $ts['site']['site_name'],
  153. );
  154. $data['body'] = array(
  155. 'email' => $_POST['email'],
  156. 'actor' => '<a href="' . U('home/Space/index',array('uid'=>$ts['user']['uid'])) . '" target="_blank">' . $ts['user']['uname'] . '</a>',
  157. 'site' => '<a href="' . U('home') . '" target="_blank">' . $ts['site']['site_name'] . '</a>',
  158. );
  159. $tpl_record = model('Template')->parseTemplate('invite_register', $data);
  160. unset($data);
  161. if ($tpl_record) {
  162. //echo -2; //????
  163. //?????? ?2
  164. $map['target_url'] = $validation;
  165. M('validation')->where($map)->setField('data', serialize(array('tpl_record_id'=>$tpl_record)));
  166. echo $validation;
  167. }else {
  168. echo 0;
  169. }
  170. }
  171. //????????
  172. public function inviteExisted() {
  173. $this->assign('uid', intval($_GET['uid']));
  174. $this->display();
  175. }
  176. //????
  177. function delprofile(){
  178. $intId = intval( $_REQUEST['id'] );
  179. $pUserProfile = D('UserProfile');
  180. echo $pUserProfile->delprofile( $intId ,$this->mid );
  181. }
  182. //????
  183. public function security() {
  184. $this->display();
  185. }
  186. //????
  187. function privacy(){
  188. if($_POST){
  189. $r = D('UserPrivacy')->dosave($_POST['userset'],$this->mid);
  190. }
  191. $userSet = D('UserPrivacy')->getUserSet($this->mid);
  192. $blacklist = D('UserPrivacy')->getBlackList($this->mid);
  193. $this->assign('userset',$userSet );
  194. $this->assign('blacklist',$blacklist );
  195. $this->display();
  196. }
  197. //?????
  198. function setBlackList(){
  199. if( D("UserPrivacy")->setBlackList( $this->mid , t($_POST['type']) , intval($_POST['uid']) ) ){
  200. echo '1';
  201. }else{
  202. echo '0';
  203. }
  204. }
  205. //?????
  206. function domain(){
  207. // ?????????
  208. $is_domain_on = model('Xdata')->lget('siteopt');
  209. if ($is_domain_on['site_user_domain_on'] != 1)
  210. $this->error('????????');
  211. if($_POST){
  212. $domain = h($_POST['domain']);
  213. if( !ereg('^[a-zA-Z]*$', $domain)){
  214. $this->error('?????????');
  215. }
  216. if( strlen($domain)<2 ){
  217. $this->error('?????1???');
  218. }
  219. if( strlen($domain)>20 ){
  220. $this->error('?????20???');
  221. }
  222. if( M('user')->where("uid!={$this->mid} AND domain='{$domain}'")->count()){
  223. $this->error('?????');
  224. }else{
  225. M('user')->setField('domain',$domain,'uid='.$this->mid);
  226. $this->success('????');
  227. }
  228. }else{
  229. $user = M('user')->where('uid='.$this->mid)->find();
  230. $data['userDomain'] = $user['domain'];
  231. $this->assign($data);
  232. $this->display();
  233. }
  234. }
  235. //????
  236. public function doModifyPassword() {
  237. if( strlen($_POST['password']) < 6 || strlen($_POST['password']) > 16 || $_POST['password'] != $_POST['repassword'] ) {
  238. $this->error('?????6-16?????????');
  239. }
  240. if ($_POST['password'] == $_POST['oldpassword']) {
  241. $this->error('?????????????');
  242. }
  243. $dao = M('user');
  244. $_POST['oldpassword'] = md5($_POST['oldpassword']);
  245. $map['uid'] = $this->mid;
  246. $map['password'] = $_POST['oldpassword'];
  247. if ( $dao->where($map)->find() ) {
  248. $_POST['password'] = md5($_POST['password']);
  249. if ( $dao->where($map)->setField('password', $_POST['password']) ) {
  250. $this->success('????');
  251. }else {
  252. $this->error('???????');
  253. }
  254. }else {
  255. $this->error('??????');
  256. }
  257. }
  258. //????
  259. public function modifyEmail() {
  260. $_POST['email'] = t($_POST['email']);
  261. $_POST['oldemail'] = t($_POST['oldemail']);
  262. if ( !isValidEmail($_POST['email']) || !isValidEmail($_POST['oldemail']) ) {
  263. echo -1;
  264. return ; //$this->error('Email????');
  265. }
  266. $map['uid'] = $this->mid;
  267. $map['email'] = $_POST['oldemail'];
  268. if ( ! M('user')->where($map)->find() ) {
  269. echo -2;
  270. return ; //??Email??
  271. }
  272. if ( !isEmailAvailable($_POST['email']) ) {
  273. echo -3;
  274. return ; //$this->error('?Emai???');
  275. }
  276. $opt_email_activate = model('Xdata')->lget('register');
  277. // ????????, ??????
  278. if (!$opt_email_activate['register_email_activate']) {
  279. if ( M('user')->where($map)->setField('email', $_POST['email']) ) {
  280. service('Passport')->logoutLocal();
  281. echo 1;
  282. }else {
  283. echo 0;
  284. }
  285. unset($opt_email_activate);
  286. exit;
  287. }
  288. unset($opt_email_activate);
  289. // ????
  290. //????
  291. $data = array('oldemail'=>$_POST['oldemail'], 'email'=>$_POST['email']);
  292. if ( $url = service('Validation')->addValidation($this->mid, '', U('home/Public/doModifyEmail'), 'modify_account', serialize($data)) ) {
  293. // ??????
  294. global $ts;
  295. $body = <<<EOD
  296. <strong>{$ts['user']['uname']}????</strong><br/>
  297. ???????????????????<br/>
  298. <a href="$url">$url</a><br/>
  299. ???????????????????????????????????<br/>
  300. ???????????????????????????????????????
  301. EOD;
  302. if (service('Mail')->send_email($_POST['email'], "??{$ts['site']['site_name']}??", $body)) {
  303. echo '2';
  304. }else {
  305. echo '-4';
  306. }
  307. }else {
  308. echo '0';
  309. }
  310. }
  311. // ????
  312. public function medal() {
  313. $_GET['type'] = $_GET['type'] == 'manage' ? 'manage' : 'my';
  314. if ($_GET['type'] == 'my') {
  315. $data = model('Medal')->getMedalWidgetData($this->mid, false, false);
  316. }else {
  317. $data = model('Medal')->getMedalWidgetData($this->mid, false, true);
  318. }
  319. $this->assign($data);
  320. $this->assign('type', $_GET['type']);
  321. $this->display();
  322. }
  323. public function doMedalManage() {
  324. // medal_manage????????????? :(
  325. if ($_POST['medal_manage'] != '1') {
  326. $this->error('????');
  327. }
  328. $dao = model('Medal');
  329. $_POST['show_ids'] = explode(',', t($_POST['show_ids']));
  330. // ??OR?????????????, ????????(?received_time<=0)????
  331. $show_ids = array();
  332. $hide_ids = array();
  333. $data = model('Medal')->getMedalWidgetData($this->mid, false, true);
  334. foreach ($data['user_medal'] as $v) {
  335. if (in_array($v['medal_id'], $_POST['show_ids'])) {
  336. $show_ids[] = $v['medal_id'];
  337. }else {
  338. $hide_ids[] = $v['medal_id'];
  339. }
  340. }
  341. if ( !empty($show_ids) ) {
  342. $dao->setUserMedalStatus($this->mid, $show_ids, 1);
  343. }
  344. if ( !empty($hide_ids) ) {
  345. $dao->setUserMedalStatus($this->mid, $hide_ids, 0);
  346. }
  347. $this->assign('jumpUrl', U('home/Account/medal', array('type'=>'manage')));
  348. $this->success('????');
  349. }
  350. //????
  351. public function credit(){
  352. $credit = X('Credit');
  353. $credit_type = $credit->getCreditType();
  354. $credit_rules = $credit->getCreditRules();
  355. $this->assign('credit_type',$credit_type);
  356. $this->assign('credit_rules',$credit_rules);
  357. $this->display();
  358. }
  359. }
  360. ?>