Пример #1
0
        public ResaPreambleParagraph CreatePreambleParagraph([NotNull] ResaElement resolution, string text = "")
        {
            if (resolution == null)
            {
                throw new ArgumentNullException("This method CreatePReambleParagraph received an resolution element null");
            }

            _context.Update(resolution);

            var paragraph = new ResaPreambleParagraph()
            {
                ResaElement = resolution,
                OrderIndex  = _context.PreambleParagraphs.Count(n => n.ResolutionId == resolution.ResaElementId),
                Text        = text
            };

            if (resolution.PreambleParagraphs == null)
            {
                resolution.PreambleParagraphs = new List <ResaPreambleParagraph>();
            }
            resolution.PreambleParagraphs.Add(paragraph);
            _context.PreambleParagraphs.Add(paragraph);
            _context.SaveChanges();
            return(paragraph);
        }
Пример #2
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl ??= Url.Content("~/");
            //ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid && Input.AcceptedAGB)
            {
                var userFound = await _userManager.FindByEmailAsync(Input.Email);

                if (userFound != null)
                {
                    if (userFound.IsShadowUser)
                    {
                        userFound.UserName = Input.Username;
                        userFound.Forename = Input.Forename;
                        userFound.Lastname = Input.Lastname;
                        await _userManager.RemovePasswordAsync(userFound);

                        await _userManager.ChangePasswordAsync(userFound, String.Empty, Input.Password);

                        _dbContext.Update(userFound);
                        _dbContext.SaveChanges();
                        await _signInManager.SignInAsync(userFound, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                    _logger.LogWarning($"User already exisits and was not a shadow user: {Input.Username}");
                }
                else
                {
                    var user = new MunityUser
                    {
                        UserName         = Input.Username,
                        Email            = Input.Email,
                        RegistrationDate = DateTime.UtcNow,
                        Birthday         = new DateOnly(Input.BirthdayYear, Input.BirthdayMonth, Input.BirthdayDay),
                        Forename         = Input.Forename,
                        Lastname         = Input.Lastname
                    };

                    var result = await _userManager.CreateAsync(user, Input.Password);

                    if (result.Succeeded)
                    {
                        _logger.LogInformation("User created a new account with password.");

                        //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                        //code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                        //var callbackUrl = Url.Page(
                        //    "/Account/ConfirmEmail",
                        //    pageHandler: null,
                        //    values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        //    protocol: Request.Scheme);

                        //await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                        //    $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                        //if (_userManager.Options.SignIn.RequireConfirmedAccount)
                        //{
                        //    return RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl });
                        //}
                        //else
                        //{
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                        //}
                    }
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(string.Empty, error.Description);
                    }
                }
            }
            else
            {
                Console.WriteLine("AGB not accepted!");
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }