public async Task <IActionResult> Register([FromBody] RegisterReq registerModel) { if (ModelState.IsValid) { //1. Check if user already exists if (!await _registerService.CheckIfUserExistsAsync(registerModel.UserName)) { //2. Check if password is strong enough if (PasswordStrength.CheckPasswordComplexity(registerModel.PassWord) && registerModel.UserName.EndsWith("@consid.se")) { //3. Create new identity user var user = await _registerService.RegisterNewUserAsync(registerModel); if (user != null) { //Send confirmationlink to email address //var token = await _registerService.GenerateEmailTokenAsync(user); //var link = Url.Action(action: "ConfirmEmail", controller: "Register", // new { userId = user.Id, token = token }, Request.Scheme); //await _registerService.SendEmailConfirmationAsync(user, link); //Write confirmationlink to file in MyPictures //var filePath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); //System.IO.File.WriteAllText(Path.Combine(filePath, $"ConfirmEmail---{user.Id}.txt"), link); return(Created("", new Response { Success = true })); } } return(BadRequest(new Response { Success = false, ErrorMessage = "Password not strong enough or invalid email-address" })); } return(BadRequest(new Response { Success = false, ErrorMessage = "A user with the submitted email-address already exists" })); } return(BadRequest(new Response { Success = false, ErrorMessage = "Both email and password must be submitted" })); }