Orchard CMS创建用户时重复输入

时间:2012-12-07 08:41:41

标签: orchardcms

我一直在打破这个问题。请看一下这段代码。此代码位于客户控制器中。

    [HttpPost]
    [Themed]
    public ActionResult Register(string email, string password, string confirmPassword, Gender gender, string givenName, string familyName, string insertion, DateTime birthDate) {

        ViewData["PasswordLength"] = MinPasswordLength;
        var shape = _orchardServices.New.Register();

        //1. Initialize new content of customer contenttype
        var customer = _orchardServices.ContentManager.New("Customer");

        if (customer != null) {
            //2. Define the parts that need to be filled
            var userPart = customer.As<UserPart>();
            var customerPart = customer.As<CustomerPart>();

            //3. Let's validate first if the user can be created
            if (userPart!=null) {
                //shape.Customer = _orchardServices.ContentManager.UpdateEditor(customer, this);
                if (!ModelState.IsValid)
                {
                    _orchardServices.TransactionManager.Cancel();
                    return new ShapeResult(this, shape);
                }

                //4. Now validate the user credentials.
                if (ValidateRegistration(email, password, confirmPassword)) {
                    //Now create the actual customer.
                    userPart.UserName = email;
                    userPart.Email = email;
                    userPart.NormalizedUserName = email.ToLowerInvariant();
                    userPart.Record.HashAlgorithm = "SHA1";
                    userPart.Record.RegistrationStatus = UserStatus.Approved;
                    userPart.Record.EmailStatus = UserStatus.Approved;

                    customerPart.CreatedAt = DateTime.UtcNow;
                    customerPart.LastLogonAt = DateTime.UtcNow;
                    _membershipService.SetPassword(userPart, password);

                    var user = customerPart.User;
                    _authenticationService.SignIn(user, false /* createPersistentCookie */);
                    return Redirect("~/");
                }
            }

        }

运行此代码时,我最终在我的数据库中有两个UserPart条目。一个与相关的CustomerPart和一个没有。

0 个答案:

没有答案