Closed gabe152006 closed 3 years ago
You'll need to set the hook before calling the login() method.
You'll need to set the hook before calling the login() method.
Sorry, I'm a bit confused, call the hook in a different method in the Auth controller file? or in the construct?
You can keep it here but you'll need to move the setHook() call up a few lines. Since the hook is called in the login() method it has to be set before the login() method is called.
Something like this:
$this->ionAuth->setHook("post_login_successful", "check_cookie", get_class($this), "handleCookies", array());
if ($this->ionAuth->login($this->request->getVar('identity'), $this->request->getVar('password'), $remember))
{
//if the login is successful
//redirect them back to the home page
You can keep it here but you'll need to move the setHook() call up a few lines. Since the hook is called in the login() method it has to be set before the login() method is called.
Something like this:
$this->ionAuth->setHook("post_login_successful", "check_cookie", get_class($this), "handleCookies", array()); if ($this->ionAuth->login($this->request->getVar('identity'), $this->request->getVar('password'), $remember)) { //if the login is successful //redirect them back to the home page
I see! Looks like now it did execute the code after I moved it but it threw this error:
call_user_func_array(): Argument #1 ($callback) must be a valid callback, non-static method App\Controllers\Auth::handleCookies() cannot be called statically
Any insight?
Trace:
VENDORPATH/benedmunds/codeigniter-ion-auth/Models/IonAuthModel.php at line 2317
2310 */
2311 protected function callHook(string $event, string $name)
2312 {
2313 if (isset($this->ionHooks->{$event}[$name]) && method_exists($this->ionHooks->{$event}[$name]->class, $this->ionHooks->{$event}[$name]->method))
2314 {
2315 $hook = $this->ionHooks->{$event}[$name];
2316
2317 return call_user_func_array([$hook->class, $hook->method], $hook->arguments);
2318 }
2319
2320 return false;
2321 }
2322
2323 /**
2324 * Call Additional functions to run that were registered with setHook().
I think I see the problem. I just pushed a commit to the 4 branch, update to use that and then update this code to:
$this->ionAuth->setHook("post_login_successful", "check_cookie", $this, "handleCookies", array());
We need to pass the instantiated object instead of just the name, but the previous typing wouldn't allow that.
I think I see the problem. I just pushed a commit to the 4 branch, update to use that and then update this code to:
$this->ionAuth->setHook("post_login_successful", "check_cookie", $this, "handleCookies", array());
We need to pass the instantiated object instead of just the name, but the previous typing wouldn't allow that.
Ahh thank you so much! The problem is now fixed
Awesome, take care!
This Github Issue section is meant to track bugs with the library itself Please post generic support issues to the CodeIgniter forums or StackOverflow.
Using branch 4 CI 4.1
Hello!
I'm trying to use inject the following function using the "post_login_successful" hook after login and it doesn't seem to work.
The function I'm trying to call
Seems like it the setHook gets ignored and continues through the normal login process. I'm wondering if I should insert the hook in a different part of the login process?