Hi,
I use portlet to display homepage with login that has forgotpassword link
on click this link i use ajax to display the result
but why ajax meets problem
how to set url? but when i use without portlet ie using views and controller ajax works
my opening url for this portlet is http://localhost/code/php/index
when i use without portlet suchas http://localhost/code/php/index.php?r=login/login it works
view is
<?php echo CHtml::link(‘Forgot Password?’,’#’,array(‘id’=>‘forgotpassword’,‘onclick’=>’$("#result").html("");’,‘style’=>‘color:yellow’));?>
<?php $urls=Yii::app()->request->url;
$script="
$(’#forgotpassword’).click(function(){
jQuery.ajax({
type:‘POST’,
url:’".$urls."&request=forgotpassword’, // i think this is the problem
cache:false,
‘data’:jQuery(this).parents(‘form’).serialize(),
success:function(html)
{
jQuery(’#passwordsend’).html(html);
},
});
return false;
});
";
Yii::app()->clientScript->registerScript(‘forgotpassword’, $script, CClientScript::POS_READY);
?>
and portlet is
class Login extends Portlet
{
protected function renderContent()
{
$form=new LoginForm;
$form->attributes=$_POST['LoginForm'];
if (Yii::app()->request->isAjaxRequest)
{
$request=Yii::app()->request->getParam('request');
if ('forgotpassword'==$request)
{
if (!empty($form->username))
{
$user=User::model()->find('username=:username ',array(':username'=>$form->username));
if (null!=$user)
{
$subject="Password Rememberance";
$to=$user->email;
$message="Password Rememberance for your Eprodigy account\n\nyour username : ".$user->username."\nPassword : ".base64_decode($user->password)."\n\n\nRegards\nEprodigy Team";
Yii::app()->mailer->Host = 'mail.prudencesolution.com';
Yii::app()->mailer->IsSMTP();
Yii::app()->mailer->From = 'rettaikulamram@gmail.com';
Yii::app()->mailer->FromName = 'Eprodigy Team';
Yii::app()->mailer->AddReplyTo('rettaikulamram@gmail.com');
Yii::app()->mailer->AddAddress($to);
Yii::app()->mailer->Subject = $subject;
Yii::app()->mailer->Body = $message;
if (Yii::app()->mailer->Send())
echo "<font color='green'>Password Remembering Successful<br/> Password Sended to your Emailaddress</font>";
else // with mailer error message eg. SMTP Error: Could not connect to SMTP host. Check Internet Connection!
echo "<font color='red'>Password Remembering Unsuccessful<br/>Password not Sended to your Emailaddress</font>";
}
else
echo "<font color='red'>Password Remembering Unsuccessful<br/>Invalid Username</font>";
}
else
echo "<font color='red'>Password Remembering Unsuccessful<br/>Invalid Username</font>";
}
}
else
{
if (isset($_POST['login']))
{
$identity=new UserIdentity($form->username,$form->password);
if($identity->authenticate())
{
//print "welcome".$form->username;
Yii::app()->user->login($identity); // allow login to this user
//$this->refresh();
$this->controller->refresh();
//$this->redirect(array('Menu')); // show success message form
}
else
yii::app()->user->setFlash('result','Login Unsuccessfully <br/>Invalid Username or Password');
}
$this->render('login',array('form'=>$form));
}
}
}
please help me