Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Callbacks

Sviatoslav edited this page May 25, 2013 · 9 revisions

To make you able to customize the behavior of hoauth, it is provide some useful callbacks.

Controller callbacks

In this section listed callbacks, that should be available as methods of controller from witch was fired HOAuthAction.

Controller::hoauthCheckAccess($user)

If you need to perform some access check for user, you can use hoauthCheckAccess($user) callback. This method will be called with one input argument - User model of the user being authorized. This method should return integer values (accessCode) depending on the scenario needed:

  • 0 - user shouldn't get access
  • 1 - user may login
  • 2 - user may login, but not now (e.g. the email should be verified and activated)

You can also not only return the accessCode, but also render the page with error or any information you need. yii-user users can also use this callback. But the default access checking method HOAuthAction::yiiUserCheckAccess() will not be fired in this case. However if you still need default access checking, you can call it by yourself for example:

class MyController extends Controller
{
  ...
  public function hoauthCheckAccess($user)
  {
    // the false as the second parameter will disable default error rendering
    $accessCode = $this->action->yiiUserCheckAccess($user, false);
    // do other stuff
    return $accessCode;
  }
}

Controller::hoauthAfterLogin($user, $newUser)

This callback is the last, what will be called after user was successfully logged in. You can use this callback to set some States or send some spam to email and what ever you want. This method will be called with two input arguments:

  • $user - User model of the user being authorized.
  • $newUser - flag, that indicating, that hoauth registered a new user.