Jump to content
ryan

Login Notifier

Recommended Posts

Provides ability to send an email, ping a URL or save a log entry when a login occurs to ProcessWire.

Works with all logins. So if you've made your own login form on the front end of your site, this will still work with it.

Download at:
https://github.com/ryancramerdesign/LoginNotifier

After you click the install button in Admin > Modules, you will get a configuration screen that looks like the following (attached).
 

post-1-132614279205_thumb.png

  • Like 1

Share this post


Link to post
Share on other sites

Great job Ryan! Looks like a interesting module - will install and test this soon.

Share this post


Link to post
Share on other sites

Very nice, i will try.

Suggestion: could be really nice if this module can save every login as pw page (choosing the parent page as option)...so an admin can control anytime all logins in his website.

Share this post


Link to post
Share on other sites

Ryan did it again. :) great addition! would it be to log date time too  ?

Share this post


Link to post
Share on other sites

Thanks guys, hope you enjoy it.

Suggestion: could be really nice if this module can save every login as pw page (choosing the parent page as option)...so an admin can control anytime all logins in his website.

I like the way you are thinking! Sounds like an interesting possibility, but a much bigger project. :) Though if we were to do something like this in the future, I think it would be a separate Process module managing it's own data rather than creating new pages on every login. My thinking is the user logins are much more dynamic and short-lived and it may be best for the implementation to reflect that with a far simpler data type.

would it be to log date time too  ?

There is actually a {datetime} tag that you can use in it. It's not documented with the module because the date/time is already a component of any email, and the log already records date/time whether you specify it or not. So the only place it might be useful is in the ping URL... though it's probably better for the ping URL to get it's time from the server rather than the request. But I didn't realize all this until after I'd added the {datetime}, so it should be there if you want it. :)

Share this post


Link to post
Share on other sites

Ryan, good to know, that was were I was coming from, but I wasn't sure if the log (sent from phone so haven't actually looked deeper into it nor tested) saves already date time, I wasn't sure.

As for the pinging, yes I would also do that on the requested php side, no need to hand that over url get variable.

I agree with having saved pages is thinking PW way, but in this scenario better have a different way of storing the data. How about  something using file system with saved logfiles? Maybe not THE idea but just came to mind.

Share this post


Link to post
Share on other sites

Would it be good to have multiple emails comma seperated possibility?

EDIT: installed, tested, so far works as expected! thanks Ryan

Share this post


Link to post
Share on other sites

Good call, I'll put multiple emails on the to-do list.

This module may seem like a lot of effort for something rather small, but this is a feature a client wanted so it got built… and figured others may have run into the need before too.

Share this post


Link to post
Share on other sites

How about Logout Notifier? Or an option to log both logins and logouts at least to a log file.

Share this post


Link to post
Share on other sites

I'm not sure if the logout notifier is worth doing because a large number (or most?) logouts are due to session expiration. For example, user logged in, made some edits, then left. In such a case, the user never performs a logout. But their session expires later that day when PHP's garbage collector comes along and cleans out old session files. Unless the user continues using the site till the end of time, it's safe to assume that every active login will end at some point (whether by their action or by PHP's). But if you still want to track actual logouts, you can. PW provides a hook that you can use: $session->logout. In the LoginNotifier module, I think that you could duplicate the login hook in that module, and copy it verbatim to make the logout hook (replacing 'login' with 'logout), and I believe it should perform what you want. Just keep in mind that you won't see near as many logouts as logins, since not everyone clicks the logout link when they are done.

Share this post


Link to post
Share on other sites

This is great, Ryan. I admin another site that has a "Failed login attempt" check -- it emails me the IP address and username when an incorrect password or username is entered. This has been really nice because after a few failed attempts I can call the client and offer to help. :-) And of course security reasons--it's a financial services site. So if you do add to this module in the future, such a feature would be awesome.

Share this post


Link to post
Share on other sites

was just playing with this module last night (very useful thanks!) - to add the users IP, copy this line into the email body or email subject field

IP:  {REMOTE_ADDR}

you can find a list of all the other PHP server variables which can be used here :

http://php.net/manua...bles.server.php

  • Like 2

Share this post


Link to post
Share on other sites

Just found this module by accident (I must read through the list), excellent, thanks Ryan and Co.!

Share this post


Link to post
Share on other sites

@Ryan, I just noticed that if in config.php I have

$config->debug = true;

then whenever I submit a change to the settings of the LoginNotifier I see at the top of the rendered page:

Notice: Undefined variable: this in /my-test-website.alan/site/site/modules/LoginNotifier/LoginNotifier.module on line 197

I assume this is nothing to be worried about and just a variable that has not been established before it's used (like I know what I am typing there... I know so little PHP ;)) Anyway I just thought I should let you know in case it's important.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks Alan. Funny I thought I'd already fixed this a long long time ago. And actually I did, but turns out I just hadn't pushed it to GitHub. But went ahead and did that so should be fixed now.

Share this post


Link to post
Share on other sites

Welcome Ryan and thanks for pushing the already tidied code back so quickly.

  • Like 1

Share this post


Link to post
Share on other sites

Hi there,

I've just come across this module and it worked as expected. Thanks a lot.

I changed a little thing though, for my personal use, and I don't know if this could be of any interest for someone else. (It's the very first time I look inside a module...)

Line 72 :

if(!$user) return;

I changed to :

if(!$user || $user->isSuperuser()) return;

My point was that I received emails even when I was logging in my site and since it's a very little amateur site with _let's admit_ no traffic (for the moment ;-) ), I kept receiving mails indicating I logged in... Now, with my little tweak, I get emails only when other members log in which is what I wanted ;-)

Now here's my thought : I thought some kind of list of roles (or users?) could be added to the settings page of the module so one could only check (or uncheck) some roles to be ignored from keeping a record (either mail or log entries) without actually touching the module code.

I don't know if I'm being very clear there... and actually I have no idea if this kind of idea is shared... But if it is, I would be glad to try and see what I can do to include such a feature in the module, even though I'm starting from very low considering my developer skills (but I'm eager to learn and improve).

Thanks for letting me know if you think that would be a loss of time ! (Or if I did a mistake changing my little line 72).

Share this post


Link to post
Share on other sites

Waow! That was quick!

Well, what can I say except THANKS!

Why did you exclude 'guest' role in the list? I guess I can understand that the Login Notifier module's point is to notify the 'guests' login actions, but why not let people decide? i can imagine someone interested in receiving mails only if a paricular role logs in (but not 'guest').

Anyway, that's just a supposition from my side. Your work is just fine for my use as it is so thank you very much.

Now that I don't have to try and do that myself (which would have taken me a lot more time, definitely!), I'll look at your code to see what i should have done ;-) Thanks in advance for the lesson !

Share this post


Link to post
Share on other sites
Why did you exclude 'guest' role in the list? I guess I can understand that the Login Notifier module's point is to notify the 'guests' login actions, but why not let people decide?

This is because all users are required to have the guest role. If the guest role were checked, the LoginNotifier would never send any notifications.

Share this post


Link to post
Share on other sites

Awesome update to this module. Thanks celfred and ryan!

  • Like 1

Share this post


Link to post
Share on other sites

Login Notifier doesn't work together with ProcessLogger. ProcessLogger only accept filenames in lowercase letters. It worked after changing this in LoginNotifier:

    /**
     * Save log entry
      *
     */
    protected function saveLog(User $user) {
        $log = new FileLog($this->config->paths->logs, strtolower(get_class($this)));
        $log->save($this->parseTags($this->logEntry, $user));
    }

Furthermore a filename with numbers like '404.txt' doesn't render as expected in ProcessLogger.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By bernhard
      --- Please use RockFinder3 ---
    • By MoritzLost
      Cacheable Placeholders
      This module allows you to have pieces of dynamic content inside cached output. This aims to solve the common problem of having a mostly cacheable site, but with pieces of dynamic output here and there.  Consider this simple example, where you want to output a custom greeting to the current user:
      <h1>Good morning, <?= ucfirst($user->name) ?></h1> This snippet means you can't use the template cache (at least for logged-in users), because each user has a different name. Even if 99% of your output is static, you can only cache the pieces that you know won't include this personal greeting. A more common example would be CSRF tokens for HTML forms - those need to be unique by definition, so you can't cache the form wholesale.
      This module solves this problem by introducing cacheable placeholders - small placeholder tokens that get replaced during every request. The replacement is done inside a Page::render hook so it runs during every request, even if the response is served from the template cache. So you can use something like this:
      <h1>Good morning, {{{greeting}}}</h1> Replacement tokens are defined with a callback function that produces the appropriate output and added to the module through a simple hook:
      // site/ready.php wire()->addHookAfter('CachePlaceholders::getTokens', function (HookEvent $e) { $tokens = $e->return; $tokens['greeting'] = [ 'callback' => function (array $tokenData) { return ucfirst(wire('user')->name); } ]; $e->return = $tokens; }); Tokens can also include parameters that are parsed and passed to the callback function. There are more fully annotated examples and step-by-step instructions in the README on Github!
      Features
      A simple and fast token parser that calls the appropriate callback and runs automatically. Tokens may include multiple named or positional parameters, as well as multi-value parameters. A manual mode that allows you to replace tokens in custom pieces of cached content (useful if you're using the $cache API). Some built-in tokens for common use-cases: CSRF-Tokens, replacing values from superglobals and producing random hexadecimal strings. The token format is completely customizable, all delimiters can be changed to avoid collisions with existing tag parsers or template languages. Links
      Github Repository & documentation Module directory (pending approval) If you are interested in learning more, the README is very extensive, with more usage examples, code samples and usage instructions!
    • By Craig
      I've been using Fathom Analytics for a while now and on a growing number of sites, so thought it was about time there was a PW module for it.
      WayFathomAnalytics
      WayFathomAnalytics is a group of modules which will allow you to view your Fathom Analytics dashboard in the PW admin panel and (optionally) automatically add and configure the tracking code on front-end pages.
      Links
      GitHub Readme & documentation Download Zip Modules directory Module settings screenshot What is Fathom Analytics?
      Fathom Analytics is a simple, privacy-focused website analytics tool for bloggers and businesses.

      Stop scrolling through pages of reports and collecting gobs of personal data about your visitors, both of which you probably don't need. Fathom is a simple and private website analytics platform that lets you focus on what's important: your business.
      Privacy focused Fast-loading dashboards, all data is on a single screen Easy to get what you need, no training required Unlimited email reports Private or public dashboard sharing Cookie notices not required (it doesn't use cookies or collect personal data) Displays: top content, top referrers, top goals and more
    • By daniels
      This is a lightweight alternative to other newsletter & newsletter-subscription modules.
      You can find the Module in the Modules directory and on Github
      It can subscribe, update, unsubscribe & delete a user in a list in Mailchimp with MailChimp API 3.0. It does not provide any forms or validation, so you can feel free to use your own. To protect your users, it does not save any user data in logs or sends them to an admin.
      This module fits your needs if you...
      ...use Mailchimp as your newsletter / email-automation tool ...want to let users subscribe to your newsletter on your website ...want to use your own form, validation and messages (with or without the wire forms) ...don't want any personal user data saved in any way in your ProcessWire environment (cf. EU data regulation terms) ...like to subscribe, update, unsubscribe or delete users to/from different lists ...like the Mailchimp UI for creating / sending / reviewing email campaigns *I have only tested it with PHP 7.x so far, so use on owners risk
      EDIT:
      Since 0.0.4, instructions and changelog can be found in the README only. You can find it here  🙂
      If you have questions or like to contribute, just post a reply or create an issue or pr on github, thanks!
    • By MoritzLost
      Sorry for the convoluted title. I have a problem with Process modules that define a custom page using the page key through getModuleInfo (as demonstrated in this excellent tutorial by @bernhard). Those pages are created automatically when the module is installed. The problem is that the title of the page only gets set in the current language. That's not a problem if the current language (language of the superuser who is installing the module) is the default language; if it isn't, the Process page is missing a title in the default language. This has the very awkward effect that a user using the backend in the default language (or any other language) will see an empty entry in the setup menu:

      This screenshot comes from my Cache Control module which includes a Process page. Now I realize the description sounds obscure, but for us it's a common setup: We a multiple bilingual sites where the default language is German and the second language is English. While the clients use the CMS in German, as a developer I prefer the English interface, so whenever I install a Process module I get this problem.
      As a module author, is there a way to handle this situation? I guess it would be possible to use post-installation hooks or create the pages manually, but I very much prefer the declarative approach. The page title is already translatable (through the __ function), but of course at the time of installation there is no translation, and as far as I'm aware it's not possible to ship translations with a module so they are used automatically. Could this situation be handled better in the core? I would prefer if the module installation process would always set the title of the Process page in the default language, instead of the language of the current user.
×
×
  • Create New...