public async Task <IActionResult> ResetPassword([FromBody] ResetPasswordReq input) { if (!ModelState.IsValid) { return(BadRequest(new Response { Success = false, ErrorMessage = "The details provided are not complete." })); } if (input.Password != input.ConfirmPassword) { return(BadRequest("Password and Confirmed password must be identical")); } if (!PasswordStrength.CheckPasswordComplexity(input.Password)) { return(BadRequest("Password not strong enough.")); } input.Token = System.Net.WebUtility.UrlDecode(input.Token); if (await _loginService.ResetPasswordAsync(input)) { return(Ok(new Response { Success = true })); } return(StatusCode(500, new Response { Success = false, ErrorMessage = "Something went wrong while trying to reset your password." })); }
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" })); }