Can someone help me with this code please? I'm trying to setup a page to change password, first by entering the old password then the new password(twice). What my script is doing is putting a new entry into the database.
My Controller code:
function admin_changepassword()
{
if($this->Session->check('userid'))
{
if($this->Session->read('usertype')=='admin')
{
if (!empty($this->data))
{
$this->data['Admin']['id']=$_SESSION['id'];
$uid = $this->Admin->findById($this->data['Admin']['id']);
if($this->data['Admin']['current']!= $uid['Admin']['password'])
{
$this->Session->setFlash("Your old Password field didn't match");
}
else if($this->data['Admin']['new_password'] != $this->data['Admin']['confirm_password'] ) {
$this->Session_setFlash("New password and Confirm password field do not match");
}
else {
$this->data['Admin']['password'] = $this->data['Admin']['new_password'];
$this->data['Admin']['id'] = $this->Admin->id;
if($this->Admin->save($this->data))
{
$this->Session->setFlash("Password updated");
$this->redirect(array('controller'=>'jobseekers','action'=>'welcome/'));
}
else
{
$this->Session->setFlash('Please try again.', true);
}
}
}
}
}
else
{
$this->Session->setFlash('You are not logged in.', true);
$this->redirect(array('action'=>'index/'));
}
$this->layout = 'admin';
}
My view code:
<table border="0" width="100%" id="table7" cellspacing="0" cellpadding="0">
<tr>
<td>
<img border="0" src="<?= $html->url('/img/adm/changepass.gif'); ?>" width="235" height="38"></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>
<?php echo $form->create('Employer',array('action'=>'changepassword')); ?>
<table border="0" width="753" id="table9" cellspacing="5" cellpadding="0">
<tr>
<td width="140" align="left">
<p style="margin-left: 10px">Password: </td>
<td width="598">
<p style="margin-left: 10px">
<?php echo $form->input('Admin.current',array('type'=>'password','label'=>false,'class'=>'input','id'=>'textfield','style'=>'font-size: 8pt; border-style: solid; border-width: 1px; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; float:left'))?>
<!--input name="textfield29" size="34" style="font-size: 8pt; border-style: solid; border-width: 1px; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; float:left" /--></td>
</tr>
<tr>
<td width="140" align="left">
<p style="margin-left: 10px">New Password:</td>
<td width="598">
<p style="margin-left: 10px">
<?php echo $form->input('Admin.new_password',array('type'=>'password','label'=>false,'class'=>'input','id'=>'textfield','style'=>'font-size: 8pt; border-style: solid; border-width: 1px; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; float:left'))?>
<!--input name="textfield27" size="34" style="font-size: 8pt; border-style: solid; border-width: 1px; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; float:left" /--></td>
</tr>
<tr>
<td width="140" align="left">
<p style="margin-left: 10px">Confirm New
Password:</td>
<td width="598">
<p style="margin-left: 10px">
<?php echo $form->input('Admin.confirm_password',array('type'=>'password','label'=>false,'class'=>'input','id'=>'textfield','style'=>'font-size: 8pt; border-style: solid; border-width: 1px; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; float:left'))?>
<!--input name="textfield28" size="34" style="font-size: 8pt; border-style: solid; border-width: 1px; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; float:left" /--></td>
</tr>
<?php echo $form->input('id',array('type'=>'hidden','value'=>$_SESSION['userid']));?>
<tr>
<td width="140"> </td>
<td width="598">
<p style="margin-left: 10px; margin-top: 5px; margin-bottom: 5px" align="left">
<?php echo $form->submit('/img/adm/submit.gif'); ?>
<!--img border="0" src="../ima/tit/submit.gif" width="58" height="15"--></td>
</tr>
</table>
<?php echo $form->end();?>
</td>
</tr>
</table>[/code]
My admin table has 3 fields: ID,USERNAME AND PASSWORD