public async Task <ActionResult <UserDto> > AddUser(UserDto user) { if (user == null || user.UserRoles.IsNullOrEmptyCollection()) { return(BadRequest()); } _logger.LogInformation(ApiLogEvents.InsertItemsList, $"{nameof(AddUser)} Started"); var repoObj = _mapper.Map <Entity.User>(user); await _localUserService.AddUser(repoObj); var result = _mapper.Map <UserDto>(repoObj); return(Ok(result)); }
public async Task <IActionResult> RegisterUser(RegisterUserViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var userToCreate = new Entities.User { Username = model.UserName, Subject = Guid.NewGuid().ToString(), Email = model.Email, Active = false }; userToCreate.Claims.Add(new Entities.UserClaim() { Type = "country", Value = model.Country }); userToCreate.Claims.Add(new Entities.UserClaim() { Type = JwtClaimTypes.Address, Value = model.Address }); userToCreate.Claims.Add(new Entities.UserClaim() { Type = JwtClaimTypes.GivenName, Value = model.GivenName }); userToCreate.Claims.Add(new Entities.UserClaim() { Type = JwtClaimTypes.FamilyName, Value = model.FamilyName }); _localUserService.AddUser(userToCreate, model.Password); await _localUserService.SaveChangesAsync(); //create an activation Link var link = Url.ActionLink("ActivateUser", "UserRegistration", new { securityCode = userToCreate.SecurityCode }); Debug.WriteLine(link); return(View("ActivationCodeSent")); //Log the user in //await HttpContext.SignInAsync(userToCreate.Subject, userToCreate.Username); ////continue with flow //if(_interaction.IsValidReturnUrl(model.ReturnUrl) // || Url.IsLocalUrl(model.ReturnUrl)) //{ // return Redirect(model.ReturnUrl); //} //return Redirect("~/"); }
public async Task <IActionResult> RegisterUser(RegisterUserViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var userToCreate = new User { Username = model.UserName, Subject = Guid.NewGuid().ToString(), Email = model.Email, Active = false }; userToCreate.Claims.Add(new UserClaim() { Type = "country", Value = model.Country }); userToCreate.Claims.Add(new UserClaim() { Type = JwtClaimTypes.Address, Value = model.Address }); userToCreate.Claims.Add(new UserClaim() { Type = JwtClaimTypes.GivenName, Value = model.GivenName }); userToCreate.Claims.Add(new UserClaim() { Type = JwtClaimTypes.FamilyName, Value = model.FamilyName }); _localUserService.AddUser(userToCreate, model.Password); await _localUserService.SaveChangesAsync(); // create an activation link var link = Url.ActionLink("ActivateUser", "UserRegistration", new { securityCode = userToCreate.SecurityCode }); if (_rootConfiguration.EmailConfiguration.Active == false) { if (Environment.IsDevelopment()) { Console.WriteLine(link); } } else { if (Environment.IsDevelopment()) { Console.WriteLine("Sending email with link: " + link); Console.WriteLine("Sending Email from: " + _rootConfiguration.EmailConfiguration.Email); } //TODO: Sendong via batter formated html tempalte await _emailService.SendEmail(model.Email, "Yourr activation link for FCT portal", "Your activation link: " + link); } return(View("ActivationCodeSent")); }