bp123
bp123

Reputation: 3417

Alert the administrator of new user

If this question should be posted somewhere else please let me know and I'll move it. I would like to create a process to alert the administrator of my site that a new account has been registered. This alert will prompt the administrator because they need to check the new users account.

My initial thought was to send an email to the administrator of the site however on further thought this has the potential to become unmanageable. Is there a better way or 'best practice' for doing this. For instance, third party software (eg. mixpanel) to manage things like this.

Upvotes: 0

Views: 42

Answers (2)

Ankur Soni
Ankur Soni

Reputation: 6018

You can insert the code to send email inside upsertNewUser. Below is the brief demo to send the email(I am assuming that you have done a prior hands-on on email package):

function upsertNewUser(id, fields){ 
    watch_new_users.upsert(id,{ fields });
    Email.send({
               to: "[email protected]",
               from: "email_ID",
               subject: "Example Email",
               html: SSR.render( 'htmlEmail', somedata )
});
}

If you desire the code in depth, I have already answer one of the questions on Email package use with HTML

Upvotes: 1

Ankur Soni
Ankur Soni

Reputation: 6018

  1. Since administrator has to be notified of new user account added, if you are not interested in notifying via Email, SMS etc you can simple put "_id" of newly created user account to some new table, I call that table "watch_new_users".
  2. You can simply call the observe method on the "users" table(or whatever table you have specified) to make an entry into the "watch_new user" table.
  3. There are numerous benefits of this.

    a. The process computation and the socket business can be minimised as email bind the socket and releases only when the message is emailed.

    b. You will always have a collection maintained with you with Zero maintainance and can retrieve data as you wish.

    c. You can retrieve the _id of user and view any depth of details you wish by creating administrative templates on clients. Even you can maintain your own dashboard.

Below is the simple code to keep watch of new users added(one benefit is you can even manage the "removed", "changed" events of account user).

project/lib/collections/watch.js

watch_new_users = new Mongo.Collection('watchnewusers');

project/server/publish.js

var allCursor = users.find();

allCursor.observe({
  added: function(id, fields){
        upsertNewUser(id, fields);
  }
});

function upsertNewUser(id, fields){ 
    watch_new_users.upsert(id,{ fields });
}

Upvotes: 1

Related Questions