- if($_G['uid']) showmessage('go_to_home','?m=home');
-
- if( !$_G['setting']['facebook_login'] || !$_G['setting']['facebook_appid'] || !$_G['setting']['facebook_secret'] ) showmessage('web_not_setting_facebook');
-
- require_once ROOT_PATH.'api/facebook_login/facebook.php';
- $facebook = new Facebook(array( 'appId' =>$_G['setting']['facebook_appid'], 'secret' => $_G['setting']['facebook_secret']));
- $user = $facebook->getUser();
- if ($user) {
- try {
- $user_profile = $facebook->api('/me'); //个人资料
-
- } catch (FacebookApiException $e) {
- $user = null;
- }
- }
-
- if ($user) {
- //登陆成功
-
- $user_arr = getuserbyuid($user_profile['id'],'facebook_uid');
-
- if($user_arr['uid']){ //已经注册了
- $password = authcode($user_arr['password'],'DECODE',$user_arr['key']);
-
- $user = new user();
- $this->login_start($user_arr['username'],$password);
-
- }else{ //第一次登陆,未注册
- $arr = array();
- $arr['username']=($user_profile['username'] ? $user_profile['username'] : $user_profile['name']);
- $arr['name']=$user_profile['name'];
- $arr['facebook_uid']=$user_profile['id'];
- $arr['password']= random(9);//随机密码
- $arr['groupid']=5;
- $arr['check'] = $_G['group'][$arr['groupid']]['reg_check'];
- $arr['sex'] = $user_profile['gender'] == 'female' ? 2:1;
- $arr['email']=$user_profile['id'].'@facebook.com';
- $arr['change_password']= 0;
-
- //添加个人头像
-
- //获取过来的是小头像100*50的,容易变形,暂时就不要了
-
- /*
- $picurl = "https://graph.facebook.com/".$user."/picture";
- $str = @file_get_contents($picurl);
- if($str){
- $save_path = 'uploads/member/'.dgmdate(TIMESTAMP,'Y/m/d/');
- if(!is_dir(ROOT_PATH.$save_path)) dmkdir(ROOT_PATH.$save_path);
- file_put_contents(ROOT_PATH.$save_path.$user.'.jpg',$str);
- $arr['ico'] = $save_path.$user.'.jpg';
- }
- */
-
- $user_action = new user();
- if($user_action->reg($arr)){
- $this->login_start($arr['username'],$arr['password']);
- }else{
- showmessage('注册失败');
- }
- }
-
- } else {
- //未登陆
-
- if($_GET['inajax']){ //自动打开新窗口,在某些浏览器下会被阻止
- $str =str_ireplace('inajax','',$facebook->getLoginUrl());
- include template('common/header_ajax');
- $str = "evalscript("<script type='text/javascript'>
- window.open('".$str."');
- </script>")";
- echo $str;
- include template('common/footer_ajax');
- }else{
-
- dheader("Location:".$facebook->getLoginUrl());
- }
- }
-
复制代码
来自群组: 山林茶社 |