2016-01-06 107 views
-1

这是我的控制器。如何防止Facebook登录后在弹出窗口中重定向网址?

public function actions() 
{ 
    return [   

     'auth' => [ 
      'class' => 'yii\authclient\AuthAction', 
      'successCallback' => [$this, 'oAuthSuccess'], 
     ], 
    ]; 
} 


public function oAuthSuccess($client) { 

    $name = explode(" ",$userAttributes['name']); 
    $existing_customer = Customer::find() 
       ->where(['email' => $userAttributes['email']]) 
       ->orWhere(['id_facebook' => $userAttributes['id']]) 
       ->one();   

    if(empty($existing_customer)){ 

     $customer = new Customer(); 
     $customer->firstname = $name[0]; 
     $customer->lastname = $name[1]; 
     $customer->id_default_group = 3; 
     $customer->username = $userAttributes['id'].'@facebook.com'; 
     $customer->id_facebook = $userAttributes['id']; 
     $customer->email = $userAttributes['email']; 
     $password = rand(0000, 9999); 
     $auth_key = Yii::$app->getSecurity()->generateRandomString(); 
     $customer->auth_key = $auth_key; 
     $hash = Yii::$app->getSecurity()->generatePasswordHash($password); 
     $customer->password_hash = $hash; 
     $customer->activation_code = $password; 
     $customer->active =1; 

     if ($customer->save(false)) {  

      $customergroup = new CustomerGroup();  
      $customergroup->id_customer = $customer->id_customer; 
      $customergroup->id_group = $customer->id_default_group; 
      $customergroup->save(false);     

      Yii::$app->response->redirect(['advanced','email' => $customer->email]); 
     }   
    } 

这是我的main.php文件。

'authClientCollection' => [ 
     'class' => 'yii\authclient\Collection', 
     'clients' => [ 
      'facebook' => [     
       'class' => 'yii\authclient\clients\Facebook', 
       'authUrl' => 'https://www.facebook.com/dialog/oauth?display=popup', 
       'clientId' => '', 
       'clientSecret' => '',      
       'scope' => [ 
        'email', 
        'user_birthday', 
        'user_location', 
        'user_hometown',       
       ], 
      ],     
     ], 
    ], 

其实我在做注册的2个过程。 用户点击Facebook按钮后,它返回到我的第二步弹出,但我需要它在我的网站。这怎么可能?

回答

1

改变你与你的愿望的行动对行动功能auth successCallBack ..

样本,其中successCallback检查,如果用户如果为真呼叫动作身份验证,否则动作连接

/** @inheritdoc */ 
public function actions() 
{ 
    return [ 
     'auth' => [ 
      'class' => AuthAction::className(), 
      'successCallback' => \Yii::$app->user->isGuest 
       ? [$this, 'authenticate'] 
       : [$this, 'connect'], 
     ] 
    ]; 
} 

客人下方在facebook登录后,您将返回oAuthSuccess函数内的代码。我认为您正在寻找的弹出窗口位于此函数内部,并且从此重定向中调用。如果你想让其他人改变这个功能的引导部分。

Yii::$app->response->redirect(['advanced','email' => $customer->email]); 
+0

你能介绍关于验证和连接功能吗? –

+0

这些函数名称是样本..你必须用你想要执行的动作的名称替换这些名称....在描述的情况下 – scaisEdge

+0

在你的问题你使用$ this'oAuthSuccess'你的控制器的动作..但似乎这显示你不想要的模式.. – scaisEdge