How to change the authentication provider of the Register/Login actions?

Topics: Core, General, Writing modules
Jan 13, 2013 at 11:56 PM

Hi,

I'd like to ask, if anyone knows:

  • When user registered, how to store their registration details (username, password, email etc.) into a custom database (via a web service)?
  • Also, when a user login, how to use that custom database to authenticate the user?

 

Many thanks,

Jim

Jan 14, 2013 at 7:45 AM

In a custom module override MembershipService from the Orchard.Users module.  

[OrchardSuppressDependency("Orchard.Users.Services.MembershipService")]
public class MembershipService : IMembershipService {
   //and so on implementing the service...

Jan 16, 2013 at 12:18 PM
BrandonJoyce wrote:

In a custom module override MembershipService from the Orchard.Users module.  

 

[OrchardSuppressDependency("Orchard.Users.Services.MembershipService")]
public class MembershipService : IMembershipService {
   //and so on implementing the service...

 

Thanks Brandon,

Do you have an example about how this function is implemented?

 

Jan 16, 2013 at 5:03 PM

A good ressource for examples are the authentication modules that are on the gallery. I'm sure you can figure out how to do it just by reading the code, it's pretty straightforward. And last but not least there is the default MembershipService that ships with Orchard. I assume it shouldn't be to hard to implement a custom service when checking out what's going on in there and how the other modules work.

 

Best regards

Jay

Jan 16, 2013 at 5:59 PM

Thanks Jay,

I think my problem is, I'm not familiar with Orchard Class, so within the Default MemberShipService class, I'm not sure which part(s) can be removed/replace etc.

It would be good to see an example about how to override this class.

 

public class MembershipService : IMembershipService {
        private readonly IOrchardServices _orchardServices;
        private readonly IMessageManager _messageManager;
        private readonly IEnumerable<IUserEventHandler> _userEventHandlers;
        private readonly IEncryptionService _encryptionService;

        public MembershipService(IOrchardServices orchardServices, IMessageManager messageManager, IEnumerable<IUserEventHandler> userEventHandlers, IClock clock, IEncryptionService encryptionService) {
            _orchardServices = orchardServices;
            _messageManager = messageManager;
            _userEventHandlers = userEventHandlers;
            _encryptionService = encryptionService;
            Logger = NullLogger.Instance;
            T = NullLocalizer.Instance;
        }

        public ILogger Logger { get; set; }
        public Localizer T { get; set; }

        public MembershipSettings GetSettings() {
            var settings = new MembershipSettings();
            // accepting defaults
            return settings;
        }