Пример #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            if (!ModelState.IsValid)
            {
                await LoadAsync(user);

                return(Page());
            }

            QualificationIdentityResource[] qualificationIdentityResource = await
                                                                            _context.QualificationIdentityResources.Where(x => x.IdentityResourceId == user.Id).ToArrayAsync();

            _context.QualificationIdentityResources.RemoveRange(qualificationIdentityResource);
            await _context.SaveChangesAsync();

            int[] choosedQualificationsIds = Input.Qualifications.Ids;
            await _qualificationService.AddQualificationsAsync(user, choosedQualificationsIds);

            await _signInManager.RefreshSignInAsync(user);

            StatusMessage = "Your profile has been updated";
            return(RedirectToPage());
        }
Пример #2
0
        public async Task <IActionResult> AddQualifications(int id, ChooseQualificationsViewModel qualificationsToAdd)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            await _qualificationService.AddQualificationsAsync(await _projectRepository.GetOneAsync(id), qualificationsToAdd.SuitableQualifications.Where(x => x.IsChecked).Select(x => x.Qualification.Id));

            return(RedirectToAction("Details", new { id }));
        }
Пример #3
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl ??= Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new IdentityResource {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (Input.Qualifications != null)
                {
                    int[] choosedQualificationsIds = Input.Qualifications.Ids;
                    await _qualificationService.AddQualificationsAsync(user, choosedQualificationsIds);
                }

                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 }));
                    }

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(LocalRedirect(returnUrl));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            IEnumerable <Qualification> qualifications = await _qualificationRepository.GetAllAsync();

            Qualifications = new MultiSelectViewModel
            {
                Elements = qualifications.Select(x => new SelectListItem {
                    Text = $"{x.Skill.Name} - {x.Level}", Value = x.Id.ToString()
                }).ToList(),
                Ids = new int[0]
            };

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