Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Max Mumford 266 posts 293 karma points
    Jul 04, 2012 @ 16:22
    Max Mumford
    0

    Executing some code after a member has been created

    Hi all,

    I need to add some rows to a custom database after a member has been created, editted and deleted through the Umbraco API or through the backend interface.

    I have a faint memory of being able to drop a .cs file into the app_data file with some methods overridden to hook into specific events...?

    How would I go about doing this? Is there any documentation of which method scan be overridden?

    Thanks,
    Max.

  • Max Mumford 266 posts 293 karma points
    Jul 04, 2012 @ 16:24
    Max Mumford
    0

    p.s. I am using the asp.net membership provider, not the out-of-the-box umbraco one and not a custom one.

  • Max Mumford 266 posts 293 karma points
    Jul 04, 2012 @ 16:46
    Max Mumford
    0

    Dont worry I solved it - I created a new class project, created a class that extended System.Web.Security.SqlMembershipProvider, overrode the create, update and delete members, called their superclasses, made the changes to my other database that I needed and returned the object that the super constructor gave me:

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
     
    using System.Web;
    using System.Web.Security;
     
    namespace MembershipProvider
    {
        public class Members : System.Web.Security.SqlMembershipProvider
        {
            public override System.Web.Security.MembershipUser CreateUser(string username, string password, string email, string passworrQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out System.Web.Security.MembershipCreateStatus status)
            {
                // create the user in the aspnet membership provider
                MembershipUser m = base.CreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, providerUserKey, out status);
                
    // do my stuff
       //......
                return m;
            }
        }
    }

     

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Jul 04, 2012 @ 16:55
    Michael Latouche
    1

    Hi Max,

    Here you have a list of all the events you can hook up to: http://our.umbraco.org/wiki/reference/api-cheatsheet/using-applicationbase-to-register-events/overview-of-all-events

    Cheers,

    Michael.

  • Max Mumford 266 posts 293 karma points
    Jul 06, 2012 @ 10:40
    Max Mumford
    0

    Thats great Michael, thanks. And to hook into these I just need to create a class which extends a namespace, then override the method I want to hook into? Then drop the .cs file into the app_data folder?

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Jul 06, 2012 @ 11:20
    Michael Latouche
    1

    Hi Max,

    Basically you need to create a class that inherits from ApplicationBase, and then in the constructor you hook up whatever event you want. So your class should look something like this:

    namespaceMemberEvent
    {
       
    publicclassPageEvent:ApplicationBase  
       
    {

     
           
    publicPageEvent(){
    umbraco.cms.businesslogic.member.Member.AfterSave += new MemberAfterSaveEvent(....);
    umbraco.cms.businesslogic.member.Member.AfterDelete += new MemberAfterDeleteEvent(....);
    ...           }

    void MemberAfterSaveEvent(....)
    {
    /* Your code here */
    }

    void MemberAfterDeleteEvent(....)
    {
    /* Your code here */
    }

    You can see a full example on this thread I just saw today : http://our.umbraco.org/forum/developers/extending-umbraco/33027-Page-Event-Button-In-Members-Sectio-%28editmemberaspx%29?p=0#comment121448

    I'm not 100% sure but I think you will need to put this in a separate assembly that you then copy into your bin folder. I don't think it would work if it resides in app_data.

    Hope this helps.

    Cheers,

    Michael.

     

  • Max Mumford 266 posts 293 karma points
    Jul 06, 2012 @ 13:38
    Max Mumford
    0

    Great, thanks very much for your help.

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Jul 06, 2012 @ 13:51
    Michael Latouche
    0

    You're welcome :-)

    Good luck!

    Cheers,

    Michael.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies