Didn't there used to be a way to hook into a login so you could do some routine every time a person logs in?
I found login as a hook in the documentation but looking at the Users system there does not seem to be a hook for it. Any ideas how to "hook" a function to a users login?
thanks!
- mercromina responded to »error when i try to upgrade to the last version of dizkus module (3.1)« 08:01 PM
- craigh responded to »TagIt 3.0 for Zikula« 03:58 PM
- localrags responded to »Remove contents of nuke_sc_anticracker from Database« 11:30 AM
- jmvaughn responded to »Shoutit for zikula 1.3?« 09:31 AM
- mdee responded to »Different page content under one template (tpl file) based on URL« 07:17 AM
- espaan responded to »Categories disappear when editing ...« 08. Feb
- eledril responded to »How decrease zikula cpu usage« 08. Feb
Zikula Blog
- Anatomy of Open Source Projects on Mar 07
- Continuous Review on Mar 01
- Not Invented Here on Feb 24
- How to Contribute Your Code at Github on Jan 13
- 10 Steps to Coding-Nirvana: Tips for Successful Module Writing on Nov 12
- Submitting Bug Report Tickets That Get Results on Aug 17
- Cozi Tricks #1: Syntax Highlighting on Aug 07
Login
login hook
-
- Rank: Softmore
- Registered: Nov 30, 2005
- Last visit: May 07, 2010
- Posts: 104
-
- Rank: Team Member
- Registered: Jan 19, 2003
- Posts: 432
You can use this hook type like that:
Code
if (!pnModRegisterHook('zikula', 'login', 'GUI', 'YourModule', 'user', 'yourfunction')) {
return LogUtil::registerError('Could not register login hook');
}
...
if (!pnModUnregisterHook('zikula', 'login', 'GUI', 'YourModule', 'user', 'yourfunction')) {
return LogUtil::registerError('Could not unregister login hook');
}
Then you can implement the function in YourModule/pnuser.php or YourModule/pnuser/yourfunction.php like below:
Code
/**
* login hook functionality for hooking into login process
*/
function YourModule_user_yourfunction($args)
{
$dom = ZLanguage::getModuleDomain('YourModule');
if ((!isset($args['objectid'])) ||
(!isset($args['extrainfo']))) {
return LogUtil::registerError(__('Error! Could not do what you wanted. Please check your input.', $dom));
}
$userid = $args['objectid'];
// Example: doing a custom redirect for user 123
if ($userid == 123) {
pnRedirect(pnModURL('YourModule', 'user', 'yourotherfunction'));
pnShutdown();
}
// do normal redirect controlled by users module
}
--
Guite | ModuleStudio -
- Rank: Developer
- Registered: Jun 16, 2003
- Posts: 1915
is there any documentation of all the available hooks? -
- Rank: Developer
- Registered: Dec 31, 1969
- Last visit: Jun 01, 2010
- Posts: 6840
Not for the login-hooks, I was never able to get the information to create even the framework for the docs, so I gave up after awhile. Looks like what we have there may help me finish FirstVisit at least.
That first code block goes in the pninit.php file correct Axel?
edited by: HalbrookTech, datetimebrief
--
Home Page | Find on Facebook | Follow on Twitter
-
- Rank: Team Member
- Registered: Jan 19, 2003
- Posts: 432
Yes, that is the common use case. In general Zikula allows developers to do that everywhere though.
--
Guite | ModuleStudio -
- Rank: Softmore
- Registered: Nov 30, 2005
- Last visit: May 07, 2010
- Posts: 104
-
- Rank: Team Member
- Registered: Jan 19, 2003
- Posts: 432
-
- Rank: Softmore
- Registered: Nov 30, 2005
- Last visit: May 07, 2010
- Posts: 104
I just tried this and it does not seem to be executing my function.
Code
function flashchat_user_loginhook($args)
{
if ((!isset($args['objectid'])) ||
(!isset($args['extrainfo']))) {
return LogUtil::registerError (_MODARGSERROR);
}
$userid = $args['objectid'];
pnModDBInfoLoad('flashchat');
pnModAPIFunc('flashchat', 'user', 'delchats', array('uid' => $userid));
// do normal redirect controlled by users module
}
And here is the API function
Code
function flashchat_userapi_delchats($args)
{
$uid = isset($args['uid']) ? $args['uid'] : null;
if (!($uid) || !is_numeric($uid)) {
return LogUtil::registerError (_MODARGSERROR);
}
// Security check - important to do this as early on as possible to
// avoid potential security holes or just too much wasted processing
if (!SecurityUtil::checkPermission('flashchat::', '::', ACCESS_OVERVIEW)){
return LogUtil::registerPermissionError();
}
$pntable = pnDBGetTables();
$flashchatColumn = $pntable['flashchat_column'];
$where = "$flashchatColumn[uid] = '" . (int)$uid . "'";
$res = DBUtil::deleteWhere('flashchat', $where);
if (!$res) {
return false;
}
return true;
} -
- Rank: Team Member
- Registered: Jan 19, 2003
- Posts: 432
Add a
Code
before
Code
$userid = $args['objectid'];
to see if it gets executed.
--
Guite | ModuleStudio -
- Rank: Softmore
- Registered: Nov 30, 2005
- Last visit: May 07, 2010
- Posts: 104
-
- Rank: Team Member
- Registered: Jan 19, 2003
- Posts: 432
If you use the pnuserapi.php you have to register the hook for API. If you register the hook for GUI you have to use a pnuser.php function instead. See the third parameters in my first post above.
--
Guite | ModuleStudio -
- Rank: Softmore
- Registered: Nov 30, 2005
- Last visit: May 07, 2010
- Posts: 104
-
- Rank: Softmore
- Registered: Nov 30, 2005
- Last visit: May 07, 2010
- Posts: 104
I don't see anywhere in the Core where a hook is created for login or logout... so I think this doesn't work.
- Moderated by:
- Support
