Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

c# - Create Umbraco Member with Group

I'm looking to create an Umbraco member with a Member Group upon registration using Umbraco Forms. I've tried a few different solutions, but couldn't come up with anything solid while going through the documentation, here is what I have so far.

Create User Workflow

using Serilog;
using System;
using System.Collections.Generic;
using Umbraco.Forms.Core;
using Umbraco.Forms.Core.Data.Storage;
using Umbraco.Forms.Core.Enums;
using Umbraco.Forms.Core.Persistence.Dtos;
using Umbraco.Forms.Core.Services;
using Umbraco.Core.Logging;
using Umbraco.Core.Composing;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
 
namespace PROJECT.Workflows
{
    public class CreateUser : WorkflowType
    {   
        private IMemberService _memberService;
 
        public CreateUser(IMemberService memberService)
        {
            this.Id = new Guid("9335a73c-d13c-49ac-8aa4-a1f99419d1f7");
            this.Name = "Create User";
            this.Description = "Create User Workflow for PROJECT";
            this.Icon = "icon-chat-active";
            this.Group = "Services";     
 
            _memberService = memberService;                 
        }
        public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
        {
            var emailAddress = record.ValueAsString("emailAddress");
 
            var member = _memberService.CreateMemberWithIdentity("username", emailAddress, "name", "aliasOfMemberType");
            _memberService.AssignRole(member.Username, "Main Client");
            _memberService.Save(member);
            _memberService.SavePassword(member, "password");
 
            return WorkflowExecutionStatus.Completed;
        }
 
        public override List<Exception> ValidateSettings()
        {
            return new List<Exception>();
        }
    }
}

My registration form only has two fields, email, and password. I want to register the user and assign the "Main Client" member group to that user.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...