Answers.Body: <p>Login is a CMS event, not a CiviCRM event. This means you can access it readily from a CMS plugin/extension/module ... but not from a CiviCRM extension.</p>
  
  <ul>
  <li>Drupal: <a href="https://api.drupal.org/api/drupal/modules%21user%21user.api.php/function/hook_user_login/7.x" rel="nofollow noreferrer"><code>hook_user_login()</code></a> hook</li>
  <li>Backdrop: <a href="https://api.backdropcms.org/api/backdrop/core%21modules%21user%21user.api.php/function/hook_user_login/1" rel="nofollow noreferrer"><code>hook_user_login()</code></a> hook</li>
  <li>WordPress: <a href="https://codex.wordpress.org/Plugin_API/Action_Reference/wp_login" rel="nofollow noreferrer"><code>wp_login</code> event</a></li>
  <li>Joomla: <a href="https://docs.joomla.org/Plugin/Events/User" rel="nofollow noreferrer"><code>onUserAuthentication</code></a> event (?)</li>
  </ul>
  
  <p>If you wanted to access this from a CiviCRM extension, you'd need to use some event which fires at the time of login. You might be able to identify one using the <a href="https://github.com/fuzionnz/contrib.showallthehooks" rel="nofollow noreferrer"><code>contrib.showallthehooks</code></a> extension to reveal which hooks get fired at the point of login. Might need to check it was going to fire for each of the CMS platforms, since behaviour could vary.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-08T14:22:45.153Z
Answers.Text: You can also use CIVICRM_UF to include a cms-specific .inc file from your main file, just you'd have to write the 4 files, but they'd be minimal and could all call the same function ultimately. E.g. include "onlogin_" . CIVICRM_UF . ".inc";
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-08T20:28:37.843Z
Answers.Text: Demerit - interesting idea, but this wouldn't register those implementations with the CMS would it? (If CiviCRM *didn't* register `civicrm_user_login()` then your extension *could* define same to have it called in Drupal, but it might not be loaded in time, and you'd be risking a collision if CiviCRM or another extension ever incorporating their own definition of the same.)
Answers.UserDisplayName: Chris Burgess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-08T22:57:32.857Z
Answers.Text: Very interesting idea - this is only to displaythe number of unread SMS messages, so ordering isn't so important.
Answers.UserDisplayName: JohnFF
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-09T00:32:59.690Z
Answers.Text: The extension main file doesn't need to be all civi hook functions, it can have other code, so it depends when php/civi itself does a "require" on your main extension file, but I imagine if you just put the "include" or "require" at the top of your main extension file that would do it. My suggestion was mostly taken from what I've seen the hook system in civi itself do. See e.g. the CRM/Utils/Hook subfolder, where it has separate implementations for each CMS, and which one gets used is ultimately based on CIVICRM_UF.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-09T00:41:15.017Z
Answers.Text: Another idea is just display that SMS count on the dashboard, or whatever page is defined as their home page, so it doesn't depend on login, just whatever is their home page. Although if their home page isn't a civi page, then you might not be able to use a civi hook to do that, but then how are you doing the outputting in a generic way?
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-09T02:35:53.273Z
Answers.Text: John - if you're seeking to periodically trigger a notification to a user message, check out how [CiviCRM handles its periodic alerts on the dashboard](https://github.com/civicrm/civicrm-core/blob/648631cd94799e87fe2347487d465b1a7256aa57/CRM/Utils/Check.php#L79). You might be just as happy with "check and notify of new SMS once an hour". Alert via `CRM_Core_Session::setStatus()` and wrap in a function to do this at the appropriate interval; no more need for login hook. As Demerit suggests, this only applies when they are in a CiviCRM page.
Answers.UserDisplayName: Chris Burgess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-08T09:23:01.960Z
Answers.LastActivityDate: 2017-11-08T09:23:01.960Z
Answers.UserDisplayName: Chris Burgess
Body: <p>Is there a good hook for on CiviCRM sign in?</p>
  
  <p>[This is to display a message upon login in a cms-independent extension.]</p>
  
  <p>Thanks,</p>
  
Tags: <extension><hooks>
Title: Is there a hook for on user sign in?
ThreadText: # Is there a hook for on user sign in?
  
  (Asked by: username_0 on 2017-11-08)
  
  Is there a good hook for on CiviCRM sign in?
  
  [This is to display a message upon login in a cms-independent extension.]
  
  Thanks,
  
  **Tags:** extension, hooks
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-11-08. Score: 4
  
  Login is a CMS event, not a CiviCRM event. This means you can access it readily from a CMS plugin/extension/module ... but not from a CiviCRM extension.
  
  * Drupal: [`hook_user_login()`](https://api.drupal.org/api/drupal/modules%21user%21user.api.php/function/hook_user_login/7.x) hook
  * Backdrop: [`hook_user_login()`](https://api.backdropcms.org/api/backdrop/core%21modules%21user%21user.api.php/function/hook_user_login/1) hook
  * WordPress: [`wp_login` event](https://codex.wordpress.org/Plugin_API/Action_Reference/wp_login)
  * Joomla: [`onUserAuthentication`](https://docs.joomla.org/Plugin/Events/User) event (?)
  
  If you wanted to access this from a CiviCRM extension, you'd need to use some event which fires at the time of login. You might be able to identify one using the [`contrib.showallthehooks`](https://github.com/fuzionnz/contrib.showallthehooks) extension to reveal which hooks get fired at the point of login. Might need to check it was going to fire for each of the CMS platforms, since behaviour could vary.
  
  > **Comments:**
  > **username_2**: You can also use CIVICRM_UF to include a cms-specific .inc file from your main file, just you'd have to write the 4 files, but they'd be minimal and could all call the same function ultimately. E.g. include "onlogin_" . CIVICRM_UF . ".inc";  
  > **username_1**: username_2 - interesting idea, but this wouldn't register those implementations with the CMS would it? (If CiviCRM *didn't* register `civicrm_user_login()` then your extension *could* define same to have it called in Drupal, but it might not be loaded in time, and you'd be risking a collision if CiviCRM or another extension ever incorporating their own definition of the same.)  
  > **username_0**: Very interesting idea - this is only to displaythe number of unread SMS messages, so ordering isn't so important.  
  > **username_2**: The extension main file doesn't need to be all civi hook functions, it can have other code, so it depends when php/civi itself does a "require" on your main extension file, but I imagine if you just put the "include" or "require" at the top of your main extension file that would do it. My suggestion was mostly taken from what I've seen the hook system in civi itself do. See e.g. the CRM/Utils/Hook subfolder, where it has separate implementations for each CMS, and which one gets used is ultimately based on CIVICRM_UF.  
  > **username_2**: Another idea is just display that SMS count on the dashboard, or whatever page is defined as their home page, so it doesn't depend on login, just whatever is their home page. Although if their home page isn't a civi page, then you might not be able to use a civi hook to do that, but then how are you doing the outputting in a generic way?  
  > **username_1**: John - if you're seeking to periodically trigger a notification to a user message, check out how [CiviCRM handles its periodic alerts on the dashboard](https://github.com/civicrm/civicrm-core/blob/648631cd94799e87fe2347487d465b1a7256aa57/CRM/Utils/Check.php#L79). You might be just as happy with "check and notify of new SMS once an hour". Alert via `CRM_Core_Session::setStatus()` and wrap in a function to do this at the appropriate interval; no more need for login hook. As username_2 suggests, this only applies when they are in a CiviCRM page.  
  
  ---
  
  