예제 #1
0
        public async Task <IActionResult> Register(RegisterViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            viewModel.UserName = viewModel.UserName.ToLower();

            if (await _authenService.AccountExistsAsync(viewModel.UserName))
            {
                ModelState.AddModelError(string.Empty, "Username already exists");
                return(View(viewModel));
            }

            var account = await _authenService.CreateAccountAsync(viewModel.UserName, viewModel.Password);

            await _authenService.AddUserRoleAsync(account, "Member");

            return(RedirectToAction(nameof(Login)));
        }