Пример #1
0
        public async Task <IActionResult> RegisterAsync(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName                = model.Email,
                    Email                   = model.Email,
                    PhoneNumber             = model.PhoneNumber,
                    PublisherFirstName      = model.PublisherFirstName,
                    PublisherLastName       = model.PublisherLastName,
                    EnumPublisherSex        = model.PublisherSex,
                    EnumPublisherPrivileges = model.PublisherPrivileges,
                    EnumRecordStatus        = model.PublisherActive
                };
                var result = await userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //Create email confirmation token
                    var token = await userManager.GenerateEmailConfirmationTokenAsync(user);

                    var confirmationLink = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, token = token }, Request.Scheme);
                    await emailSender.SendEmailConfirmationAsync(user, confirmationLink);

                    //log email sent
                    logger.Log(LogLevel.Warning, confirmationLink);

                    ViewBag.ErrorTitle   = "Registration Sucessful";
                    ViewBag.ErrorMessage = "Before you can Login, please confirm your" +
                                           "email, by clicking on the linke that we have emailed you.";
                    return(View("Home"));
                    //await signInManager.SignInAsync(user, isPersistent: false);
                    //return RedirectToAction("index","home");
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }
            return(View(model));
        }