1

I am using ServiceStack's SocialBootstrapApi and it contains a class CustomUserSession that I can use to override the OnRegistered method. I want to override it because I am attempting to obtain information about the registration so that I can publish an event that a new user has registered. This handler provides an instance of the RegistrationService that handled the registration but not anything about the registration request itself or the resulting UserAuth instance. For instance, I'd like to get the e-mail address used to register.

    public override void OnRegistered(IServiceBase registrationService)
    {
        base.OnRegistered(registrationService);

        // Ideally, I could do get the registered user's primary e-mail address from the UserAuth instance.
        var primaryEmail = ((RegistrationService) registrationService)
            .UserAuthRepo
            .GetUserAuth(this, null)  //<--- 'this' is a mostly empty session instance
            .PrimaryEmail;
    }

This of course doesn't work because the session instance I'm using for the GetUserAuth call doesn't contain any of the necessary authentication information to be useful for looking up the user's authentication information. So GetUserAuth returns null as you would expect. So how should I go about obtaining this information? Would it be incorrect design for the OnRegistered handler to be passed the UserAuth instance created by the RegistrationService?

    public interface IAuthSession
    {
        ...
        void OnRegistered(IServiceBase registrationService, UserAuth userAuth); // <-- new signature
        ...
    }

That would be convenient! :)

Or perhaps there's another way to go about this?

Thanks in advance.

4

1 回答 1

1

那么我应该如何获取这些信息呢?

您应该能够通过registrationService访问注册请求的所有数据。你只需要做一点挖掘和铸造......

public override void OnRegistered(IServiceBase registrationService)
{
    base.OnRegistered(registrationService);

    var requestContext = (HttpRequestContext)registrationService.RequestContext;
    var dto = ((Registration)requestContext.Dto);
    var primaryEmail = dto.Email;
}

将 OnRegistered 处理程序传递给由 RegistrationService 创建的 UserAuth 实例是否是不正确的设计?

我会把设计决定留给专业人士。上面的代码应该可以工作。选角看起来有点难看,但所有必要的数据都在那里。

我不喜欢入侵 SS,所以我选择通过 dto.UserName 从 UserAuth 集合中选择用户身份验证信息

于 2013-03-19T19:12:33.083 回答