Can you add some debug code in your function, to see if it’s called?
I added an echo statement to my decrypt function, and it is being called, but somehow the decrypt isn’t working correctly. It’s very strange.
Here is my code, maybe someone can spot where I’ve gone wrong.
Controller:
class Profile extends MY_Controller {
public function __construct() {
parent::__construct();
}
public function index()
{
//[removed due to length]
}
public function manage()
{
$user = new User($this->session->userdata('user_id'));
if($this->input->post('submit'))
{
$user->fname = $this->input->post('first_name');
$user->lname = $this->input->post('last_name');
$user->email_address = $this->input->post('email');
if($user->save())
{
redirect('profile');
}
}
$user->group->get();
$lists = array();
foreach($user->maillist->get() as $list)
{
$scope = ($list->private == 1)?"private":"public";
$lists[] = $list->name . ' (' . $scope . ')';
}
if(count($lists) == 0)
{
$lists[] = '<em>none</em>';
}
$this->data['lists'] = $lists;
$this->data['user'] = $user;
}
}
Model:
class User extends DataMapper {
var $has_one = array('group');
var $has_many = array('maillist','email','sent_email','signature');
var $validation = array(
//[other fields]
'password' => array(
'rules' => array('xss_clean','trim','encrypt','required', 'max_length' => 255),
'label' => 'Password',
'get_rules' => array('decrypt')
),
//[other fields]
);
var $default_order_by = array('group_admin','fname', 'lname');
function __construct($id = NULL)
{
parent::__construct($id);
$this->pass_key = "[removed]";
}
public static function check_login($username, $password)
{
$return = false;
$user = new User();
$user->where('username',$username)->get();
if($user->password == $password)
{
$return = $user->id;
}
return $return;
}
function _encrypt($field)
{
if (!empty($this->{$field}))
{
$CI = get_instance();
$CI->load->library('encrypt');
$this->{$field} = $CI->encrypt->encode($this->{$field}, $this->pass_key);
}
}
function _decrypt($field)
{
if (!empty($this->{$field}))
{
$CI = get_instance();
$CI->load->library('encrypt');
$this->{$field} = $CI->encrypt->decode($this->{$field}, $this->pass_key);
}
}
}
View:
<div>
<h2>Manage Your Profile</h2>
<p> <?php<br />
foreach ($user->error->all as $e)<br />
{<br />
echo '<div class="error">'.$e . '</div>';<br />
}<br />
?><br />
<?php echo form_open('profile/manage','',array('user_id'=>$user->id)); ?><br />
<br />
<label for="first_name">First Name</label><br />
<input type="text" name="first_name" value="<?php echo $user->fname;?>" ><br />
<br />
<br />
<label for="last_name">Last Name</label><br />
<input type="text" name="last_name" value="<?php echo $user->lname;?>" ><br />
<br />
<br />
<label for="password">Password</label><br />
<?php $pass = $user->password; ?><br />
<input type="password" name="password" value="<?php echo $pass; ?>" /><br />
<br />
<br />
<label for="pass_conf">Password Confirmation</label><br />
<input type="password" name="pass_conf" value="" /><br />
<br />
<br />
<label for="email">Email</label><br />
<input type="text" name="email" value="<?php echo $user->email_address; ?>" ><br />
<br />
<br />
<label for="group">Group</label><br />
<input readonly="readonly" type="text" name="group" value="<?php echo $user->group->name; ?>" ><br />
<br />
<br />
<label for="group_admin">Group Admin</label><br />
<input type="radio" name="group_admin" value="1"<?php echo (($user->group_admin == 1)?' checked="checked"':'disabled="disabled"') ?>> True<br />
<input type="radio" name="group_admin" value="0"<?php echo (($user->group_admin == 1)?'':' checked="checked" disabled="disabled"') ?>> False<br />
<br />
<br />
<input type="submit" name="submit" value="Submit" /><br />
<input type="reset" name="reset" value="Reset" /><br />
</p>
<p><br />
<input type="button" name="cancel"><br />
<br />
</form><br />
</div>
Also, I have attached a screenshot of my browser with firebug open, so you can see what I’m talking about.