public async Task <IActionResult> SetUserType(UserType userType)
        {
            IActionResult result = null;
            var           user   = await userRepository.GetByName(User.Identity.Name);

            switch (userType.ChosenUserType)
            {
            case UserTypes.Company:
                await authenticationProvider.AddClaim(user, "CompanyRole", "Company");

                companiesRepository.Create(new Company {
                    UserId = user.Id
                });
                result = RedirectToAction("Index", "Dashboard", new { area = "Company" });     // TODO: Redirect to company Dashboard
                break;

            case UserTypes.Candidate:
                await authenticationProvider.AddClaim(user, "CandidateRole", "Candidate");

                candidateRepository.Create(new Candidate {
                    UserId = user.Id
                });
                result = RedirectToAction("Index", "Dashboard", new { area = "Candidate" });
                break;

            default:
                throw new ArgumentException("No user type with this name!");
            }

            await authenticationProvider.SignIn(user);

            return(result);
        }
示例#2
0
        public async Task <IActionResult> Register(Register userRegistration)
        {
            if (!ModelState.IsValid)
            {
                return(View(userRegistration));
            }

            var user = new User {
                UserName = userRegistration.UserName, Email = userRegistration.Email
            };
            var isSuccess = await userRepository.Create(user, userRegistration.Password);

            await authenticationProvider.AddClaim(user, ClaimTypes.Name, user.UserName);

            if (isSuccess)
            {
                logger.LogInformation($"User with username: {user.UserName} just registered");
                await authenticationProvider.SignIn(user);

                return(RedirectToAction(nameof(UserTypeController.ChooseUserType), "UserType", new { area = "Account" }));
            }

            return(View(userRegistration));
        }