1

最適に機能しないパスワードのリセット コンポーネントを含む joomla 1.5 サイトを継承しました。ATM ユーザーが入力した電子メールにパスワードのリセットを送信することはできますが、既存のユーザーと照合して電子メールが有効かどうかをチェックする機能がコンポーネントにありません。私は PHP にかなり慣れていないので、追加の if ステートメントを導入する方法が 100% わかりません。

これまでの様子は次のとおりです。

public function submitemail() {
    $db = JFactory::getDBO() ;
    $requestedEmail =   JRequest::getVar('emailaddr' , '') ;
    $db->setQuery('select id , username, name, email from #__users where block = 0  and email = "'.$requestedEmail.'"') ;
    if( $user =  $db->loadObject() )  {

        // Make sure the user isn't a Super Admin.
        $juser = JFactory::getUser($user->id) ;
        //joomla 1.6 and 1.5 check  
        if ($juser->authorize('core.admin') || $juser->usertype == 'Super Administrator') {
            $this->setRedirect( 'index.php?option=com_resetpassword'  , 'Email is not valid' ) ;        
        }
        else {          
            $result = $this->sendPasswordResetEmail( $user ) ;
            $this->setRedirect( 'index.php?option=com_resetpassword&layout=success'  //, 'Please check your email and follow the instructions to reset your password ' 
                ) ;
        }
    }
    else {
        $this->setRedirect( 'index.php?option=com_resetpassword'  );
    }
}

そして、このスニペットを見つけた関連記事に出くわしました。リセットのためにユーザーが入力した電子メールに対して、現在データベースにある電子メール アドレスを確認するにはどうすればよいですか?

function validate()
{ jimport('joomla.mail.helper');
$valid = true;
 if ($this->_data->email && !JMailHelper::isEmailAddress($this->_data->email))
{           
     $this->_app->enqueueMessage(JText::_('Invalid Email Address'),'error');                       
     $valid = false;           
}   
return $valid; 
}
4

1 に答える 1

1

それは実際にすでに行われていることです。一番上は、送信された電子メール アドレスに基づいてユーザーの行を読み込みます。

$requestedEmail =   JRequest::getVar('emailaddr' , '') ;
$db->setQuery('select id , username, name, email from #__users where block = 0  and email = "'.$requestedEmail.'"') ;
if( $user =  $db->loadObject() )  {
    ...

おそらく必要なことは、これが失敗した場合のメッセージを下部のelseステートメントに追加することだけです:

else {
    $this->_app->enqueueMessage(JText::_('Invalid Email Address'),'error');
    $this->setRedirect( 'index.php?option=com_resetpassword'  );
}

が設定されていない場合$this->_appは、代わりにこれを使用して取得できるはずです。

JFactory::getApplication()->enqueueMessage(JText::_('Invalid Email Address'),'error');
于 2013-03-10T03:48:05.290 に答える