Monday, June 29, 2009

Member Action Handlers

Sometimes you need do stuff with members once you've created, delete, changed something. The code below adds two new action handlers 1 when a member is created and one when a members is saved. In version 4 of Umbraco create a new class project and do something like so:




   1:   public class MemberAction : ApplicationBase

   2:      {

   3:   

   4:          public MemberAction() {

   5:          Member.New += new Member.NewEventHandler(Member_BeforeSave);

   6:          Member.AfterSave += new Member.SaveEventHandler(Member_Save);

   7:          }

   8:   

   9:          void Member_BeforeSave(Member sender, NewEventArgs e)

  10:          {

  11:              //do something here

  12:          }

  13:          

  14:          void Member_Save(Member sender, SaveEventArgs e)

  15:           {

  16:              //do something here

  17:             

  18:              //get new member details

  19:               Member m = Member.GetMemberFromEmail(sender.Email);

  20:           }

  21:          

  22:      }

No comments: