Ejemplo n.º 1
0
 /**
  * UC登录或者注册
  * @param string $username
  * @param string $password
  * @param string $is_remember_me 是否记住登录
  * @return bool 
  */
 private function ucLogin($username, $password, $is_remember_me)
 {
     //载入UC客户端SDK
     include_once SITE_PATH . '/api/uc_client/client.php';
     //1. 获取UC信息.
     if ($this->isValidEmail($username)) {
         $use_email = true;
         $uc_login_type = 2;
     } else {
         $use_email = false;
         $uc_login_type = 0;
     }
     $uc_user = uc_user_login($username, $password, $uc_login_type);
     //2. 已经同步过的直接登录
     $uc_user_ref = ts_get_ucenter_user_ref('', $uc_user['0'], '');
     if ($uc_user_ref['uid'] && $uc_user_ref['uc_uid'] && $uc_user[0] > 0) {
         //登录本地帐号
         $result = $uc_user_ref['uid'] > 0 ? $this->_recordLogin($uc_user_ref['uid'], $is_remember_me) : false;
         if ($result) {
             $this->success .= uc_user_synlogin($uc_user[0]);
             return true;
         } else {
             $this->error = '登录失败,请重试';
             return false;
         }
     }
     //3. 关联表无、获取本地帐号信息.
     $ts_user = $this->getLocalUser($username, $password);
     // 调试用-写log
     // $log_message = "============================ \n "
     // 				.date('Y-m-d H:i:s')." \n ".$_SERVER['REQUEST_URI']." \n "
     // 				.var_export($uc_user,true)." \n "
     // 				.var_export($ts_user,true)." \n "
     // 				.var_export($uc_user_ref,true)." \n ";
     // $log_file = SITE_PATH."/ts_uc_log.txt";
     // $result = error_log($log_message,3,$log_file);
     //4. 关联表无、UC有、本地有的
     if ($uc_user[0] > 0 && $ts_user['uid'] > 0) {
         $result = ts_add_ucenter_user_ref($ts_user['uid'], $uc_user[0], $uc_user[1], $uc_user[3]);
         if (!$result) {
             $this->error = '用户不存在或密码错误';
             return false;
         }
         //登录本地帐号
         $result = $this->_recordLogin($ts_user['uid'], $is_remember_me);
         if ($result) {
             $this->success .= uc_user_synlogin($uc_user[0]);
             return true;
         } else {
             $this->error = '登录失败,请重试';
             return false;
         }
     }
     //5. 关联表无、UC有、本地无的
     if ($uc_user[0] > 0 && !$ts_user['uid']) {
         //写入本地系统
         $login_salt = rand(11111, 99999);
         $map['uname'] = $uc_user[1];
         $map['sex'] = 1;
         $map['login_salt'] = $login_salt;
         $map['password'] = md5(md5($uc_user[2]) . $login_salt);
         $map['login'] = $map['email'] = $uc_user[3];
         $map['reg_ip'] = get_client_ip();
         $map['ctime'] = time();
         $map['is_audit'] = 1;
         $map['is_active'] = 1;
         $map['first_letter'] = getFirstLetter($uname);
         //如果包含中文将中文翻译成拼音
         if (preg_match('/[\\x7f-\\xff]+/', $map['uname'])) {
             //昵称和呢称拼音保存到搜索字段
             $map['search_key'] = $map['uname'] . ' ' . model('PinYin')->Pinyin($map['uname']);
         } else {
             $map['search_key'] = $map['uname'];
         }
         $ts_uid = model('User')->add($map);
         if (!$ts_uid) {
             $this->error = '本地用户注册失败,请联系管理员';
             return false;
         }
         //写入关联表
         $result = ts_add_ucenter_user_ref($ts_uid, $uc_user[0], $uc_user[1], $uc_user[3]);
         if (!$result) {
             $this->error = '用户不存在或密码错误';
             return false;
         }
         // 添加至默认的用户组
         $registerConfig = model('Xdata')->get('admin_Config:register');
         $userGroup = empty($registerConfig['default_user_group']) ? C('DEFAULT_GROUP_ID') : $registerConfig['default_user_group'];
         model('UserGroupLink')->domoveUsergroup($ts_uid, implode(',', $userGroup));
         // 添加双向关注用户
         $eachFollow = $registerConfig['each_follow'];
         if (!empty($eachFollow)) {
             model('Follow')->eachDoFollow($ts_uid, $eachFollow);
         }
         // 添加默认关注用户
         $defaultFollow = $registerConfig['default_follow'];
         $defaultFollow = array_diff(explode(',', $defaultFollow), explode(',', $eachFollow));
         if (!empty($defaultFollow)) {
             model('Follow')->bulkDoFollow($ts_uid, $defaultFollow);
         }
         //登录本地帐号
         $result = $this->_recordLogin($ts_uid, $is_remember_me);
         if ($result) {
             $this->success .= uc_user_synlogin($uc_user[0]);
             return true;
         } else {
             $this->error = '登录失败,请重试';
             return false;
         }
     }
     //6. 关联表无、UC无、本地有
     if ($uc_user[0] < 0 && $ts_user['uid'] > 0) {
         //写入UC
         $uc_uid = uc_user_register($ts_user['uname'], $password, $ts_user['email'], '', '', get_client_ip());
         if ($uc_uid > 0) {
             $this->error = 'UC帐号注册失败,请联系管理员';
             return false;
         }
         //写入关联表
         $result = ts_add_ucenter_user_ref($ts_user['uid'], $uc_uid, $ts_user['uname'], $ts_user['email']);
         if (!$result) {
             $this->error = '用户不存在或密码错误';
             return false;
         }
         //登录本地帐号
         $result = $this->_recordLogin($ts_user['uid'], $is_remember_me);
         if ($result) {
             $this->success .= uc_user_synlogin($uc_uid);
             return true;
         } else {
             $this->error = '登录失败,请重试';
             return false;
         }
     }
     //7. 关联表无、UC无、本地无的
     $this->error = '用户不存在';
     return false;
 }
 /**
  * uc登陆或者注册。返回数组
  * $result['user'] 用户信息。用于ts系统使用
  * $result['login'] 同步登陆是否成功
  * @param unknown_type $username
  * @param unknown_type $password
  */
 public function ucLogin($username, $password)
 {
     if (isValidEmail($username)) {
         $user = service('Passport')->getLocalUser($username, $password);
         if (UC_SYNC && $user['uid']) {
             $uc_user_ref = ts_get_ucenter_user_ref($user['uid']);
             if ($uc_user_ref['uc_uid']) {
                 $uc_user = uc_user_login($uc_user_ref['uc_uid'], $password, 1);
                 if ($uc_user[0] == -1 || $uc_user[0] == -2) {
                     $uc_user_ref = array();
                 }
             } else {
                 if ($user['uname']) {
                     $res_checkname = uc_user_checkname($user['uname']);
                     if ($res_checkname >= -3 && $res_checkname <= -1) {
                         $error_param = L('username');
                     }
                     $res_checkemail = uc_user_checkemail($username);
                     if ($res_checkemail >= -6 && $res_checkemail <= -4) {
                         $error_param = $error_param ? $error_param . L('and_email') : 'Email';
                     }
                     if ($error_param) {
                         $message_data['title'] = L('sync_ucenter') . $error_param . L('sign_in_failed');
                         $message_data['content'] = L('you_of_site') . $error_param . L('ucenter_sign_in_failed') . $error_param . L('ucenter_clash') . U('home/Account/security') . L('ucenter_reset') . $error_param . '。';
                         $message_data['to'] = $user['uid'];
                         model('Message')->postMessage($message_data, M('user')->getField('uid', 'admin_level=1'));
                     } else {
                         $uc_uid = uc_user_register($user['uname'], $password, $username);
                         ts_add_ucenter_user_ref($user['uid'], $uc_uid, $user['uname']);
                         $uc_user[0] = $uc_uid;
                     }
                 }
             }
         }
     } else {
         if (UC_SYNC) {
             $uc_user = uc_user_login($username, $password);
             if ($uc_user[0] > 0) {
                 $uc_user_ref = ts_get_ucenter_user_ref('', $uc_user[0]);
                 if (!$uc_user_ref) {
                     // 注册
                     if ($this->isValidEmail($uc_user['3']) && $this->isEmailAvailable($uc_user['3'])) {
                         $user['email'] = $uc_user['3'];
                     } else {
                         $message_data['title'] = L('ucenter_sync_email_clash');
                         $message_data['content'] = L('ucenter_email_used') . U('home/Account/bind') . L('ucenter_reset_email');
                     }
                     if (isLegalUsername($uc_user['1']) && !M('user')->where("uname='{$uc_user['1']}'")->count()) {
                         $user['uname'] = $uc_user['1'];
                     }
                     $user['password'] = md5($uc_user['2']);
                     $user['ctime'] = time();
                     $user['is_active'] = 1;
                     $user['uid'] = M('user')->add($user);
                     if ($user['uid']) {
                         $reg_from_ucenter = 1;
                         ts_add_ucenter_user_ref($user['uid'], $uc_user['0'], $uc_user['1']);
                         // 将用户添加到myop_userlog,以使漫游应用能获取到用户信息
                         $userlog = array('uid' => $user['uid'], 'action' => 'add', 'type' => '0', 'dateline' => time());
                         M('myop_userlog')->add($userlog);
                         if (isset($message_data) && !empty($message_data)) {
                             $message_data['to'] = $user['uid'];
                             model('Message')->postMessage($message_data, M('user')->getField('uid', 'admin_level=1'));
                         }
                         //关联操作
                         //$this->registerRelation($user['uid']);
                     } else {
                         $user = array();
                     }
                 } else {
                     if ($username != $uc_user_ref['uc_username']) {
                         ts_update_ucenter_user_ref('', $uc_user_ref['uc_uid'], $username);
                     }
                     $user = M('user')->where("uid={$uc_user_ref['uid']}")->find();
                     if (md5($password) != $user['password']) {
                         M('user')->where("uid={$uc_user_ref['uid']}")->setField('password', md5($password));
                     }
                 }
             }
         } else {
             $uc_user_ref = ts_get_ucenter_user_ref('', '', $username);
             if ($uc_user_ref['uid']) {
                 $user = service('Passport')->getLocalUser($uc_user_ref['uid'], $password);
             }
         }
     }
     $result['login'] = '';
     if ($user) {
         $result['login'] = UC_SYNC && $uc_user[0] ? uc_user_synlogin($uc_user[0]) : '';
     }
     $result['user'] = $user;
     $result['reg_from_ucenter'] = $reg_from_ucenter;
     return $result;
 }
Ejemplo n.º 3
0
 function updatepw($get, $post)
 {
     if (!API_UPDATEPW) {
         return API_RETURN_FORBIDDEN;
     }
     $uc_username = uc_auto_charset($get['username']);
     $password = $get['password'];
     $uc_user_ref = ts_get_ucenter_user_ref('', '', $uc_username);
     M('user')->where("uid={$uc_user_ref['uid']}")->setField('password', md5($password));
     return API_RETURN_SUCCEED;
 }
Ejemplo n.º 4
0
 public function synlogin($get, $post)
 {
     if (!API_SYNLOGIN) {
         return API_RETURN_FORBIDDEN;
     }
     header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
     $uc_uid = $get['uid'];
     $uc_uname = uc_auto_charset($get['username']);
     $uc_password = $get['password'];
     $uc_user_ref = ts_get_ucenter_user_ref('', $uc_uid);
     $user = ts_get_user($uc_user_ref['uid']);
     if ($user) {
         //检查是否激活,未激活用户不自动登录
         if ($user['is_active'] == 0) {
             exit;
         }
         if ($uc_uname != $uc_user_ref['uc_username']) {
             ts_update_ucenter_user_ref($uc_user_ref['uid'], $uc_uid, $uc_uname);
         }
         //登录到TS系统
         $user['login_from_dz'] = true;
         $result = ts_synclogin($user);
     }
 }
 public function doModifyUCenter()
 {
     include_once SITE_PATH . '/api/uc_client/uc_sync.php';
     if (UC_SYNC) {
         $uc_user_ref = ts_get_ucenter_user_ref($this->mid);
         if (!$uc_user_ref) {
             $username = $_POST['username'];
             $email = $_POST['email'];
             $password = $_POST['password'];
             if (uc_user_checkname($username) != 1 || !isLegalUsername($username) || M('user')->where("uname='{$username}' AND uid<>{$this->mid}")->count()) {
                 $this->error('Tên tài khoản không hợp lệ hoặc đã tồn tại, hãy nhập lại');
             }
             if (uc_user_checkemail($email) != 1 || M('user')->where("uname='{$email}' AND uid<>{$this->mid}")->count()) {
                 $this->error('Email không hợp lệ hoặc đã tồn tại, hãy nhập lại');
             }
             global $ts;
             if (md5($password) != $ts['user']['password']) {
                 $this->error(L('password_error_retype'));
             }
             $uc_uid = uc_user_register($username, $password, $email);
             if ($uc_uid > 0) {
                 ts_add_ucenter_user_ref($this->mid, $uc_uid, $username);
                 $this->assign('jumpUrl', U('home/Account/security'));
                 $this->success(L('ucenter_setting_success'));
             } else {
                 $this->error(L('ucenter_setting_error'));
             }
         } else {
             redirect(U('home/Account/security'));
         }
     } else {
         redirect(U('home/Account/security'));
     }
 }