/** * 认证方法 --using * @param varchar login 手机号或用户名 * @param varchar password 密码 * @return array 状态+提示 */ public function authorize() { $_REQUEST = array_merge($_GET, $_POST); if (!empty($_REQUEST['login']) && !empty($_REQUEST['password'])) { $username = addslashes($_REQUEST['login']); $password = addslashes($_REQUEST['password']); $map = "(phone = '{$username}' or uname='{$username}' or email='{$username}') AND is_del=0"; //根据帐号获取用户信息 $user = model('User')->where($map)->field('uid,password,login_salt,is_audit,is_active')->find(); //判断用户名密码是否正确 if ($user && md5(md5($password) . $user['login_salt']) == $user['password']) { if (model('DisableUser')->isDisableUser($user['uid'])) { return array('status' => 0, 'msg' => '您的帐号被已管理员禁用'); } //如果未激活提示未激活 if ($user['is_audit'] != 1) { return array('status' => 0, 'msg' => '您的帐号尚未通过审核'); } if ($user['is_active'] != 1) { return array('status' => 0, 'msg' => '您的帐号尚未激活,请进入邮箱激活'); } //记录token $data['oauth_token'] = getOAuthToken($user['uid']); $data['oauth_token_secret'] = getOAuthTokenSecret(); $data['uid'] = $user['uid']; $data['user'] = model('User')->getUserInfo($data['uid']); $login = D('')->table(C('DB_PREFIX') . 'login')->where('uid=' . $user['uid'] . " AND type='location'")->find(); if (!$login) { $savedata['type'] = 'location'; $savedata = array_merge($savedata, $data); D('')->table(C('DB_PREFIX') . 'login')->add($savedata); } else { //清除缓存 model('Cache')->rm($login['oauth_token'] . $login['oauth_token_secret']); D('')->table(C('DB_PREFIX') . 'login')->where('uid=' . $user['uid'] . " AND type='location'")->save($data); } //直播用户信息 if ($live_user_info = D('live_user_info')->where(array('uid' => $user['uid']))->find()) { $data['ticket'] = $live_user_info['ticket']; } else { $live_user_info = file_get_contents(SITE_URL . '/api.php?api_version=live&mod=LiveUser&act=postUser&uid=' . $user['uid']); //$live_user_info && $data['ticket'] = $live_user_info['ticket']; $live_user_info = json_decode($live_user_info, true); $live_user_info['status'] == 1 && ($data['ticket'] = $live_user_info['data']['ticket']); } $data['status'] = 1; return $data; } else { return array('status' => 0, 'msg' => '用户名或密码错误'); } } else { return array('status' => 0, 'msg' => '用户名或密码不能为空'); } }
public function ZB_User_Get_AuthByTicket() { $api = t($_REQUEST['api']); $ticket = t($_REQUEST['ticket']); if (!$ticket) { $return = array('code' => '00502', 'message' => '票据丢失了'); exit(json_encode($return)); } $mod = M('live_user_info'); $map = array('ticket' => $ticket); $uid = $mod->where($map)->getField('uid'); if (!$uid) { $return['message'] = '用户不存在'; $return['code'] = '00404'; exit(json_encode($return)); } $hasUser = M('user')->where(array('uid' => $uid))->count(); if (!$hasUser) { $return['message'] = '用户不存在'; $return['code'] = '00404'; exit(json_encode($return)); } $oauth_info = M('login')->where(array('uid' => $uid, 'type' => 'location'))->field('oauth_token_secret,oauth_token')->find(); /* * 此处有坑,暂时不能够判断前端用户是根据什么登录方式拿到的ticket */ if (!$oauth_info) { $data['oauth_token'] = getOAuthToken($uid); $data['oauth_token_secret'] = getOAuthTokenSecret(); $data['uid'] = $uid; $savedata['type'] = 'location'; $savedata = array_merge($savedata, $data); M('login')->add($savedata); $oauth_info['oauth_token'] = $data['oauth_token']; $oauth_info['oauth_token_secret'] = $data['oauth_token_secret']; } foreach ($oauth_info as $key => $value) { $data[] = array('auth_key' => $key, 'auth_value' => $value); } $return['data'] = $data; $return['code'] = '00000'; exit(json_encode($return)); break; }
function authorize() { if ($_POST['uid'] && $_POST['passwd']) { // 杨德升添加 $isIphone = $_REQUEST['isIphone'] === '1'; $username = $isIphone ? $_POST['uid'] : desdecrypt($_POST['uid'], $this->getRequestKey()); if (is_numeric($username)) { $map['uid'] = $username; } elseif (is_string($username)) { $map['email'] = $username; } else { $this->verifyError(); } $map['password'] = $isIphone ? $_POST['passwd'] : md5(desdecrypt($_POST['passwd'], $this->getRequestKey())); $user = M('user')->where($map)->field('uid')->find(); if ($user) { if ($login = M('login')->where("uid=" . $user['uid'] . " AND type='location'")->find()) { $data['oauth_token'] = $login['oauth_token']; $data['oauth_token_secret'] = $login['oauth_token_secret']; $data['uid'] = $user['uid']; } else { $data['oauth_token'] = getOAuthToken($user['uid']); $data['oauth_token_secret'] = getOAuthTokenSecret(); $data['uid'] = $user['uid']; $savedata['type'] = 'location'; $savedata = array_merge($savedata, $data); M('login')->add($savedata); } return $data; } else { $this->verifyError(); } } else { $this->verifyError(); } }
private function _loginSuccessOnClient($local_uid, $type) { if ($login = M('login')->where('uid=' . $local_uid . " AND type='location'")->find()) { $data['oauth_token'] = $login['oauth_token']; $data['oauth_token_secret'] = $login['oauth_token_secret']; $data['uid'] = $local_uid; $data['type'] = 'location'; } else { $data['oauth_token'] = getOAuthToken($local_uid); $data['oauth_token_secret'] = getOAuthTokenSecret(); $data['uid'] = $local_uid; $data['type'] = 'location'; M('login')->add($data); } redirect(Addons::createAddonUrl('Login', 'login_success_on_client', $data)); }
private function createRequestTokenByUID($uid, $api_key, $secret_key) { $map['uname'] = $username; $map['passwd'] = $password; $user = D('User')->where($map)->field('uid')->find(); if ($user) { $data['oauth_token'] = getOAuthToken($user['uid'], $api_key, $secret_key); $data['oauth_code'] = getOAuthCode($user['uid'], $api_key, $secret_key); $data['api_key'] = $api_key; $data['uid'] = $user['uid']; return D('OauthLogin')->add($data); } else { return false; } }
public function getOtherLoginInfo() { $type = addslashes($this->data['type']); $type_uid = addslashes($this->data['type_uid']); $access_token = addslashes($this->data['access_token']); $refresh_token = addslashes($this->data['refresh_token']); $expire = intval($this->data['expire_in']); if (!empty($type) && !empty($type_uid)) { $user = M('login')->where("type_uid='{$type_uid}' AND type='{$type}'")->find(); if ($user && $user['uid'] > 0) { if ($login = M('login')->where("uid=" . $user['uid'] . " AND type='location'")->find()) { $data['oauth_token'] = $login['oauth_token']; $data['oauth_token_secret'] = $login['oauth_token_secret']; $data['uid'] = $login['uid']; } else { $data['oauth_token'] = getOAuthToken($user['uid']); $data['oauth_token_secret'] = getOAuthTokenSecret(); $data['uid'] = $user['uid']; $savedata['type'] = 'location'; $savedata = array_merge($savedata, $data); $result = M('login')->add($savedata); if (!$result) { return -3; } } return $data; } else { return 0; } } else { return 0; } }
/** * 第三方绑定,通过手机号获取用户信息 * */ public function getUserInfoByPhone() { file_put_contents('/tmp/test.log', 'getUserInfoByPhone' . "\n\r", FILE_APPEND); $phone = $_REQUEST['phone']; $code = $this->data['code']; if (empty($code)) { return $this->returnData('', '验证码不能为空', -1); } elseif (!model('Sms')->CheckCaptcha($phone, $code)) { return $this->returnData('', model('Sms')->getMessage(), -1); } //数据中心 判断手机号是否存在 存在返回用户信息 $sCenter_token = $this->getCenterToken(); $sCkurl = C('APIURL') . '/v1/user/mobile-sole?access_token=' . $sCenter_token . '&mobile=' . $phone; $sJson = request_get($sCkurl); file_put_contents('/tmp/test.log', $sJson . "\n\r", FILE_APPEND); $rResult = json_decode($sJson, true); // code=0 该手机号未被注册 if ($rResult['code'] === 0) { return $this->returnData('', '该帐号尚未注册', 0); } $map['is_audit'] = 1; $map['is_active'] = 1; $map['is_init'] = 1; $map['cyj_id'] = $rResult['data']['ret']['open_id']; //数据中心存在而ts不存在的情况 $user = model('User')->where(array('cyj_id' => $map['cyj_id']))->find(); file_put_contents('/tmp/test.log', json_encode($user) . "\n\r", FILE_APPEND); if (empty($user)) { $regmodel = model('Register'); $registerConfig = model('Xdata')->get('admin_Config:register'); //ts开始注册 $database['phone'] = $rResult['data']['ret']['mobile']; $database['uname'] = $rResult['data']['ret']['username']; $database['password'] = $rResult['data']['ret']['password']; $database['login_salt'] = $rResult['data']['ret']['password_salt']; $database['cyj_id'] = $rResult['data']['ret']['open_id']; $database['sex'] = $rResult['data']['ret']['gender'] ? $rResult['data']['ret']['gender'] : 0; $database['ctime'] = time(); $database['is_audit'] = $registerConfig['register_audit'] ? 0 : 1; // $map['is_audit'] = 1; $database['is_active'] = 1; //手机端不需要激活 $database['is_init'] = 1; //手机端不需要初始化步骤 $database['first_letter'] = getFirstLetter($database['uname']); if (preg_match('/[\\x7f-\\xff]+/', $database['uname'])) { //如果包含中文将中文翻译成拼音 $database['search_key'] = $database['uname'] . ' ' . model('PinYin')->Pinyin($database['uname']); } else { $database['search_key'] = $database['uname']; } $uid = model('User')->add($database); // 添加至默认的用户组 $userGroup = empty($registerConfig['default_user_group']) ? C('DEFAULT_GROUP_ID') : $registerConfig['default_user_group']; model('UserGroupLink')->domoveUsergroup($uid, implode(',', $userGroup)); // 添加双向关注用户 $eachFollow = $registerConfig['each_follow']; if (!empty($eachFollow)) { model('Follow')->eachDoFollow($uid, $eachFollow); } // 添加默认关注用户 $defaultFollow = $registerConfig['default_follow']; $defaultFollow = array_diff(explode(',', $defaultFollow), explode(',', $eachFollow)); if (!empty($defaultFollow)) { model('Follow')->bulkDoFollow($uid, $defaultFollow); } } $userInfo = model('User')->getUserInfoByPhone($phone, $map); file_put_contents('/tmp/test.log', json_encode($userInfo) . "\n\r", FILE_APPEND); $rtnData = array(); if ($userInfo) { $rtnData['uid'] = $userInfo['uid']; $rtnData['uname'] = $rResult['data']['ret']['username']; $rtnData['sex'] = $rResult['data']['ret']['gender'] ? $rResult['data']['ret']['gender'] : 0; $rtnData['ctime'] = $userInfo['ctime']; $rtnData['avatar'] = $userInfo['avatar_original']; //$rResult['data']['ret']['avatar']; if ($login = D('')->table(C('DB_PREFIX') . 'login')->where("uid=" . $userInfo['uid'] . " AND type='location'")->find()) { $data['oauth_token'] = $login['oauth_token']; $data['oauth_token_secret'] = $login['oauth_token_secret']; } else { $data['oauth_token'] = getOAuthToken($userInfo['uid']); $data['oauth_token_secret'] = getOAuthTokenSecret(); $savedata['uid'] = $userInfo['uid']; $savedata['type'] = 'location'; $savedata = array_merge($savedata, $data); D('')->table(C('DB_PREFIX') . 'login')->add($savedata); } $rtnData['is_admin'] = isAdmin($rtnData['uid']); $rtnData = array_merge($rtnData, $data); file_put_contents('/tmp/test.log', json_encode($rtnData) . "\n\r", FILE_APPEND); } $msg = $userInfo ? 'ok' : '帐号异常,请找回密码!'; file_put_contents('/tmp/test.log', $msg . "\n\r", FILE_APPEND); $code = $userInfo ? 1 : 0; file_put_contents('/tmp/test.log', json_encode($this->returnData($rtnData, $msg, $code)) . "\n\r", FILE_APPEND); return $this->returnData($rtnData, $msg, $code); }
/** * 绑定第三方帐号,生成新账号 --using * @param varchar uname 用户名 * @param varchar password 密码 * @param varchar type 帐号类型 * @param varchar type_uid 第三方用户标识 * @param varchar access_token 第三方access token * @param varchar refresh_token 第三方refresh token(选填,根据第三方返回值) * @param varchar expire_in 过期时间(选填,根据第三方返回值) */ public function bind_new_user() { $uname = t($this->data['uname']); $password = t($this->data['password']); //用户名验证 if (!model('Register')->isValidName($uname)) { $msg = model('Register')->getLastError(); $return = array('status' => 0, 'msg' => $msg); return $return; } //密码验证 if (!model('Register')->isValidPasswordNoRepeat($password)) { $msg = model('Register')->getLastError(); $return = array('status' => 0, 'msg' => $msg); return $return; } $login_salt = rand(11111, 99999); $map['uname'] = $uname; $map['login_salt'] = $login_salt; $map['password'] = md5(md5($password) . $login_salt); $map['login'] = $uname; $map['ctime'] = time(); $registerConfig = model('Xdata')->get('admin_Config:register'); $map['is_audit'] = $registerConfig['register_audit'] ? 0 : 1; $map['is_active'] = 1; //手机端不需要激活 $map['is_init'] = 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']; } $uid = model('User')->add($map); if ($uid) { //第三方登录数据写入 $other['oauth_token'] = addslashes($this->data['access_token']); $other['oauth_token_secret'] = addslashes($this->data['refresh_token']); $other['type'] = addslashes($this->data['type']); $other['type_uid'] = addslashes($this->data['type_uid']); $other['uid'] = $uid; M('login')->add($other); $data['oauth_token'] = getOAuthToken($uid); $data['oauth_token_secret'] = getOAuthTokenSecret(); $data['uid'] = $uid; $savedata['type'] = 'location'; $savedata = array_merge($savedata, $data); $result = M('login')->add($savedata); // 添加至默认的用户组 $userGroup = empty($registerConfig['default_user_group']) ? C('DEFAULT_GROUP_ID') : $registerConfig['default_user_group']; model('UserGroupLink')->domoveUsergroup($uid, implode(',', $userGroup)); // 添加双向关注用户 $eachFollow = $registerConfig['each_follow']; if (!empty($eachFollow)) { model('Follow')->eachDoFollow($uid, $eachFollow); } // 添加默认关注用户 $defaultFollow = $registerConfig['default_follow']; $defaultFollow = array_diff(explode(',', $defaultFollow), explode(',', $eachFollow)); if (!empty($defaultFollow)) { model('Follow')->bulkDoFollow($uid, $defaultFollow); } return $data; } else { return array('status' => '0', 'msg' => '注册失败'); } }
/** * 绑定第三方帐号,生成新账号 --using * @param varchar uname 用户名 * @param varchar password 密码 * @param varchar type 帐号类型 * @param varchar type_uid 第三方用户标识 * @param varchar access_token 第三方access token * @param varchar refresh_token 第三方refresh token(选填,根据第三方返回值) * @param varchar expire_in 过期时间(选填,根据第三方返回值) */ public function bind_new_user() { $uname = t($this->data['uname']); $password = t($this->data['password']); //用户名验证 if (!model('Register')->isValidName($uname)) { $msg = model('Register')->getLastError(); $return = array('status' => 0, 'msg' => $msg); return $return; } //密码验证 if (!model('Register')->isValidPasswordNoRepeat($password)) { $msg = model('Register')->getLastError(); $return = array('status' => 0, 'msg' => $msg); return $return; } $login_salt = rand(11111, 99999); $map['uname'] = $uname; $map['login_salt'] = $login_salt; $map['password'] = md5(md5($password) . $login_salt); // $map['login'] = $uname; // # 该字段为手机号,有用户名方式和email登陆! $map['ctime'] = time(); $registerConfig = model('Xdata')->get('admin_Config:register'); $map['is_audit'] = $registerConfig['register_audit'] ? 0 : 1; $map['is_active'] = 1; //手机端不需要激活 $map['is_init'] = 1; //手机端不需要初始化步骤 $map['first_letter'] = getFirstLetter($uname); $map['sex'] = $_REQUEST['other_sex'] == '男' ? 1 : 2; if (preg_match('/[\\x7f-\\xff]+/', $map['uname'])) { //如果包含中文将中文翻译成拼音 $map['search_key'] = $map['uname'] . ' ' . model('PinYin')->Pinyin($map['uname']); } else { $map['search_key'] = $map['uname']; } $uid = model('User')->add($map); if ($uid) { //第三方登录数据写入 $other['oauth_token'] = addslashes($this->data['access_token']); $other['oauth_token_secret'] = addslashes($this->data['refresh_token']); $other['type'] = addslashes($this->data['type']); $other['type_uid'] = addslashes($this->data['type_uid']); $other['uid'] = $uid; M('login')->add($other); $data['oauth_token'] = getOAuthToken($uid); $data['oauth_token_secret'] = getOAuthTokenSecret(); $data['uid'] = $uid; $savedata['type'] = 'location'; $savedata = array_merge($savedata, $data); $result = M('login')->add($savedata); //直播用户信息 if ($live_user_info = D('live_user_info')->where(array('uid' => $uid))->find()) { $data['ticket'] = $live_user_info['ticket']; } else { $live_user_info = file_get_contents(SITE_URL . '/api.php?api_version=live&mod=LiveUser&act=postUser&uid=' . $uid); //$live_user_info && $data['ticket'] = $live_user_info['ticket']; $live_user_info = json_decode($live_user_info, true); $live_user_info['status'] == 1 && ($data['ticket'] = $live_user_info['data']['ticket']); } //保存头像 if ($_REQUEST['other_avatar']) { model('Avatar')->saveRemoteAvatar(t($_REQUEST['other_avatar']), $uid); } // 添加至默认的用户组 $userGroup = empty($registerConfig['default_user_group']) ? C('DEFAULT_GROUP_ID') : $registerConfig['default_user_group']; model('UserGroupLink')->domoveUsergroup($uid, implode(',', $userGroup)); // 添加双向关注用户 $eachFollow = $registerConfig['each_follow']; if (!empty($eachFollow)) { model('Follow')->eachDoFollow($uid, $eachFollow); } // 添加默认关注用户 $defaultFollow = $registerConfig['default_follow']; $defaultFollow = array_diff(explode(',', $defaultFollow), explode(',', $eachFollow)); if (!empty($defaultFollow)) { model('Follow')->bulkDoFollow($uid, $defaultFollow); } if ($map['is_audit'] == 1) { return $data; } else { $return = array('status' => 1, 'msg' => '注册成功,请等待审核', 'need_audit' => 1); } } else { return array('status' => 0, 'msg' => '注册失败'); } }
/** * 绑定第三方帐号,生成新账号 --using * @author <*****@*****.**> * @param varchar uname 用户名 * @param varchar password 密码 * @param varchar type 帐号类型 * @param varchar type_uid 第三方用户标识 * @param varchar access_token 第三方access token * @param varchar refresh_token 第三方refresh token(选填,根据第三方返回值) * @param varchar expire_in 过期时间(选填,根据第三方返回值) * * @return array('status' => , 'msg' => ) */ public function bind_new_user2() { $uname = t($this->data['uname']); $password = t($this->data['password']); //用户名验证 if (!model('Register')->isValidName($uname)) { $msg = model('Register')->getLastError(); $return = array('status' => 0, 'msg' => $msg); return $return; } //密码验证 if (!model('Register')->isValidPasswordNoRepeat($password)) { $msg = model('Register')->getLastError(); $return = array('status' => 0, 'msg' => $msg); return $return; } //数据中心开始注册 $access_token = $this->getCenterToken(); $sRurl = C('APIURL') . '/v1/user/register?access_token=' . $access_token; $rCont = array('mobile' => $phone, 'password' => $password, 'reg_channel' => 'ts', 'reg_ip' => get_client_ip(), 'username' => $uname, 'gender' => $sex); $sCenstatus = request_post($sRurl, $rCont); $rRes = json_decode($sCenstatus, true); if ($rRes['code'] !== 0) { $return = array('status' => 0, 'msg' => '注册失败'); return $return; } $map['cyj_id'] = $rRes['data']['ret']['open_id']; $map['password'] = $rRes['data']['ret']['password']; $map['login_salt'] = $rRes['data']['ret']['password_salt']; //$login_salt = rand(111111, 999999); $map['uname'] = $uname; //$map['login_salt'] = $login_salt; //$map['password'] = md5(md5($password).$login_salt); // $map['login'] = $uname; // # 该字段为手机号,有用户名方式和email登陆! $map['ctime'] = time(); $registerConfig = model('Xdata')->get('admin_Config:register'); $map['is_audit'] = $registerConfig['register_audit'] ? 0 : 1; $map['is_active'] = 1; //手机端不需要激活 $map['is_init'] = 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']; } $uid = model('User')->add($map); if ($uid) { //第三方登录数据写入 $other['oauth_token'] = addslashes($this->data['access_token']); $other['oauth_token_secret'] = addslashes($this->data['refresh_token']); $other['type'] = addslashes($this->data['type']); $other['type_uid'] = addslashes($this->data['type_uid']); $other['uid'] = $uid; M('login')->add($other); $data['oauth_token'] = getOAuthToken($uid); $data['oauth_token_secret'] = getOAuthTokenSecret(); $data['uid'] = $uid; $savedata['type'] = 'location'; $savedata = array_merge($savedata, $data); $result = M('login')->add($savedata); // 添加至默认的用户组 $userGroup = empty($registerConfig['default_user_group']) ? C('DEFAULT_GROUP_ID') : $registerConfig['default_user_group']; model('UserGroupLink')->domoveUsergroup($uid, implode(',', $userGroup)); // 添加双向关注用户 $eachFollow = $registerConfig['each_follow']; if (!empty($eachFollow)) { model('Follow')->eachDoFollow($uid, $eachFollow); } // 添加默认关注用户 $defaultFollow = $registerConfig['default_follow']; $defaultFollow = array_diff(explode(',', $defaultFollow), explode(',', $eachFollow)); if (!empty($defaultFollow)) { model('Follow')->bulkDoFollow($uid, $defaultFollow); } if ($map['is_audit'] == 1) { return $data; } else { $return = array('status' => 1, 'msg' => '注册成功,请等待审核', 'need_audit' => 1); } } else { return array('status' => 0, 'msg' => '注册失败'); } }