Update User fileds and send challenge email in workflow

Topics: Administration
May 8 at 10:32 PM
I am using Orchard v.1.10.0.0
I added a FirstName field to the user Content Definition (without a content part. just added the field to the user)
I am running a workflow for creating a new user.
I am trying to use the Decision activity to update the FirstName field from the custom form field.
  1. What is the syntax i should use?
  2. How do i send the email challenge mail message from the workflow?
May 9 at 9:12 AM
I managed to update the user fields like this:
ContentItem.User.FirstName.Value = "#{FormSubmission.Field:FirstName}";

How do i send the email challenge mail message from the workflow?
Developer
May 9 at 9:19 AM
May 9 at 10:18 AM
sfmskywalker wrote:
It is described in this blog post: http://www.ideliverable.com/blog/customizing-user-registration-and-login-with-dynamic-forms-and-workflows
In this post the the workflow approve the user. I want to manually approve the user but i want the email verification to be sent automatically
Developer
May 9 at 10:28 AM
I see. You can do this by creating a workflow that starts with the UserApproved event and followed by the SendEmail activity.
May 9 at 10:30 AM
sfmskywalker wrote:
I see. You can do this by creating a workflow that starts with the UserApproved event and followed by the SendEmail activity.
Yes, but how do i generate the challenge link for the email verification?
Developer
May 9 at 10:39 AM
Oh, now I understand. Right. So, Instead of the user being approved after clicking that link, you want the email address to be confirmed. I don't believe there is an existing activity for that, so you would have to write one yourself first. It would be similar to the ApproveUserActivity, the differece being that you would set the user's EmailStatus to Approved (see UserService.ValidateChallenge). When you have that in place, the generation of the challenge link would be the same, except you would specify a different signal name.
May 9 at 12:59 PM
sfmskywalker wrote:
Oh, now I understand. Right. So, Instead of the user being approved after clicking that link, you want the email address to be confirmed. I don't believe there is an existing activity for that, so you would have to write one yourself first. It would be similar to the ApproveUserActivity, the differece being that you would set the user's EmailStatus to Approved (see UserService.ValidateChallenge). When you have that in place, the generation of the challenge link would be the same, except you would specify a different signal name.
There is already a mechanism like that. i can send the verify email manually by clicking the "Send challenge E-mail" link in the users screen on the admin.
I just want the workflow to send the user an email with the exact link the admin page is sending. (i hope it si more clear now)

Thanks for your answers
Developer
May 10 at 11:36 AM
That makes sense. I looked into it and found that there is actually a workflow event called UserSentChallengeEmail. Sadly enough, it is only triggered when the user itself registers with the site and their email is not automatically approved.

To work around this, you would need to implement a custom activity called something like SendChallengeEmail that basically implements the code you find in the SendChallengeEmail method of the AdminController of the Users module. Specifically this call:
_userService.SendChallengeEmail(user.As<UserPart>(), nonce => Url.MakeAbsolute(Url.Action("ChallengeEmail", "Account", new { Area = "Orchard.Users", nonce = nonce }), siteUrl));
You would trigger this workflow activity by implementing the Approved event of the IUserEventHandler interface.
You can trigger workflow events using the IWorkflowManager service provided by the Workflows module.

I hope this helps, but let me know if you have any further questions.
Developer
May 10 at 11:38 AM
I looked into it and found that there is actually a workflow event called UserSentChallengeEmail. Sadly enough, it is only triggered when the user itself registers with the site and their email is not automatically approved.
Moreover, this event isn't even invoked with the challenge link, so it would have been useless to you all the same.