ほぼ同じコードの 2 つの連続した elseif ブロックがあるため、コード ロジックに間違いがあると思います。
//first elseif
elseif (!$socialUser && empty($siteUserId)) {
//first time user
$secretWord = $this->RandomString->getRand(7);
$data = array('User'=> array(
'username' => $this->userData['username'],
'password' => $this->Auth->password($secretWord),
'email' => $this->userData['email'],
'name' => $this->userData['name']
));
$siteUserId = $this->_addSiteUser($data);
if ($siteUserId){
$data = array('SocialUser' => array(
'title' => 'facebook',
'identifier' => $this->FB_userId,
'user_id' => $siteUserId
));
if ($this->_addSocialUser($data)){
$this->Auth->login($siteUserId);
$l = $this->Session->read('Auth.redirect');
if (empty($l)) $l = array('controller' => 'qurans', 'action' => 'index');
$this->controller->Session->setFlash(__('You are logined using Facebook Sucessfully!'.$this->userData['name'], true).' '.$secretWord, 'done_msg');
$this->Session->delete('Auth.redirect');
$this->controller->redirect($l);
}
else{
$this->controller->Session->setFlash(__('There is an error during adding you as a social member. Contact admin!',true), 'error_msg');
// $this->controller->redirect($this->Auth->loginAction);
$this->logout();
$this->controller->redirect(array('controller' => 'qurans', 'action' => 'index'));
}
}
}
//second elseif
elseif($socialUser && empty($siteUserId)){
$secretWord = $this->RandomString->getRand(7);
$data = array('User'=> array(
'username' => $this->userData['username'],
'password' => $this->Auth->password($secretWord),
'email' => $this->userData['email'],
'name' => $this->userData['name']
));
$siteUserId = $this->_addSiteUser($data);
if ($siteUserId){
//HERE IS ONLY THE DIFFERENCE
$data = $socialUser;
$data['SocialUser']['user_id'] = $siteUserId;
//DIFFERENCE END HERE
if ($this->_addSocialUser($data)){
$this->Auth->login($siteUserId);
$l = $this->Session->read('Auth.redirect');
if (empty($l)) $l = array('controller' => 'qurans', 'action' => 'index');
$this->controller->Session->setFlash(__('You are logined using Facebook Sucessfully!'.$this->userData['name'], true).' '.$secretWord, 'done_msg');
$this->Session->delete('Auth.redirect');
$this->controller->redirect($l);
}
else{
$this->controller->Session->setFlash(__('There is an error during adding you as a social member. Contact admin!',true), 'error_msg');
// $this->controller->redirect($this->Auth->loginAction);
$this->logout();
$this->controller->redirect(array('controller' => 'qurans', 'action' => 'index'));
}
}
}
コードは問題なく動作すると思いますが、2 つの連続する elseif ブロックの間でコード ブロックをコピー アンド ペーストするのがうまくいきませんか? このコードを改善するアイデアはありますか? それとも大丈夫ですか?