Jump to content


Photo

Module: Login Notifier


  • Please log in to reply
22 replies to this topic

#1 ryan

ryan

    Reiska

  • Administrators
  • 7,783 posts
  • 6526

  • LocationAtlanta, GA

Posted 29 September 2011 - 10:04 AM

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/r...n/LoginNotifier

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

Attached Thumbnails

  • LoginNotifier.png


#2 apeisa

apeisa

    Hero Member

  • Moderators
  • 3,151 posts
  • 1697

  • LocationVihti, Finland

Posted 29 September 2011 - 10:13 AM

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

#3 Sevarf2

Sevarf2

    Sr. Member

  • Members
  • PipPipPipPip
  • 373 posts
  • 48

  • LocationBratislava

Posted 29 September 2011 - 10:31 AM

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.

#4 Soma

Soma

    Hero Member

  • Moderators
  • 5,040 posts
  • 3792

  • LocationSH, Switzerland

Posted 29 September 2011 - 02:03 PM

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

@somartist | modules created | support me, flattr my work flattr.com


#5 ryan

ryan

    Reiska

  • Administrators
  • 7,783 posts
  • 6526

  • LocationAtlanta, GA

Posted 29 September 2011 - 02:29 PM

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




#6 Soma

Soma

    Hero Member

  • Moderators
  • 5,040 posts
  • 3792

  • LocationSH, Switzerland

Posted 29 September 2011 - 02:45 PM

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.

@somartist | modules created | support me, flattr my work flattr.com


#7 Soma

Soma

    Hero Member

  • Moderators
  • 5,040 posts
  • 3792

  • LocationSH, Switzerland

Posted 29 September 2011 - 03:32 PM

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

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

@somartist | modules created | support me, flattr my work flattr.com


#8 ryan

ryan

    Reiska

  • Administrators
  • 7,783 posts
  • 6526

  • LocationAtlanta, GA

Posted 30 September 2011 - 11:13 AM

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.

#9 lpa

lpa

    Distinguished Member

  • Members
  • PipPipPip
  • 79 posts
  • 5

  • LocationHelsinki, Finland

Posted 29 March 2012 - 12:12 AM

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

#10 ryan

ryan

    Reiska

  • Administrators
  • 7,783 posts
  • 6526

  • LocationAtlanta, GA

Posted 29 March 2012 - 08:54 AM

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.

#11 MarcC

MarcC

    Sr. Member

  • Members
  • PipPipPipPip
  • 315 posts
  • 107

  • LocationCalifornia

Posted 31 March 2012 - 10:18 AM

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.

I'm a freelance, processwire-using web designer based in california. work site | personal site | visuals


#12 AnotherAndrew

AnotherAndrew

    Sr. Member

  • Members
  • PipPipPipPip
  • 168 posts
  • 27

Posted 31 March 2012 - 07:55 PM

This would be awesome if it could return the IP address of the user that logged in. Anyone know how to do this?

#13 Michael Murphy

Michael Murphy

    Distinguished Member

  • Members
  • PipPipPipPip
  • 101 posts
  • 66

  • LocationBasel, Switzerland

Posted 01 April 2012 - 02:19 AM

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

#14 alanfluff

alanfluff

    Hero Member

  • Members
  • PipPipPipPipPip
  • 577 posts
  • 186

  • LocationOttawa, Canada

Posted 17 September 2012 - 09:31 AM

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

#15 alanfluff

alanfluff

    Hero Member

  • Members
  • PipPipPipPipPip
  • 577 posts
  • 186

  • LocationOttawa, Canada

Posted 17 September 2012 - 09:43 AM

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

#16 ryan

ryan

    Reiska

  • Administrators
  • 7,783 posts
  • 6526

  • LocationAtlanta, GA

Posted 17 September 2012 - 07:35 PM

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.

#17 alanfluff

alanfluff

    Hero Member

  • Members
  • PipPipPipPipPip
  • 577 posts
  • 186

  • LocationOttawa, Canada

Posted 18 September 2012 - 04:47 AM

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

#18 celfred

celfred

    Full Member

  • Members
  • PipPipPip
  • 54 posts
  • 34

  • LocationFrance

Posted 14 January 2013 - 02:42 PM

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



#19 ryan

ryan

    Reiska

  • Administrators
  • 7,783 posts
  • 6526

  • LocationAtlanta, GA

Posted 15 January 2013 - 09:08 AM

Good idea. I've added a role exclusion feature to the module's configuration so you can check boxes next to any roles you want excluded from sending notifications.

https://github.com/r...4270a23866626e8



#20 celfred

celfred

    Full Member

  • Members
  • PipPipPip
  • 54 posts
  • 34

  • LocationFrance

Posted 15 January 2013 - 02:09 PM

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 !






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users