public async Task <IActionResult> ForgottenPasswordDefinition(ForgottenPasswordRequest request) { var result = await _users.DefineForgottenPassword(request.Token, request.Password, HttpContext.RequestAborted); if (!result) { return(BadRequest()); } return(Ok()); }
public async Task <bool> SendForgottenPasswordLink(string email) { bool result = false; string fullUrl = ""; var baseUrl = GlobalConfig.Instance.GetByKey("com.google.android.firebase.restful.api.url")?.ToString(); var apiKey = GlobalConfig.Instance.GetByKey("com.google.android.firebase.API_KEY")?.ToString(); if (!string.IsNullOrEmpty(baseUrl) && !string.IsNullOrEmpty(apiKey) && !string.IsNullOrEmpty(email)) { fullUrl = baseUrl + "/getOobConfirmationCode?key=" + apiKey; try { using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); var body = new ForgottenPasswordRequest { requestType = "PASSWORD_RESET", email = email }; var bodyStr = JsonConvert.SerializeObject(body); var stringContent = new StringContent(bodyStr, Encoding.UTF8, "application/json"); var response = await httpClient.PostAsync(fullUrl, stringContent).ConfigureAwait(false); var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var deserializedContent = JsonConvert.DeserializeObject <ForgottenPasswordResponse>(content); result = deserializedContent != null && !string.IsNullOrEmpty(deserializedContent.email) && !string.IsNullOrEmpty(deserializedContent.kind); } } catch (Exception ex) { Console.WriteLine(ex); } } return(result); }
private async Task SendRequestEmail(ForgottenPasswordRequest request) { var subject = "Forgotten password"; var body = "You reset-code is: " + request.Code; await _emailSender.SendEmailAsync(request.Email, subject, body); }
public void Return_400_On_Valid_Forgotten_Password_Definition(Mock <IUserService> service, IAuthorizationService authorization, ForgottenPasswordRequest request) { service.Setup(x => x.DefineForgottenPassword(request.Token, request.Password, It.IsAny <CancellationToken>())).ReturnsAsync(false); var controller = TestSetup.SetupController <UsersController>(service.Object, authorization); var result = controller.ForgottenPasswordDefinition(request); result.Should().NotBeNull(); result.Result.Should().BeOfType <BadRequestResult>(); }