Welcome Guest, Not a member yet? Register   Sign In
Callbacks: Your own Validation Functions
#1

[eluser]nirbhab[/eluser]
Hi All,

I feed up with this function,
I work with full error reporting on means level 5.

Is there any way to check the integrity of the function, you made in this method?

Explanation with example code:
Code:
function oldpass_check($str)
    {
        $user = $this->authentication->give_user_details();//return as array of logged in user.
        $query = $this->db->query("SELECT ".$user->password." from fc_user WHERE username = '".$user->username."' AND password = '".$user->password."' LIMIT 1");
        if($query->num_rows() == 1)
        {
            $row = $query_result->first_row();
            if ($str == $row->password)
            {
                $this->validation->set_message('oldpass_check', 'The %s does not matches');
                return FALSE;
            }
            else
            {
                return TRUE;
            }
        }
        else
        {
            return true;
        }
    }
Quote:This is what $user = $this->authentication->give_user_details();//return as array of logged in returns
Array
(
[0] => stdClass Object
(
[user_id] => 8
[name] => deepesh
[email] => [email protected]
[username] => deepesh
[password] => 02e450de72288537cfc18d003639c92b
[auth_type] => o
[status] => a
[reg_on] => 0000-00-00 00:00:00
)

)
#2

[eluser]nirbhab[/eluser]
I got a article which actually helps me out,
as i was running my callback_method in MODEL.
It was not calling the method.
But question still persists regarding a way to test the callback_method directly.

Quote:here is the article
Callback in Model
#3

[eluser]webthink[/eluser]
I'm not entirely sure what you're asking. When you say "Is there any way to check the integrity of the function, you made in this method?" Do you mean you want to check for the existence of the callback function?
so something like this? if (method_exists($this, oldpass_check)) or since you say you've put the callback in your model if (method_exists($this->myModel, oldpass_check)). Is this what you mean?

I'm a bit confused about the actual code in your callback function though.

1. You call $user = $this->authentication->give_user_details(); which gives you an array of objects so instead of $this->user you're going to need to do something like $this->user[0]->password.

2. You have the user information from the db already so why do you need to query the db again with this $this->db->query?

3. The query you're trying to build won't work because even if you do access the password var in the manner i've described above you'll still end up with something like this:
SELECT 02e450de72288537cfc18d003639c92b from fc_user WHERE username = 'deepesh' AND password = '02e450de72288537cfc18d003639c92b' LIMIT 1
#4

[eluser]nirbhab[/eluser]
1. I make modules in model, do all the task in that model, so that it doesn't depends upon the controller at all.
2. My aim: make change password module. which when called does all the stuff for me.
3. You are right at your point 1. i have changed it as you have done.
4. in second point of yours i am checking the logged in users password with the form field, telling me to change the password, so when old password from the form, n the password retrieved from the logged in user matches , i will allow user to change his password.
5. Model Of CI doesn't supports callback_ method. thats why callback_oldpass_check|required|trim, didn't worked for me.
6. Now a way to check the integrity of the function, we can all it like this
$this->ModelName->oldpass_check('SomeValue'); in our controller.
After searching the whole day! i got this thing cleared. Previous post of mine contains a link.. which actually explains how to run callback_ in model.

Your help is appreciable...thanks a lot to figure out my fault.




Theme © iAndrew 2016 - Forum software by © MyBB