Getting the full Registration Information in the OnRegistered event

Hi,

I am attempting to get the full registration information passed in to the Register Service. I created a new event class like in the samples I found, but I am only getting the IAuthSession values and not all of the registration information that is available:

public class CustomRegistrationAuthEvents : AuthEvents
{
        /// <inheritdoc />
   public override void OnRegistered(IRequest httpReq, IAuthSession session, IServiceBase registrationService)
   {
        base.OnRegistered(httpReq, session, registrationService);
        var u = session.ConvertTo<AuthUserSession>();
    }
}

I check out the src for the service and it looks like its converting it to just the authentication information. Is there anyway to get all of the registration information without resorting to writing a custom registration service? It would make sense that all the information for the registration would be available on the OnRegistered event (Company, PhoneNumber etc).

FYI for proper formatting you should embed C# code using GitHub flavored markdown syntax, e.g:

```csharp
// C# code here
```

You can get any information from the HTTP Request from the IRequest API, e.g:

var myInfo = httpReq.FormData["myInfo"];

Or if you just wanted the Register Request DTO from IRequest.Dto, e.g:

if (httpReq.Dto is Register dto) {
}

Note if preferred you can override the OnRegistered handler in your Custom UserSession instead.

Thank you for your response, I appreciate it. I did as you said, and I am still not getting the values. I took the liberty of just converting the object into a JSON response so I can see it in the Terminal window of Visual Code.
Here is my form:

Here is the actual request header information:

Here is the payload:

And here is what is coming through to the OnRegistered event:

  Request starting HTTP/1.1 POST http://localhost:5000/register application/json;charset=UTF-8 185

Dto Value
{“UserName”:“datag”,“FirstName”:“data”,“LastName”:“g”,“DisplayName”:null,“Email”:“datag@datag.com”,“Password”:“password1”,“ConfirmPassword”:“password1”,“AutoLogin”:null,“Continue”:null,“ErrorView”:null}
Form Data
[]

When I use this code:

public override void OnRegistered(IRequest httpReq, IAuthSession session, IServiceBase registrationService)
{
base.OnRegistered(httpReq, session, registrationService);
var dtoValue = httpReq.Dto as Register;
Console.WriteLine(“Dto Value”);
Console.WriteLine(Helpers.Helper.Dump(dtoValue));
Console.WriteLine(“Form Data”);
Console.WriteLine(Helpers.Helper.Dump(httpReq.FormData));
}

Please advise.

EDIT

Here is what the session object is returning:
{“ReferrerUrl”:null,“Id”:“5o0znLNf45eXrMnIUt5Z”,“UserAuthId”:“1”,“UserAuthName”:null,“UserName”:“datag”,“TwitterUserId”:null,“TwitterScreenName”:null,“FacebookUserId”:null,“FacebookUserName”:null,“FirstName”:“data”,“LastName”:“g”,“DisplayName”:null,“Company”:null,“Email”:“datag@datag.com”,“PrimaryEmail”:“datag@datag.com”,“PhoneNumber”:null,“BirthDate”:null,“BirthDateRaw”:null,“Address”:null,“Address2”:null,“City”:null,“State”:null,“Country”:null,“Culture”:null,“FullName”:null,“Gender”:null,“Language”:null,“MailAddress”:null,“Nickname”:null,“PostalCode”:null,“TimeZone”:null,“RequestTokenSecret”:null,“CreatedAt”:“2019-04-24T01:26:43.3339518Z”,“LastModified”:“2019-04-24T01:26:43.3339518Z”,“Roles”:[],“Permissions”:[],“IsAuthenticated”:false,“FromToken”:false,“ProfileUrl”:null,“Sequence”:null,“Tag”:0,“AuthProvider”:null,“ProviderOAuthAccess”:[],“Meta”:null,“Audiences”:null,“Scopes”:null,“Dns”:null,“Rsa”:null,“Sid”:null,“Hash”:null,“HomePhone”:null,“MobilePhone”:null,“Webpage”:null,“EmailConfirmed”:null,“PhoneNumberConfirmed”:null,“TwoFactorEnabled”:null,“SecurityStamp”:null,“Type”:null}

That’s because you’re sending it as JSON, not as HTML Form POST urlencoded parameters.

So you’d need to re-read the JSON body in order to parse a copy of the JSON payload to deserialize it yourself, but the HTTP Request stream is forward-only by default so you’d need to buffer the Request Stream.

At which point you may want to consider taking a copy of the RegisterService.cs and use a custom Register DTO that includes your entire Typed Request DTO that you’re sending.

Ah, Okay so I need to send it as a form post. I will try that and see if that works. Again, thank you for responding I appreciate it.

That was a success, thank you for your help.

1 Like