/code/apps/home/Lib/Action/PublicAction.class.php
PHP | 945 lines | 701 code | 143 blank | 101 comment | 133 complexity | b4abcf7f4002656a0bf1368512b9ce55 MD5 | raw file
Possible License(s): LGPL-2.1
- <?php
- class PublicAction extends Action{
-
- public function _initialize() {
-
- }
-
- public function adminlogin() {
- if ( service('Passport')->isLoggedAdmin() ) {
- redirect(U('admin/Index/index'));
- }
-
- $this->display();
- }
-
- public function doAdminLogin() {
- // ?????
- if ( md5($_POST['verify']) != $_SESSION['verify'] ) {
- $this->error('?????');
- }
-
- // ????
- if ( empty($_POST['password']) ) {
- $this->error('??????');
- }
- if ( isset($_POST['email']) && ! isValidEmail($_POST['email']) ) {
- $this->error('email????');
- }
-
- // ????/??
- $is_logged = false;
- if ( isset($_POST['email']) ) {
- $is_logged = service('Passport')->loginAdmin(NULL, $_POST['email'], $_POST['password']);
- }else if ( $this->mid > 0 ) {
- $is_logged = service('Passport')->loginAdmin($this->mid, NULL, $_POST['password']);
- }else {
- $this->error('????');
- }
-
- // ?????????
- $this->assign('isAdmin','1');
-
- if ($is_logged) {
- $this->assign('jumpUrl', U('admin/Index/index'));
- $this->success('????');
- }else {
- $this->assign('jumpUrl', U('home/Public/adminlogin'));
- $this->error('????');
- }
- }
-
- public function login() {
- // ???
- if ( service('Passport')->isLogged() ) {
- U('home/Space/index','',true);
- }
- unset($_SESSION['sina'], $_SESSION['key'], $_SESSION['douban'], $_SESSION['open_platform_type']);
-
- //???
- $opt_verify = model('Xdata')->lget('siteopt');
- $opt_verify = $opt_verify['site_verify'];
- $opt_verify = in_array('login', $opt_verify);
- if ($opt_verify) {
- $this->assign('register_verify_on', 1);
- }
-
- $data['email'] = t($_REQUEST['email']);
- $data['uid'] = t($_REQUEST['uid']);
- $data['list'] = D('Operate','weibo')->getIndex(3);
-
- // ????
- include_once SITE_PATH.'/addons/plugins/login/douban.class.php';
- $douban = new douban();
- $this->assign('doubanurl', $douban->getUrl());
-
- // ????
- include_once( SITE_PATH.'/addons/plugins/login/sina.class.php' );
- $sina = new sina();
- $this->assign('sinaurl',$sina->getUrl());
-
- $this->assign($data);
- $this->assign('regInfo',model('Xdata')->lget('register'));
- $this->display();
- }
-
- //??????
- public function otherlogin(){
- if ( !in_array($_SESSION['open_platform_type'], array('sina', 'douban')) ) {
- $this->error('????');
- }
-
- $type = $_SESSION['open_platform_type'];
- include_once( SITE_PATH."/addons/plugins/login/{$type}.class.php" );
- $platform = new $type();
- $userinfo = $platform->userInfo();
-
- // ????????????
- if ( !is_numeric($userinfo['id']) || !is_string($userinfo['uname']) ) {
- $this->assign('jumpUrl', SITE_URL);
- $this->error('????????');
- }
-
- if ( $info = M('login')->where("type_uid=".$userinfo['id']." AND type='{$type}'")->find() ) {
- $user = M('user')->where("uid=".$info['uid'])->find();
-
- if (empty($user)) {
- // ??????????, ????????,???????
- M('login')->where("type_uid=".$userinfo['id']." AND type='{$type}'")->delete();
- }else {
- if ( $info['oauth_token'] == '' ) {
- $syncdata['login_id'] = $info['login_id'];
- $syncdata['oauth_token'] = $_SESSION[$type]['access_token']['oauth_token'];
- $syncdata['oauth_token_secret'] = $_SESSION[$type]['access_token']['oauth_token_secret'];
- M('login')->save($syncdata);
- }
-
- $this->setSessionAndCookie($user['uid'], $user['uname'], '', FALSE );
- $this->recordLogin($user['uid']);
- redirect(U('home/User/index'));
- }
- }
- $this->assign('user',$userinfo);
- $this->assign('type',$type);
- $this->display();
- }
-
- // ??????
- public function initotherlogin(){
- if ( ! in_array($_POST['type'], array('douban','sina')) ) {
- $this->error('????');
- }
-
- $type = $_POST['type'];
- include_once( SITE_PATH."/addons/plugins/login/{$type}.class.php" );
- $platform = new $type();
- $userinfo = $platform->userInfo();
-
- // ????????????
- if ( !is_numeric($userinfo['id']) || !is_string($userinfo['uname']) ) {
- $this->assign('jumpUrl', SITE_URL);
- $this->error('????????');
- }
-
- // ?????????
- $map['type_uid'] = $userinfo['id'];
- $map['type'] = $type;
- if ( ($local_uid = M('login')->where($map)->getField('uid')) && (M('user')->where('uid='.$local_uid)->find()) ) {
- $this->assign('jumpUrl', SITE_URL);
- $this->success('???????');
- }
-
- // ???????, ????
- $data['uname'] = $userinfo['uname'];
- $data['province'] = intval($userinfo['province']);
- $data['city'] = intval($userinfo['city']);
- $data['location'] = $userinfo['location'];
- $data['sex'] = intval($userinfo['sex']);
- $data['is_active'] = 1;
- $data['is_init'] = 1;
- $data['is_synchronizing'] = ($type == 'sina') ? '1' : '0'; // ????????. ??????????
-
- if ( $id = M('user')->add($data) ) {
- // ????????
- $syncdata['uid'] = $id;
- $syncdata['type_uid'] = $userinfo['id'];
- $syncdata['type'] = $type;
- $syncdata['oauth_token'] = $_SESSION[$type]['access_token']['oauth_token'];
- $syncdata['oauth_token_secret'] = $_SESSION[$type]['access_token']['oauth_token_secret'];
- M('login')->add($syncdata);
-
- //????
- D('Avatar')->saveAvatar($id,$userinfo['userface']);
-
- // ??????myop_userlog???????????????
- $userlog = array(
- 'uid' => $id,
- 'action' => 'add',
- 'type' => '0',
- 'dateline' => time(),
- );
- M('myop_userlog')->add($userlog);
-
- $this->recordLogin($id);
- $this->setSessionAndCookie($id, $data['uname'], '', FALSE );
- $this->registerRelation($id);
-
- redirect( U('home/public/followuser') );
- }else{
- $this->error('????????');
- }
- }
-
- public function bindaccount() {
- if ( ! in_array($_POST['type'], array('douban','sina')) ) {
- $this->error('????');
- }
-
- $psd = ($_POST['passwd']) ? $_POST['passwd'] : true;
- $type = $_POST['type'];
-
- if ( $user = service('Passport')->getLocalUser($_POST['email'], $psd) ) {
- include_once( SITE_PATH."/addons/plugins/login/{$type}.class.php" );
- $platform = new $type();
- $userinfo = $platform->userInfo();
-
- // ????????????
- if ( !is_numeric($userinfo['id']) || !is_string($userinfo['uname']) ) {
- $this->assign('jumpUrl', SITE_URL);
- $this->error('????????');
- }
-
- // ?????????
- $map['type_uid'] = $userinfo['id'];
- $map['type'] = $type;
- if ( ($local_uid = M('login')->where($map)->getField('uid')) && (M('user')->where('uid='.$local_uid)->find()) ) {
- $this->assign('jumpUrl', SITE_URL);
- $this->success('???????');
- }
-
- $syncdata['uid'] = $user['uid'];
- $syncdata['type_uid'] = $userinfo['id'];
- $syncdata['type'] = $type;
- if ( M('login')->add($syncdata) ) {
- $this->setSessionAndCookie($user['uid'], $user['uname'], '', FALSE );
- $this->recordLogin($user['uid']);
- $this->assign('jumpUrl', U('home/User/index'));
- $this->success('????');
-
- }else {
- $this->assign('jumpUrl', SITE_URL);
- $this->error('????');
- }
- }else {
- $this->error('??????');
- }
- }
-
- //
- public function callback(){
- include_once( SITE_PATH.'/addons/plugins/login/sina.class.php' );
- $sina = new sina();
- $sina->checkUser();
- redirect(U('home/public/otherlogin'));
- }
-
- public function doubanCallback() {
- if ( !isset($_GET['oauth_token']) ) {
- $this->error('Error: No oauth_token detected.');
- exit;
- }
- require_once SITE_PATH . '/addons/plugins/login/douban.class.php';
- $douban = new douban();
- if ( $douban->checkUser($_GET['oauth_token']) ) {
- redirect(U('home/Public/otherlogin'));
- }else {
- $this->assign('jumpUrl', SITE_URL);
- $this->error('????');
- }
- }
-
- public function doLogin($username = '', $password = '') {
- //?????
- $opt_verify = model('Xdata')->lget('siteopt');
- $opt_verify = $opt_verify['site_verify'];
- $opt_verify = in_array('login', $opt_verify);
- if ($opt_verify && md5($_POST['verify'])!=$_SESSION['verify']) {
- $this->error('?????');
- }
-
- $username = empty($username) ? $_POST['email'] : $username;
- $password = empty($password) ? $_POST['password'] : $password;
-
- if(!$password){
- $this->error('?????');
- }
- $passport = service('Passport');
- $user = $passport->getLocalUser($username,$password);
-
- if($user) {
- //??????
- if ($user['is_active'] == 0) {
- redirect(U('home/public/login',array('t'=>'unactive','email'=>$username,'uid'=>$user['uid'])));
- exit;
- /**
- //????Email??
- $opt_email_activate = model('Xdata')->lget('register');
- $opt_email_activate = $opt_email_activate['register_email_activate'];
- if ($opt_email_activate == 1) {
- $this->activate($user['uid'], $user['email'], '', 1);
- exit;
- }else {
- //????
- $map['uid'] = $user['uid'];
- M('user')->where($map)->setField('is_active', 1);
- }
- **/
- }
-
- $this->setSessionAndCookie($user['uid'], $user['uname'], $user['email'], intval($_POST['remember']) === 1);
-
- $this->recordLogin($user['uid']);
-
- //?????????url
- if ( $_SESSION['refer_url'] != '' ) {
- $refer_url = $_SESSION['refer_url'];
- unset($_SESSION['refer_url']);
- }else {
- $refer_url = U('home/User/index');
- }
- $this->assign('jumpUrl',$refer_url);
- $this->success($username.' ????');
- }else {
- $this->error('????');
- }
- }
-
- public function logout() {
- service('Passport')->logoutLocal();
- $this->assign('jumpUrl',U('home/index'));
- $this->success('????');
- }
-
- public function logoutAdmin() {
- // ?????????
- $this->assign('isAdmin','1');
-
- service('Passport')->logoutLocal();
- $this->assign('jumpUrl',U('home/Public/adminlogin'));
- $this->success('????');
- }
-
- public function register() {
- //????????
- $opt_register = model('Xdata')->lget('register');
- $opt_register = $opt_register['register_type'];
- if ( $opt_register === 'closed' ) {
- $this->error('??????????');
- } else if ( $opt_register === 'invite' ) {
- // if ( empty($_GET['validationid']) || empty($_GET['validationcode']) ) {
- // $this->error('???????????????????????????');
- // }else if ( ! $invite = service('Validation')->getValidation() ) {
- // $this->error('????????');
- // }
- $invite = h($_REQUEST['invite']);
- $inviteSet = model('Invite')->getSet();
- if($inviteSet['invite_set']=='close'){
- $this->error('?????????');
- }elseif ($inviteSet['invite_set']=='common') {
- if ( !$invite ) {
- $this->error('???????????????????????????');
- }else {
- // ?????????(???????ID)
- if( ! M('user')->where('`uid`='.intval($invite))->find() ) {
- $this->error('????????');
- }
- }
- }elseif ($inviteSet['invite_set']=='invitecode'){
- if ( !$invite ) {
- $this->error('???????????????????????????');
- }else{
- $info = model('Invite')->checkInviteCode($invite);
- if(!$info){
- $this->error('????????');
- }
- if($info['is_used']==1){
- $this->error('???????');
- }
- $this->assign('inviteinfo',$info);
- }
- }
- }
-
- if ($invite) {
- $this->assign('invite', $invite);
- }
-
- //???
- $opt_verify = model('Xdata')->lget('siteopt');
- $opt_verify = $opt_verify['site_verify'];
- $opt_verify = in_array('register', $opt_verify);
- if ($opt_verify) {
- $this->assign('register_verify_on', 1);
- }
-
- $this->display();
- }
-
- // ????
- public function doRegister() {
- //$invite = service('Validation')->getValidation();
-
- //????????
- $opt_register = model('Xdata')->lget('register');
- $opt_register = $opt_register['register_type'];
- if ( $opt_register === 'closed' ) {
- $this->error('??????????');
- } else if ( $opt_register === 'invite' ) {
- // if ( empty($_POST['validationid']) || empty($_POST['validationcode']) ) {
- // $this->error('???????????????????????????');
- // }else if ( !$invite ) {
- // $this->error('????????');
- // }
- $invite = h($_REQUEST['invitecode']);
- $inviteSet = model('Invite')->getSet();
- if($inviteSet['invite_set']=='close'){
- $this->error('????????');
- }elseif($inviteSet['invite_set']=='common'){
- $inviteinfo['uid'] = $invite;
- }else{
- $inviteinfo = model('Invite')->checkInviteCode($invite);
- if(!$inviteinfo){
- $this->error('????????');
- }
- if($inviteinfo['is_used']==1){
- $this->error('???????');
- }
- }
- }
- //???????
- $required_field = array(
- 'email' => 'Email',
- 'password' => '??',
- 'repassword'=> '??',
- );
- foreach ($required_field as $k => $v) {
- if ( empty($_POST[$k]) ) $this->error($v . '????');
- }
-
- //???
- $opt_verify = model('Xdata')->lget('siteopt');
- $opt_verify = $opt_verify['site_verify'];
- $opt_verify = in_array('register', $opt_verify);
- if ( $opt_verify && md5($_POST['verify'])!=$_SESSION['verify'] ) {
- $this->error('?????');
- }
-
- if ( ! $this->isValidEmail($_POST['email']) ) {
- $this->error('Email??????????');
- }
- if( strlen($_POST['password']) < 6 || strlen($_POST['password']) > 16 || $_POST['password'] != $_POST['repassword'] ) {
- $this->error('?????6-16?????????');
- }
- if ( ! $this->isEmailAvailable($_POST['email']) ) {
- $this->error('Email???????????');
- }
-
-
- // ????Email??
- $opt_email_activate = model('Xdata')->lget('register');
- $opt_email_activate = $opt_email_activate['register_email_activate'];
-
- // ??
- $_POST['password'] = md5($_POST['password']);
- $_POST['ctime'] = time();
- $_POST['is_active'] = $opt_email_activate == 1 ? 0 : 1;
- $dao = M('user');
- $uid = $dao->add($_POST);
- if (!$uid) $this->error('?????????????');
-
- // ??????myop_userlog???????????????
- $userlog = array(
- 'uid' => $uid,
- 'action' => 'add',
- 'type' => '0',
- 'dateline' => time(),
- );
- M('myop_userlog')->add($userlog);
-
- // ????????
- model('Invite')->setInviteCodeUsed($invite);
-
- // ??????
- if ( $inviteinfo['uid'] ) {
- D('Follow','weibo')->dofollow($uid,$inviteinfo['uid']);
- D('Follow','weibo')->dofollow($inviteinfo['uid'],$uid);
- //???????
- X('Credit')->setUserCredit($inviteinfo['uid'],'invite_friend');
- }
-
- // ????
- if ( $opt_email_activate == 1 ) {
- $this->activate($uid, $_POST['email'], $invite);
- }else {
-
- $this->setSessionAndCookie($uid, $_POST['uname'], $_POST['email']);
-
- $this->recordLogin($uid);
-
- // ????
- $this->registerRelation($uid, $invite);
-
- //service('Validation')->unsetValidation();
-
- //?????????????
- redirect( U('home/public/userinfo') );
- }
- }
-
- //??????
- function userinfo(){
-
- if( $_POST ){
- $data['uname'] = t( $_POST['nickname'] );
- if(mb_strlen($data['uname'],'UTF8')>10){
- $this->error('??????10???');
- }
- $data['sex'] = intval( $_POST['sex'] );
- $data['province'] = intval( $_POST['area_province'] );
- $data['city'] = intval( $_POST['area_city'] );
- $data['location'] = getLocation($data['province'],$data['city']);
- $data['is_init'] = 1;
- M('user')->where('uid='.$this->mid)->data($data)->save();
- redirect( U('home/public/followuser') );
- }else{
- $this->display();
- }
- }
-
- //??????
- function followuser(){
- if($_POST){
- if($_POST['followuid']){
- foreach ($_POST['followuid'] as $value){
- D('Follow','weibo')->dofollow($this->mid,$value,0);
- }
- }
- if($_POST['doajax']){
- echo '1';
- }else{
- redirect(U('home/user/index'));
- }
- }else{
- //$data['commenduser'] = M('user')->where('is_active=1 AND is_init=1 AND uid<>'.$this->mid)->limit(12)->findall();
- $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");
- foreach ($data['commenduser'] as $key=>$value){
- $data['commenduser'][$key] = M('user')->where('uid='.$value['fid'])->find();
- if(!$data['commenduser'][$key]['is_init']) {
- unset($data['commenduser'][$key]);
- continue;
- }
- $data['commenduser'][$key]['follower_count'] = $value['count'];
- $data['commenduser'][$key]['followstate'] = getFollowState($this->mid, $value['fid']);
- }
- $this->assign( $data );
- $this->display();
- }
- }
-
- //???????
- public function inviteRegister() {
- if ( ! $invite = service('Validation')->getValidation() ) {
- $this->error('?????');
- }
-
- if ( "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"] != $invite['target_url'] ) {
- $this->error('URL??');
- }
- $this->assign('invite', $invite);
-
- $invite['data'] = unserialize($invite['data']);
- $map['tpl_record_id'] = $invite['data']['tpl_record_id'];
- $tpl_record = model('Template')->getTemplateRecordByMap($map, '', 1);
- $tpl_record = $tpl_record['data'][0]['data'];
- $this->assign('template', $tpl_record);
-
- //??????
- $friend = model('Friend')->getFriendList($invite['from_uid'], null, 9);
- $this->assign($friend);
-
- $this->display('invite');
- }
-
- public function resendEmail() {
- $invite = service('Validation')->getValidation();
- $this->activate(intval($_GET['uid']), $_GET['email'], $invite, 1);
- }
-
- //??????
- public function activate($uid, $email, $invite = '', $is_resend = 0) {
- //??????
- $activate_url = service('Validation')->addValidation($uid, '', U('home/Public/doActivate'), 'register_activate', serialize($invite));
- if ($invite) {
- $this->assign('invite', $invite);
- }
- $this->assign('url',$activate_url);
-
- //??????
- $body = <<<EOD
- ??????!<br>
-
- ?????????????????????<br>
-
- <a href="$activate_url" target='_blank'>$activate_url</a><br/>
-
- ???????????????????????????????????<br/>
-
- ???????????????????????????????????????
- EOD;
- // ????
- global $ts;
- $email_sent = service('Mail')->send_email($email, "??{$ts['site']['site_name']}??",$body);
-
- // ????
- if ($email_sent) {
- $email_info = explode("@", $email);
- switch ($email_info[1]) {
- case "qq.com" : $email_url = "mail.qq.com";break;
- case "163.com" : $email_url = "mail.163.com";break;
- case "126.com" : $email_url = "mail.126.com";break;
- case "gmail.com" : $email_url = "mail.google.com";break;
- default : $email_url = "mail.".$email_info[1];
- }
-
- $this->assign("uid",$uid);
- $this->assign('email', $email);
- $this->assign('is_resend', $is_resend);
- $this->assign("email_url",$email_url);
- $this->display('activate');
- }else {
- $this->assign('jumpUrl', U('home/Index/index'));
- $this->error('???????????????');
- }
- }
-
- public function doActivate() {
- $invite = service('Validation')->getValidation();
- if (!$invite) {
- $this->assign('jumpUrl', U('home/Public/register'));
- $this->error('??????????????');
- }
- $uid = $invite['from_uid'];
-
- $user = M('user')->where("`uid`=$uid")->find();
- if ($user['is_active'] == 1) {
- $this->assign('jumpUrl', U('home/Public/login'));
- $this->success('???????');
- exit;
- } else if ($user['is_active'] == 0) {
- //????
- $res = M('user')->where("`uid`=$uid")->setField('is_active', 1);
- if (!$res) $this->error('???????');
-
- $this->setSessionAndCookie($user['uid'], $user['uname'], $user['email']);
-
- $this->recordLogin($user['uid']);
-
- //????
- $this->registerRelation($user['uid'], $invite);
-
- service('Validation')->unsetValidation();
-
- $this->assign('jumpUrl', U('home/Account/index'));
- $this->success("???????");
- } else {
- $this->assign('jumpUrl', U('home/Public/register'));
- $this->error('??????????????');
- }
- }
-
- public function sendPassword() {
- $this->display();
- }
-
- public function doSendPassword() {
- $_POST["email"] = t($_POST["email"]);
- if ( !$this->isValidEmail($_POST['email']) )
- $this->error('??????');
-
- $user = M("user")->where('`email`="' . $_POST['email'] . '"')->find();
-
- if(!$user) {
- $this->error("???????");
- }else {
- $code = base64_encode( $user["uid"] . "." . md5($user["uid"] . '+' . $user["password"]) );
- $url = U('home/Public/resetPassword', array('code'=>$code));
- $body = <<<EOD
- <strong>{$user["uname"]}????</strong><br/>
-
- ???????????????????<br/>
-
- <a href="$url">$url</a><br/>
-
- ???????????????????????????????????<br/>
-
- ???????????????????????????????????????
- EOD;
-
- global $ts;
- $email_sent = service('Mail')->send_email($user['email'], "??{$ts['site']['site_name']}??", $body);
-
- if ($email_sent) {
- $this->assign('jumpUrl', SITE_URL);
- $this->success("???????????$email???????");
- }else {
- $this->error('???????????????');
- }
- }
- }
-
- public function resetPassword() {
- $code = explode('.', base64_decode($_GET['code']));
- $user = M('user')->where('`uid`=' . $code[0])->find();
-
- if ( $code[1] == md5($code[0].'+'.$user["password"]) ) {
- $this->assign('email',$user["email"]);
- $this->assign('code', $_GET['code']);
- $this->display();
- }else {
- $this->error("???????");
- }
- }
-
- public function doResetPassword() {
- if($_POST["password"] != $_POST["repassword"]) {
- $this->error("?????????????????");
- }
-
- $code = explode('.', base64_decode($_POST['code']));
- $user = M('user')->where('`uid`=' . $code[0])->find();
-
- if ( $code[1] == md5($code[0] . '+' . $user["password"]) ) {
- $user['password'] = md5($_POST['password']);
- $res = M('user')->save($user);
- if ($res) {
- $this->assign('jumpUrl', U('home/Public/login'));
- $this->success('????');
- }else {
- $this->error('?????????????');
- }
- }else {
- $this->error("????????");
- }
- }
-
- public function doModifyEmail() {
- if ( !$validation = service('Validation')->getValidation() ) {
- $this->error('?????');
- }
- if ( "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"] != $validation['target_url'] ) {
- $this->error('URL??');
- }
-
- $validation['data'] = unserialize($validation['data']);
- $map['uid'] = $validation['from_uid'];
- $map['email'] = $validation['data']['oldemail'];
- if ( M('user')->where($map)->setField('email', $validation['data']['email']) ) {
- service('Validation')->unsetValidation();
- service('Passport')->logoutLocal();
- $this->assign('jumpUrl', SITE_URL);
- $this->success('???Email????????');
- }else {
- $this->error('??????Email??');
- }
- }
-
- //??Email??????
- public function isValidEmail($email) {
- return preg_match("/[_a-zA-Z\d\-\.]+@[_a-zA-Z\d\-]+(\.[_a-zA-Z\d\-]+)+$/i", $email) !== 0;
- }
-
- //??Email????
- public function isEmailAvailable($email = null) {
- $return_type = empty($email) ? 'ajax' : 'return';
- $email = empty($email) ? $_POST['email'] : $email;
-
- $res = M('user')->where('`email`="'.$email.'"')->find();
-
- if ( !$res ) {
- if ($return_type === 'ajax') echo 'success';
- else return true;
- }else {
- if ($return_type === 'ajax') echo '??????';
- else return false;
- }
- }
-
- //?????????
-
- public function isValidNickName( $name ){
- $name = empty($name) ? t($_POST['nickname']) : $name;
- $res = M('user')->where("uname='{$name}'")->count();
- if ( !$res ) {
- echo 'success';
- }else {
- if ($return_type === 'ajax') echo '?????????';
- else return false;
- }
- }
-
- //???????????ajax?return
- public function isValidRealName($name = null, $opt_register = null) {
- $return_type = empty($name) ? 'ajax' : 'return';
- $name = empty($name) ? t($_POST['uname']) : $name;
- $opt_register = empty($opt_register) ? model('Xdata')->lget('register') : $opt_register;
-
- if ($opt_register['register_realname_check'] == 1) {
- $lastname = explode(',', $opt_register['register_lastname']);
- $res = in_array( substr($name, 0, 3), $lastname ) || in_array( substr($name, 0, 6), $lastname );
- }else {
- $res = true;
- }
-
- if ($res) {
- if ($return_type === 'ajax') echo 'success';
- else return true;
- }else {
- if ($return_type === 'ajax') echo 'fail';
- else return false;
- }
- }
-
- public function isValidInviteCode($invitecode) {
- return true;
- }
-
- //????????Session?Cookie
- public function setSessionAndCookie($uid, $uname, $email, $remember = false) {
- $_SESSION['mid'] = $uid;
- $_SESSION['uname'] = $uname;
- $remember ?
- cookie('LOGGED_USER',base64_encode('thinksns.'.$uid),(3600*24*365)) :
- cookie('LOGGED_USER',base64_encode('thinksns.'.$uid),(3600*2));
- }
-
- //????
- public function recordLogin($uid) {
- $data['uid'] = $uid;
- $data['ip'] = get_client_ip();
- $data['place'] = convert_ip($data['ip']);
- $data['ctime'] = time();
- M('login_record')->add($data);
- //????
- X('Credit')->setUserCredit($uid,'user_login');
- }
-
- //???????
- public function registerRelation($uid, $invite = '') {
- if ( empty($uid) ) return ;
-
- // ???????????????
-
- // ???????
- $dao = D('Follow','weibo');
- $auto_freind = model('Xdata')->lget('register');
- $auto_freind['register_auto_friend'] = explode(',', $auto_freind['register_auto_friend']);
- foreach($auto_freind['register_auto_friend'] as $v) {
- if ( ($v = intval($v)) <= 0 )
- continue ;
- $dao->dofollow($v,$uid);
- $dao->dofollow($uid,$v);
- }
-
- // ???????
-
- // ????
-
- // ??????
- $data['uid'] = $uid;
- model('Space')->add($data);
-
- //???? ????
- X('Credit')->setUserCredit($uid,'init_default');
- }
-
- public function verify() {
- require_once(SITE_PATH.'/addons/libs/Image.class.php');
- require_once(SITE_PATH.'/addons/libs/String.class.php');
- Image::buildImageVerify();
- }
-
- //????
- public function uploadpic(){
- if( $_FILES['pic'] ){
- //??????
- $savePath = $this->getSaveTempPath();
- $filename = md5( time().'teste' ).'.'.substr($_FILES['pic']['name'],strpos($_FILES['pic']['name'],'.')+1);
- if(@copy($_FILES['pic']['tmp_name'], $savePath.'/'.$filename) || @move_uploaded_file($_FILES['pic']['tmp_name'], $savePath.'/'.$filename))
- {
- $result['boolen'] = 1;
- $result['type_data'] = 'temp/'.$filename;
- $result['picurl'] = __UPLOAD__.'/temp/'.$filename;
- } else {
- $result['boolen'] = 0;
- $result['message'] = '????';
- }
- }else{
- $result['boolen'] = 0;
- $result['message'] = '????';
- }
-
- exit( json_encode( $result ) );
- }
-
- //??????
- public function getSaveTempPath(){
- $savePath = SITE_PATH.'/data/uploads/temp';
- if( !file_exists( $savePath ) ) mk_dir( $savePath );
- return $savePath;
- }
-
- // ????
- public function getArea() {
- echo json_encode(model('Area')->getAreaTree());
- }
-
- /** ?? **/
- public function document() {
- $list = array();
- $detail = array();
- $res = M('document')->where('`is_active`=1')->order('`display_order` ASC,`document_id` ASC')->findAll();
-
- // ??content?url?????????
- global $ts;
- $ids_has_url = array();
- foreach($ts['footer_document'] as $v)
- if( !empty($v['url']) )
- $ids_has_url[] = $v['document_id'];
-
- $_GET['id'] = intval($_GET['id']);
-
- foreach($res as $v) {
- // ???content?url?????????
- if ( in_array($v['document_id'], $ids_has_url) )
- continue ;
-
- $list[] = array('document_id'=>$v['document_id'], 'title'=>$v['title']);
-
- // ???ID???ID????????????url?????????????????
- if ( $v['document_id'] == $_GET['id'] || empty($detail) ) {
- $v['content'] = htmlspecialchars_decode($v['content']);
- $detail = $v;
- }
- }
- unset($res);
-
- $this->assign('detail', $detail);
- $this->assign('list', $list);
- $this->display();
- }
-
- /** ???? **/
- public function error404() {
- $this->display('404');
- }
- }