/code/apps/home/Lib/Action/AccountAction.class.php
PHP | 416 lines | 326 code | 56 blank | 34 comment | 52 complexity | e4b3dde3069f23c7779810509b4356e5 MD5 | raw file
Possible License(s): LGPL-2.1
- <?php
- /**
- * ??????
- * @author Nonant
- *
- */
-
- class AccountAction extends Action{
-
- var $pUser;
-
- function _initialize(){
- $this->pUser = D('UserProfile');
- $this->pUser->uid = $this->mid;
-
- // ?????????
- $is_domain_on = model('Xdata')->lget('siteopt');
- $is_domain_on = $is_domain_on['site_user_domain_on'];
-
- $menu[] = array( 'url' => 'index', 'name' => '????' );
- $menu[] = array( 'url' => 'privacy', 'name' => '????' );
- if ($is_domain_on == 1)
- $menu[] = array( 'url' => 'domain', 'name' => '?????' );
- $menu[] = array( 'url' => 'security', 'name' => '????' );
- $menu[] = array( 'url' => 'medal', 'name' => '????');
- $menu[] = array( 'url' => 'bind', 'name' => '????' );
- $menu[] = array( 'url' => 'credit', 'name' => '????' );
- $this->assign('accountmenu',$menu);
- }
-
- //????
- function index(){
- $data['userInfo'] = $this->pUser->getUserInfo();
- $data['userTag'] = D('UserTag')->getUserTagList($this->mid);
- $data['userFavTag'] = D('UserTag')->getFavTageList($this->mid);
- $this->assign( $data );
- $this->display();
- }
-
- //????
- function update(){
- exit( json_encode($this->pUser->upDate( t($_REQUEST['dotype']) )) );
- }
-
- //????
- function bind(){
- $sinabind = M('login')->where('type="sina" AND uid='.$this->mid)->findall();
- $data['sina'] = $sinabind;
- $user = M('user')->where('uid='.$this->mid)->field('email')->find();
- $replace = substr($user['email'],2,-3);
- for ($i=1;$i<=strlen($replace);$i++){
- $replacestring.='*';
- }
- $data['email'] = str_replace( $replace, $replacestring ,$user['email'] );
- $this->assign($data);
- $this->display();
- }
-
- //???????
- function addproject(){
- $pUserProfile = D('UserProfile');
- $pUserProfile->uid = $this->mid;
- $strType = t( $_POST['addtype'] );
- if( $strType =='education' ){
- $data['school'] = t($_POST['school']);
- $data['classes'] = t($_POST['classes']);
- $data['year'] = t($_POST['year']);
- if( empty( $data['school'] ) ){
- $return['message'] = '????????';
- $return['boolen'] = "0";
- exit( json_encode($return) );
- }
- }elseif ($strType == 'career' ){
- $data['company'] = t($_POST['company']);
- $data['position'] = t($_POST['position']);
- $data['begintime'] = intval( $_POST['beginyear'] ).'-'.intval($_POST['beginmonth']);
- $data['endtime'] = ( $_POST['nowworkflag'] ) ? '??' : intval( $_POST['endyear'] ).'-'.intval($_POST['endmonth']);
- if( empty( $data['company'] ) ){
- $return['message'] = '????????';
- $return['boolen'] = "0";
- exit( json_encode($return) );
- }
- }
- $data['id'] = $pUserProfile->dosave($strType,$data,'list',true);
- if($data['id']){
- $data['addtype'] = $strType;
- $return['message'] = '????????';
- $return['boolen'] = "1";
- $return['data'] = $data;
- exit( json_encode($return) );
- }
- }
-
- //????
- function doUserTag(){
- $strType = h($_REQUEST['type']);
- if($strType=='addByname'){
- $_POST['tagname'] = str_replace('?', ',', $_POST['tagname']);
- echo D('UserTag')->addUserTagByName( $_POST['tagname'] ,$this->mid);
- }elseif ($strType=='deltag'){
- echo D('UserTag')->doDel(intval($_POST['tagid']),$this->mid);
- }elseif ($strType=='addByid'){
- echo D('UserTag')->addUserTagById( $_POST['tagid'] ,$this->mid);
- }
- }
-
- //????
- function avatar(){
- $type = $_REQUEST['t'];
- $pAvatar = D('Avatar');
- $pAvatar ->uid = $this->mid;
- if( $type == 'upload' ){
- echo $pAvatar->upload();
- }elseif ( $type == 'save'){
- $pAvatar->dosave($this->mid);
- }elseif ( $type == 'camera'){
- $pAvatar->getcamera();
- }else{
- $this->display();
- }
- }
-
- //??
- public function invite() {
- if($_POST){
- if( model('Invite')->getReceiveCode( $this->mid ) ){
- $this->assign('jumpUrl',U('home/Account/invite'));
- $this->success('???????');
- redirect( U('home/Account/invite') );
- }else{
- $this->error('???????');
- }
- }else{
- $invitecode = model('Invite')->getInviteCode( $this->mid );
- $receivecount = model('Invite')->getReceiveCount( $this->mid );
- $this->assign('receivecount',$receivecount);
- $this->assign('list',$invitecode);
- $this->display();
- }
- }
-
- public function doInvite() {
- $_POST['email'] = t($_POST['email']);
- if ( !isValidEmail($_POST['email']) ) {
- echo -1; //???Email??
- return ;
- }
-
- $map['email'] = $_POST['email'];
- $map['is_active'] = 1;
- if ( $user = M('user')->where($map)->find() ) {
- echo $user['id']; //???????
- return ;
- }
- unset($map);
-
- //?????? ?1
- $validation = service('Validation')->addValidation($this->mid, $_POST['email'], U('home/Public/inviteRegister'), 'test_invite');
- if (!$validation) {
- echo 0;
- return ;
- }
-
- //??????
- global $ts;
- $data['title'] = array(
- 'actor_name' => $ts['user']['uname'],
- 'site_name' => $ts['site']['site_name'],
- );
- $data['body'] = array(
- 'email' => $_POST['email'],
- 'actor' => '<a href="' . U('home/Space/index',array('uid'=>$ts['user']['uid'])) . '" target="_blank">' . $ts['user']['uname'] . '</a>',
- 'site' => '<a href="' . U('home') . '" target="_blank">' . $ts['site']['site_name'] . '</a>',
- );
- $tpl_record = model('Template')->parseTemplate('invite_register', $data);
- unset($data);
-
- if ($tpl_record) {
- //echo -2; //????
-
- //?????? ?2
- $map['target_url'] = $validation;
- M('validation')->where($map)->setField('data', serialize(array('tpl_record_id'=>$tpl_record)));
- echo $validation;
- }else {
- echo 0;
- }
- }
-
- //????????
- public function inviteExisted() {
- $this->assign('uid', intval($_GET['uid']));
- $this->display();
- }
-
- //????
- function delprofile(){
- $intId = intval( $_REQUEST['id'] );
- $pUserProfile = D('UserProfile');
- echo $pUserProfile->delprofile( $intId ,$this->mid );
- }
-
- //????
- public function security() {
- $this->display();
- }
-
- //????
- function privacy(){
- if($_POST){
- $r = D('UserPrivacy')->dosave($_POST['userset'],$this->mid);
- }
- $userSet = D('UserPrivacy')->getUserSet($this->mid);
- $blacklist = D('UserPrivacy')->getBlackList($this->mid);
- $this->assign('userset',$userSet );
- $this->assign('blacklist',$blacklist );
- $this->display();
-
- }
-
-
- //?????
- function setBlackList(){
- if( D("UserPrivacy")->setBlackList( $this->mid , t($_POST['type']) , intval($_POST['uid']) ) ){
- echo '1';
- }else{
- echo '0';
- }
- }
-
- //?????
- function domain(){
- // ?????????
- $is_domain_on = model('Xdata')->lget('siteopt');
- if ($is_domain_on['site_user_domain_on'] != 1)
- $this->error('????????');
-
- if($_POST){
- $domain = h($_POST['domain']);
-
- if( !ereg('^[a-zA-Z]*$', $domain)){
- $this->error('?????????');
- }
-
- if( strlen($domain)<2 ){
- $this->error('?????1???');
- }
-
- if( strlen($domain)>20 ){
- $this->error('?????20???');
- }
- if( M('user')->where("uid!={$this->mid} AND domain='{$domain}'")->count()){
- $this->error('?????');
- }else{
- M('user')->setField('domain',$domain,'uid='.$this->mid);
- $this->success('????');
- }
- }else{
- $user = M('user')->where('uid='.$this->mid)->find();
- $data['userDomain'] = $user['domain'];
- $this->assign($data);
- $this->display();
- }
- }
-
- //????
- public function doModifyPassword() {
- if( strlen($_POST['password']) < 6 || strlen($_POST['password']) > 16 || $_POST['password'] != $_POST['repassword'] ) {
- $this->error('?????6-16?????????');
- }
- if ($_POST['password'] == $_POST['oldpassword']) {
- $this->error('?????????????');
- }
-
- $dao = M('user');
- $_POST['oldpassword'] = md5($_POST['oldpassword']);
- $map['uid'] = $this->mid;
- $map['password'] = $_POST['oldpassword'];
- if ( $dao->where($map)->find() ) {
-
- $_POST['password'] = md5($_POST['password']);
- if ( $dao->where($map)->setField('password', $_POST['password']) ) {
- $this->success('????');
- }else {
- $this->error('???????');
- }
-
- }else {
- $this->error('??????');
- }
- }
-
- //????
- public function modifyEmail() {
- $_POST['email'] = t($_POST['email']);
- $_POST['oldemail'] = t($_POST['oldemail']);
- if ( !isValidEmail($_POST['email']) || !isValidEmail($_POST['oldemail']) ) {
- echo -1;
- return ; //$this->error('Email????');
- }
- $map['uid'] = $this->mid;
- $map['email'] = $_POST['oldemail'];
- if ( ! M('user')->where($map)->find() ) {
- echo -2;
- return ; //??Email??
- }
- if ( !isEmailAvailable($_POST['email']) ) {
- echo -3;
- return ; //$this->error('?Emai???');
- }
-
- $opt_email_activate = model('Xdata')->lget('register');
-
- // ????????, ??????
- if (!$opt_email_activate['register_email_activate']) {
- if ( M('user')->where($map)->setField('email', $_POST['email']) ) {
- service('Passport')->logoutLocal();
- echo 1;
- }else {
- echo 0;
- }
- unset($opt_email_activate);
- exit;
- }
-
- unset($opt_email_activate);
-
- // ????
-
- //????
- $data = array('oldemail'=>$_POST['oldemail'], 'email'=>$_POST['email']);
- if ( $url = service('Validation')->addValidation($this->mid, '', U('home/Public/doModifyEmail'), 'modify_account', serialize($data)) ) {
- // ??????
- global $ts;
- $body = <<<EOD
- <strong>{$ts['user']['uname']}????</strong><br/>
-
- ???????????????????<br/>
-
- <a href="$url">$url</a><br/>
-
- ???????????????????????????????????<br/>
-
- ???????????????????????????????????????
- EOD;
-
- if (service('Mail')->send_email($_POST['email'], "??{$ts['site']['site_name']}??", $body)) {
- echo '2';
- }else {
- echo '-4';
- }
-
- }else {
- echo '0';
- }
- }
-
- // ????
- public function medal() {
- $_GET['type'] = $_GET['type'] == 'manage' ? 'manage' : 'my';
-
- if ($_GET['type'] == 'my') {
- $data = model('Medal')->getMedalWidgetData($this->mid, false, false);
- }else {
- $data = model('Medal')->getMedalWidgetData($this->mid, false, true);
- }
-
- $this->assign($data);
- $this->assign('type', $_GET['type']);
- $this->display();
- }
-
- public function doMedalManage() {
- // medal_manage????????????? :(
- if ($_POST['medal_manage'] != '1') {
- $this->error('????');
- }
-
- $dao = model('Medal');
- $_POST['show_ids'] = explode(',', t($_POST['show_ids']));
-
- // ??OR?????????????, ????????(?received_time<=0)????
- $show_ids = array();
- $hide_ids = array();
- $data = model('Medal')->getMedalWidgetData($this->mid, false, true);
- foreach ($data['user_medal'] as $v) {
- if (in_array($v['medal_id'], $_POST['show_ids'])) {
- $show_ids[] = $v['medal_id'];
- }else {
- $hide_ids[] = $v['medal_id'];
- }
- }
-
- if ( !empty($show_ids) ) {
- $dao->setUserMedalStatus($this->mid, $show_ids, 1);
- }
- if ( !empty($hide_ids) ) {
- $dao->setUserMedalStatus($this->mid, $hide_ids, 0);
- }
-
- $this->assign('jumpUrl', U('home/Account/medal', array('type'=>'manage')));
- $this->success('????');
- }
-
- //????
- public function credit(){
- $credit = X('Credit');
- $credit_type = $credit->getCreditType();
- $credit_rules = $credit->getCreditRules();
-
- $this->assign('credit_type',$credit_type);
- $this->assign('credit_rules',$credit_rules);
- $this->display();
- }
- }
- ?>