We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4385
    • 372 Posts
    I am trying to get an email whenever a web user logs in. I thought I could just make a plugin and check off OnWebLogin under Web Access Service Events
    I tried something simple, I didn’t add the email code yet. Or maybe add the to a list. I could modify the login snippet, but I would have to modify for each update or snippet.

    Login Notification -- plugin test

    $username = $modx->db->escape($username);
    $email = $modx->db->escape($email);
      
    $output = ($username . " - " . $email);
    
    $modx->Event->output($output);
    
      DropboxUploader -- Upload files to a Dropbox account.
      DIG -- Dynamic Image Generator
      gus -- Google URL Shortener
      makeQR -- Uses google chart api to make QR codes.
      MODxTweeter -- Update your twitter status on publish.
    • Before you can use an Event object, you have to instantiate one. See this on how to make a plugin.
      http://www.sottwell.com/how-plugins-work.html
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 4385
        • 372 Posts
        Thanks Susan!

        // Get a reference to the event
        $e = & $modx->Event;
        
        $username = $modx->getLoginUserName();
        
        switch ($e->name) {
           case "OnWebLogin":
        		$ourFileName = "file.txt";		
        		$path = $modx->config['base_path'].$ourFileName;
        		
        		$ourFileHandle = fopen($path, 'a');
        		fwrite($ourFileHandle, $username . "\t" . date("l dS \of F Y h:i:s A",time()) . "\n");
        		fclose($ourFileHandle);
            break;
                   default :
                        return; // stop here - this is very important.
                        break;
        }
        


        I am going to write it to a file. Then use a timed snippet execution (cronX, which I just made today) to send the log once a week.
          DropboxUploader -- Upload files to a Dropbox account.
          DIG -- Dynamic Image Generator
          gus -- Google URL Shortener
          makeQR -- Uses google chart api to make QR codes.
          MODxTweeter -- Update your twitter status on publish.