PingCrosby February 2016

Orchard CMS ask for an invite token to link to backend data during registration using workflows only

I am using Orchard CMS v1.9 and want to display a custom registration page to accept the usual username/password/email and an additional token (invite token). The token will be used to match the user to some to custom data on the server.

I have walked through this blog Customizing User Registation With Dynamic Forms And Workflows. But in addition to what is achieved in this blog I want to force a registering user to enter a token. The token is used to lookup data on the server and create a link to the userpart.

Adding the token to the form is not the issue - its the querying and linking the entered token to the backend data and storing it in the userpart that im finding awkward.

  • Is this possible using just workflows - or do i need a custom module? I did not see a custom action that allowed me to match the token and link.

  • Is there a custom module already available that does something
    similar?

Answers


Xceno February 2016

Disclaimer: This approach is currently based on Orchard 1.10 but was initially developed on the 1.9.x branch. It does not rely on Dynamic Forms and Workflows, but I think you could achieve something similar with those modules.

Okay so I ended up building an example module with our approach to extended users / activation system. I stripped out a lot of code, but also let some juicy parts, which aren't directly related to your answer, in it.

First you should check out the UsersController it has the activate actions you are searching for. You may need to extend the orchard LogOn-View and include some GET & POST Actions accordingly.

[AllowAnonymous]
[HttpGet]
public ActionResult Activate(string activationCode)
{
    // validation stuff....

    var viewModel = new CustomUserActivate
    {
        // This is the activationCode you're looking for
        ActivationCode = userFromActivationCode.ActivationCode,
        UserName = userFromActivationCode.User.UserName,
        WelcomeText = userFromActivationCode.WelcomeText,
        Email = userFromActivationCode.User.Email
    };

    return this.View(viewModel);
}

[AllowAnonymous]
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Activate(CustomUserActivate input)
{
    if ( input == null )
    {
        this.ModelState.AddModelError("_form", this.T("The argument cannot be null").Text);
    }

    CustomUserPart customUserPart = null;
    if ( this.ModelState.IsValid )
    {
        customUserPart = this.myService.GetCustomUserByActivationCode(input.ActivationCode);

        if ( customUserPart == null || customUserPart.User == null || customUserPart.User.UserName != input.UserName )
        {
            this.notifier.Add(NotifyType.Error, this.T("The activation failed"));
        }

        if ( string.IsNullOrE 

Post Status

Asked in February 2016
Viewed 2,275 times
Voted 12
Answered 1 times

Search




Leave an answer