Jump to content

Login Notifier


ryan
 Share

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
Link to comment
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. :)

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

  • 5 months later...

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.

Link to comment
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.

Link to comment
Share on other sites

  • 5 months later...

@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
Link to comment
Share on other sites

  • 3 months later...

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).

Link to comment
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 !

Link to comment
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.

Link to comment
Share on other sites

  • 2 years later...

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.

Link to comment
Share on other sites

  • 10 months later...

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
 Share

×
×
  • Create New...