function synlogin($get, $post) { global $_G; if (!API_SYNLOGIN) { return API_RETURN_FORBIDDEN; } //note 同步登录 API 接口 header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"'); $cookietime = 31536000; $uid = intval($get['uid']); $query = DB::query("SELECT uid, username, password FROM " . DB::table('common_member') . " WHERE uid='{$uid}'"); if ($member = DB::fetch($query)) { dsetcookie('auth', authcode("{$member['password']}\t{$member['uid']}", 'ENCODE'), $cookietime); } elseif (!empty($_G['setting']['autoactivationuser'])) { //自动激活 require_once libfile('function/login'); $result = autoactivationuser($uid); if ($result) { setloginstatus($result, $cookietime); } } }
/** * 登陆函数 * @return 登录状态 * 1 = 成功, 2 = 成功自动激活,0 = 失败 */ function userlogin($username, $password, $questionid, $answer, $loginfield = 'username') { $return = array(); if ($loginfield == 'uid') { $isuid = 1; } elseif ($loginfield == 'email') { $isuid = 2; } elseif ($loginfield == 'auto') { $isuid = 3; } else { $isuid = 0; } if (!function_exists('uc_user_login')) { loaducenter(); } if ($isuid == 3) { if (preg_match('/^[1-9]\\d*$/', $username)) { //note username 为uid的可能性很大 $return['ucresult'] = uc_user_login($username, $password, 1, 1, $questionid, $answer); } elseif (isemail($username)) { //note username 为email的可能性很大 $return['ucresult'] = uc_user_login($username, $password, 2, 1, $questionid, $answer); } if ($return['ucresult'][0] <= 0) { //note 验证失败,尝试使用 username 方式登录 $return['ucresult'] = uc_user_login($username, $password, 0, 1, $questionid, $answer); } } else { $return['ucresult'] = uc_user_login($username, $password, $isuid, 1, $questionid, $answer); } list($tmp['uid'], $tmp['username'], $tmp['password'], $tmp['email'], $duplicate) = daddslashes($return['ucresult'], 1); $return['ucresult'] = $tmp; $return['ucresult']['uid'] = intval($return['ucresult']['uid']); if ($duplicate && $return['ucresult']['uid'] > 0) { if ($olduid = DB::result_first("SELECT uid FROM " . DB::table('common_member') . " WHERE username='******'ucresult']['username']) . "'")) { require_once libfile('function/membermerge'); membermerge($olduid, $return['ucresult']['uid']); uc_user_merge_remove($return['ucresult']['username']); } else { $return['status'] = 0; return $return; } } if ($return['ucresult']['uid'] <= 0) { $return['status'] = 0; return $return; } $member = DB::fetch_first("SELECT * FROM " . DB::table('common_member') . " WHERE uid='" . $return['ucresult']['uid'] . "'"); if (!$member) { //自动激活 $return['member'] = autoactivationuser($return['ucresult']['uid']); if ($return['member']) { $return['status'] = 2; } return $return; } $return['member'] = $member; $return['status'] = 1; if (addslashes($member['email']) != $return['ucresult']['email']) { DB::query("UPDATE " . DB::table('common_member') . " SET email='" . $return['ucresult']['email'] . "' WHERE uid='" . $return['ucresult']['uid'] . "'"); } return $return; }