sasori
(Nemo Md5)
November 17, 2010, 6:50am
1
hi, one of my super noob questions:
I created a simple recovery password script and it doesn’t seem to move at all when i submit the form
did i miss something ?
controller code
public function actionForget()
{
$form = new Wsmembers;
if(isset($_POST['Wsmembers']))
{
$form->attributes = $_POST['Wsmembers'];
$sql = "SELECT sha1(WSLoginPassword) FROM wsmembers WHERE WSEmailAddress = :email";
$command = Yii::app()->db->createCommand($sql);
$command->bindValue(":email", $_POST['WSEmailAddress']);
$pass = $command->query();
if($pass === 1){
$to = $_POST['WSEmailAddress'];
$subject = "Your Password";
$message = "Your password is = $pass";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: buggyman<buggyman@gmail.com>' . "\r\n";
mail($to, $subject, $message, $headers);
Yii::app()->user->setFlash('recover','Your password has been sent to your email address');
$this->redirect('forget', array('wsmembers/forget'));
}
}
$this->render('forget', array('form' => $form));
}
forget.php view form
<?php
$this->breadcrumbs=array(
'Member'=>array('index'),
'forget',
);
?>
<h3>Recover Password</h3>
<div class="form">
<?php echo CHtml::beginForm(); ?>
<?php echo CHtml::errorSummary($form)?>
Please Enter Your Email Address
<div class="row">
<?php echo CHtml::activeLabelEx($form,'WSEmailAddress'); ?>
<?php echo CHtml::activeTextField($form,'WSEmailAddress'); ?>
</div>
<div class="action">
<?php echo CHtml::submitButton('Recover'); ?>
</div>
<?php echo CHtml::endForm(); ?>
</div>
andy_s
(Arekandrei)
November 17, 2010, 6:57am
2
$pass = $command->query();
if($pass === 1){
$pass can’t be an integer. Check the API: http://www.yiiframework.com/doc/api/1.1/CDbCommand#query-detail
Maybe you should use queryRow() and check if it is not false.
iivano71
(Igor Zg1987)
November 17, 2010, 8:52am
3
Try This
public function actionForget()
{
$form = new Wsmembers;
if(isset($_POST['Wsmembers']))
{
$form->attributes = $_POST['Wsmembers'];
$CRI=new CDbCriteria;
$CRI->select = 'sha1(WSLoginPassword)';
$CRI->condition = 'WSEmailAddress = '.$form->WSEmailAddress; // or $CRI->condition = "WSEmailAddress = '".$form->WSEmailAddress."' ";
$pass = $form->find($CRI);// if dosent work try $form->findAll($CRI)
if($pass === 1){
$to = $form->WSEmailAddress;
$subject = "Your Password";
$message = "Your password is = $pass";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: buggyman<buggyman@gmail.com>' . "\r\n";
mail($to, $subject, $message, $headers);
Yii::app()->user->setFlash('recover','Your password has been sent to your email address');
$this->redirect('forget', array('wsmembers/forget'));
}
}
$this->render('forget', array('form' => $form));
}
sasori
(Nemo Md5)
November 17, 2010, 9:07am
4
Try This
public function actionForget()
{
$form = new Wsmembers;
if(isset($_POST['Wsmembers']))
{
$form->attributes = $_POST['Wsmembers'];
$CRI=new CDbCriteria;
$CRI->select = 'sha1(WSLoginPassword)';
$CRI->condition = 'WSEmailAddress = '.$form->WSEmailAddress; // or $CRI->condition = "WSEmailAddress = '".$form->WSEmailAddress."' ";
$pass = $form->find($CRI);// if dosent work try $form->findAll($CRI)
if($pass === 1){
$to = $form->WSEmailAddress;
$subject = "Your Password";
$message = "Your password is = $pass";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: buggyman<buggyman@gmail.com>' . "\r\n";
mail($to, $subject, $message, $headers);
Yii::app()->user->setFlash('recover','Your password has been sent to your email address');
$this->redirect('forget', array('wsmembers/forget'));
}
}
$this->render('forget', array('form' => $form));
}
thanks, but i got this
how do we quote this line ?
$CRI->condition = 'WSEmailAddress = ' .$form->WSEmailAddress;
I tried
$CRI->condition = ‘WSEmailAddress = \’$form->WSEmailAddress\’’; ( doesn’t work )
$CRI->condition = “WSEmailAddress = \’$form->WSEmailAddress\’”; ( doesn’t work as well)
$CRI->condition = “WSEmailAddress = ‘$form->WSEmailAddress’”; ( same with this )
zaccaria
(Matteo Falsitta)
November 17, 2010, 9:15am
5
$CRI->condition = 'WSEmailAddress = :mail';
$CRI->params=array(':mail'=>$form->WSEmailAddress);
sasori
(Nemo Md5)
November 17, 2010, 9:17am
6
I just tried this before i got your reply, but it doesn’t work too
iivano71
(Igor Zg1987)
November 17, 2010, 9:30am
7
Error is because mysql coomand this will work
public function actionForget()
{
$form = new Wsmembers;
if(isset($_POST['Wsmembers']))
{
$form->attributes = $_POST['Wsmembers'];
$CRI=new CDbCriteria;
$CRI->select = 'sha1(WSLoginPassword)';
$CRI->condition = "WSEmailAddress = '".$form->WSEmailAddress."' ";
$pass = $form->find($CRI);// if dosent work try $form->findAll($CRI)
if($pass === 1){
$to = $form->WSEmailAddress;
$subject = "Your Password";
$message = "Your password is = $pass";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: buggyman<buggyman@gmail.com>' . "\r\n";
mail($to, $subject, $message, $headers);
Yii::app()->user->setFlash('recover','Your password has been sent to your email address');
$this->redirect('forget', array('wsmembers/forget'));
}
}
$this->render('forget', array('form' => $form));
}
sasori
(Nemo Md5)
November 17, 2010, 9:35am
8
$CRI->condition = "WSEmailAddress = '".$form->WSEmailAddress."'";
$pass = $form->find($CRI);
or
$pass = $form->findAll($CRI);
doesn’t throw quote error anymore, but it got stuck, that the page won’t move at all after clicking the
submit button… why is that happening, any idea ?
iivano71
(Igor Zg1987)
November 17, 2010, 11:51am
9
this will help you create in Wsmebers model
object name :
public $emailed;
public function actionForget()
{
$form = new Wsmembers;
$form->emailed = "Email Form";
if(isset($_POST['Wsmembers']))
{
$form->attributes = $_POST['Wsmembers'];
$CRI=new CDbCriteria;
$CRI->select = 'sha1(WSLoginPassword)';
$CRI->condition = "WSEmailAddress = '".$form->WSEmailAddress."' ";
$pass = $form->find($CRI);// if dosent work try $form->findAll($CRI)
if($pass === 1){
$form->emailed = "Sent";
$to = $form->WSEmailAddress;
$subject = "Your Password";
$message = "Your password is = $pass";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: buggyman<buggyman@gmail.com>' . "\r\n";
mail($to, $subject, $message, $headers);
Yii::app()->user->setFlash('recover','Your password has been sent to your email address');
$this->render('forget', array('form' => $form));
}
}
$this->render('forget', array('form' => $form));
}
and in forget View This
<?php if($form->emailed = "Email Form") : ?>
<?php
$this->breadcrumbs=array(
'Member'=>array('index'),
'forget',
);
?>
<h3>Recover Password</h3>
<div class="form">
<?php echo CHtml::beginForm(); ?>
<?php echo CHtml::errorSummary($form)?>
Please Enter Your Email Address
<div class="row">
<?php echo CHtml::activeLabelEx($form,'WSEmailAddress'); ?>
<?php echo CHtml::activeTextField($form,'WSEmailAddress'); ?>
</div>
<div class="action">
<?php echo CHtml::submitButton('Recover'); ?>
</div>
<?php echo CHtml::endForm(); ?>
</div>
<?php else if($form->emailed = "Sent") :?>
<?php
//echo something hire like
echo "Email was send to your email, thank you for using our password reset form"; ?>
<?php endif; ?>
iivano71
(Igor Zg1987)
November 17, 2010, 12:11pm
10
i forgot you have to echo password
in your mail form
if($pass === 1){
$to = $form->WSEmailAddress;
$subject = "Your Password";
$message = "Your password is = ".$pass->WSLoginPassword;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: buggyman<buggyman@gmail.com>' . "\r\n";
mail($to, $subject, $message, $headers);
Yii::app()->user->setFlash('recover','Your password has been sent to your email address');
$this->redirect('forget', array('wsmembers/forget'));
}
sasori
(Nemo Md5)
November 17, 2010, 12:18pm
11
I did try, but what’s bothering me now is that, it doesn’t send the email nor do the query, when it doesn’t have much difference in my registration stuff, only the query itself
iivano71
(Igor Zg1987)
November 17, 2010, 12:21pm
12
try to echo out all $form->attributes in your view to see if thy are full
sasori
(Nemo Md5)
November 17, 2010, 12:25pm
13
yeah i did
<?php echo $form->WSEmailAddress; ?>
or even
<?php echo "<pre>",print_r($form->attributes),"</pre>"; ?>
Array
(
[WSEmailConfirmed] => 0
[WSMembershipLoginAttempts] => 0
[WSMembershipLockedOut] => 0
[WSMembershipSystemLockedOut] => 0
[WSEmailAddress] => buggyman@gmail.com
[MemberShipID] =>
[WSLoginName] =>
[WSLoginPassword] =>
[WSMembershipDateSetup] =>
[WSMembershipDateConfirmed] =>
[WSMembershipContactName] =>
[WSMembershipSecretQuestion] =>
[WSMembershipSecretAnswer] =>
[WSMembershipLockOutDateTime] =>
[WSLoginNameAllUsers] =>
[WSLoginPasswordAllUsers] =>
[IntroducingMemberID] =>
)
1
iivano71
(Igor Zg1987)
November 17, 2010, 12:33pm
14
email should be sent
try to echo out
if($pass === 1){
echo $form->WSEmailAddress;
echo $pass->WSLoginPassword;
}
and see if thy are filed
sasori
(Nemo Md5)
November 17, 2010, 12:39pm
15
doesn’t echo out anything, but i did this
if($pass !== null)
it does send the email now
but the email body contains no password retrieved from table
Your password is =
iivano71
(Igor Zg1987)
November 17, 2010, 1:00pm
16
print_r($pass) see what is in there if dosent show anything try to findAll()
$CRI=new CDbCriteria;
//$CRI->select = 'sha1(WSLoginPassword)';
$CRI->condition = "WSEmailAddress = '".$form->WSEmailAddress."' ";
$pass = $form->findAll($CRI);
print_r($pass);
iivano71
(Igor Zg1987)
November 17, 2010, 1:24pm
17
i`n mysql
you cant decode sha(WSLoginPassword);
sasori
(Nemo Md5)
November 17, 2010, 1:27pm
18
but it works with my login script in yii, I use sha1() when checking,
a few minutes ago I was able to send the email and retrieve back the encrypted password, it’s weird sha1 doesn’t work now…maybe it’s with the way i am quoting each variables
iivano71
(Igor Zg1987)
November 17, 2010, 1:30pm
19
sasori:
but it works with my login script in yii, I use sha1() when checking,
a few minutes ago I was able to send the email and retrieve back the encrypted password, it’s weird sha1 doesn’t work now…maybe it’s with the way i am quoting each variables
yes but mysql doesen`t support decoding sha1
iivano71
(Igor Zg1987)
November 17, 2010, 1:34pm
20
upoad entire login system and i will help you, you can only upadate your password or , create a random update password and then send new password to email