コード例 #1
0
        public async Task <ActionResult> SignUp(SignUpViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string[] emailParts = model.Email.Split(new[] { '@' });
                    UserBO   newUser    = new UserBO
                    {
                        Email          = model.Email,
                        FirstName      = model.FirstName,
                        LastName       = model.LastName,
                        StaffUserName  = emailParts[0],
                        UserName       = model.Email,
                        OrganizationId = model.OrganizationId,
                        LockoutEnabled = true,
                        Audit          = new Entity.Entities.Audit(),
                        EmailConfirmed = true //remove
                    };

                    IdentityResult result = await UserManager.CreateAsync(newUser, model.Password);

                    if (result.Succeeded)
                    {
                        //remove this
                        var roleResult = await UserManager.AddToRoleAsync(newUser.Id, SiriusRoles.USER);

                        if (roleResult.Succeeded)
                        {
                            await SignInManager.SignInAsync(newUser, false, false);

                            return(Json(JsonResponse.RedirectTo("", Url.Action("setup", "staff"))));
                        }
                        //remove

                        ////send verification email
                        //string code = await UserManager.GenerateEmailConfirmationTokenAsync(newUser.Id);
                        //string callbackUrl = Url.Action("confirm", "user", new { userId = newUser.Id, code = code }, protocol: Request.Url.Scheme);

                        //string imageUrl = Url.Action("GetEmailHeaderImage", "Base");
                        ////string route = "../" + orgName + "/confirmation/" + user.Id + "/" + code; /EmailTemplates/images/head1.png

                        //string emailBody = await CreateEmailBodyAsync("../EmailTemplates/AccountConfirmation.html", newUser.Email, newUser.FirstName, callbackUrl, imageUrl);
                        //await UserManager.SendEmailAsync(newUser.Id, "SiriusPM Account Confimation", emailBody);

                        ////user/confirmationsent
                        //string url = "~/confirmationsent";
                        //return Json(JsonResponse.RedirectTo("", url));
                    }
                    else
                    {
                        return(PartialView(model));
                    }
                }
                return(PartialView(model));
            }
            catch (Exception ex)
            {
                LogError(ex);
                return(PartialView(model));
            }
        }