BMC: ForgotPassword Functionality
This commit is contained in:
parent
0b613fe1f5
commit
ba7ebf68c1
@ -30,6 +30,7 @@ using System.IO;
|
||||
using Abp.AutoMapper;
|
||||
using Abp.Domain.Entities;
|
||||
using BCS.BMC.BMC.FirebaseCloudMessages;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace BCS.BMC.Controllers
|
||||
{
|
||||
@ -430,5 +431,198 @@ namespace BCS.BMC.Controllers
|
||||
}
|
||||
return Ok("Success");
|
||||
}
|
||||
|
||||
//[HttpPost]
|
||||
//public async Task<IActionResult> ForgotPasswordForBmcUser([FromBody] ForgotPasswordInput input)
|
||||
//{
|
||||
// using (HttpClient client = new HttpClient())
|
||||
// {
|
||||
// var baseUrl = input.CompanyUrl + "/api/services/bwac/employeeRegister/RegisterEmployeeAsNewUser";
|
||||
|
||||
// var data = new
|
||||
// {
|
||||
// userName = input.UserName,
|
||||
// AppType = input.AppType
|
||||
// };
|
||||
// var requestJson = JsonConvert.SerializeObject(data);
|
||||
// var requestContent = new StringContent(requestJson.ToString());
|
||||
// requestContent.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");
|
||||
// HttpResponseMessage response = await client.PostAsync(baseUrl, requestContent);
|
||||
// return Ok("Success");
|
||||
// }
|
||||
//}
|
||||
//----------------------
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> GetBmcPhoneOrEmailByUserId([FromBody] ForgotPasswordInput input)
|
||||
{
|
||||
Uri uri = new Uri(input.CompanyUrl, UriKind.Absolute);
|
||||
var domain = uri.Host;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.CompanyUrl))
|
||||
{
|
||||
return BadRequest("Please Enter A Valid Url");
|
||||
}
|
||||
var company = await _companyMaster.FirstOrDefaultAsync(x => x.DomainName == domain);
|
||||
if (company == null)
|
||||
{
|
||||
return BadRequest("Url Not Found");
|
||||
}
|
||||
|
||||
using (HttpClient client = new HttpClient())
|
||||
{
|
||||
var baseUrl = input.CompanyUrl + "api/services/bwac/bmcUserForgotPassword/GetPhoneOrEmailByUserId";
|
||||
|
||||
var data = new
|
||||
{
|
||||
userName = input.UserName,
|
||||
appType = input.AppType
|
||||
};
|
||||
var requestJson = JsonConvert.SerializeObject(data);
|
||||
var requestContent = new StringContent(requestJson.ToString());
|
||||
requestContent.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");
|
||||
HttpResponseMessage response = await client.PostAsync(baseUrl, requestContent);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
var contents = await response.Content.ReadAsStringAsync();
|
||||
ForgotPasswordUserResponse result = JsonConvert.DeserializeObject<ForgotPasswordUserResponse>(contents);
|
||||
var emailOrPhone = result.result;
|
||||
int num;
|
||||
bool isMobile = Int32.TryParse(emailOrPhone,out num);
|
||||
if (isMobile)
|
||||
{
|
||||
result.type = "phoneNo";
|
||||
return Ok(result);
|
||||
}
|
||||
if (!isMobile)
|
||||
{
|
||||
result.type = "emailAddress";
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
ResponseMessageModel results = JsonConvert.DeserializeObject<ResponseMessageModel>(content);
|
||||
return BadRequest(results.error.message.ToString());
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> ForgotPasswordForBmcUser([FromBody] ForgotPasswordInput input)
|
||||
{
|
||||
Uri uri = new Uri(input.CompanyUrl, UriKind.Absolute);
|
||||
var domain = uri.Host;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.CompanyUrl))
|
||||
{
|
||||
return BadRequest("Please Enter A Valid Url");
|
||||
}
|
||||
var company = await _companyMaster.FirstOrDefaultAsync(x => x.DomainName == domain);
|
||||
if (company == null)
|
||||
{
|
||||
return BadRequest("Url Not Found");
|
||||
}
|
||||
|
||||
using (HttpClient client = new HttpClient())
|
||||
{
|
||||
var baseUrl = input.CompanyUrl + "api/services/bwac/bmcUserForgotPassword/ForgotPassword";
|
||||
|
||||
var data = new
|
||||
{
|
||||
userName = input.UserName,
|
||||
appType = input.AppType
|
||||
};
|
||||
var requestJson = JsonConvert.SerializeObject(data);
|
||||
var requestContent = new StringContent(requestJson.ToString());
|
||||
requestContent.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");
|
||||
HttpResponseMessage response = await client.PostAsync(baseUrl, requestContent);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
else
|
||||
{
|
||||
var contents = await response.Content.ReadAsStringAsync();
|
||||
ResponseMessageModel result = JsonConvert.DeserializeObject<ResponseMessageModel>(contents);
|
||||
return BadRequest(result.error.message.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> BmcAuthenticateForgotPasswordCode([FromBody] ForgotPasswordUserAndCodeInput input)
|
||||
{
|
||||
Uri uri = new Uri(input.CompanyUrl, UriKind.Absolute);
|
||||
var domain = uri.Host;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.CompanyUrl))
|
||||
{
|
||||
return BadRequest("Please Enter A Valid Url");
|
||||
}
|
||||
var company = await _companyMaster.FirstOrDefaultAsync(x => x.DomainName == domain);
|
||||
if (company == null)
|
||||
{
|
||||
return BadRequest("Url Not Found");
|
||||
}
|
||||
|
||||
using (HttpClient client = new HttpClient())
|
||||
{
|
||||
var baseUrl = input.CompanyUrl + "api/services/bwac/bmcUserForgotPassword/BmcAuthenticateForgotPasswordCode";
|
||||
|
||||
var data = new
|
||||
{
|
||||
userName = input.UserName,
|
||||
code = input.Code
|
||||
};
|
||||
var requestJson = JsonConvert.SerializeObject(data);
|
||||
var requestContent = new StringContent(requestJson.ToString());
|
||||
requestContent.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");
|
||||
HttpResponseMessage response = await client.PostAsync(baseUrl, requestContent);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
var contents = await response.Content.ReadAsStringAsync();
|
||||
ResponseMessageModel result = JsonConvert.DeserializeObject<ResponseMessageModel>(contents);
|
||||
return BadRequest(result.error.message.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> BmcResetPassword([FromBody] ForgotPasswordUserAndPwdInput input)
|
||||
{
|
||||
Uri uri = new Uri(input.CompanyUrl, UriKind.Absolute);
|
||||
var domain = uri.Host;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.CompanyUrl))
|
||||
{
|
||||
return BadRequest("Please Enter A Valid Url");
|
||||
}
|
||||
var company = await _companyMaster.FirstOrDefaultAsync(x => x.DomainName == domain);
|
||||
if (company == null)
|
||||
{
|
||||
return BadRequest("Url Not Found");
|
||||
}
|
||||
|
||||
using (HttpClient client = new HttpClient())
|
||||
{
|
||||
var baseUrl = input.CompanyUrl + "api/services/bwac/bmcUserForgotPassword/BmcResetPassword";
|
||||
|
||||
var data = new
|
||||
{
|
||||
userName = input.UserName,
|
||||
password = input.Password
|
||||
};
|
||||
var requestJson = JsonConvert.SerializeObject(data);
|
||||
var requestContent = new StringContent(requestJson.ToString());
|
||||
requestContent.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");
|
||||
HttpResponseMessage response = await client.PostAsync(baseUrl, requestContent);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
var contents = await response.Content.ReadAsStringAsync();
|
||||
ResponseMessageModel result = JsonConvert.DeserializeObject<ResponseMessageModel>(contents);
|
||||
return BadRequest(result.error.message.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BCS.BMC.Models.TokenAuth
|
||||
{
|
||||
public class ForgotPasswordInput
|
||||
{
|
||||
public string CompanyUrl { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public int AppType { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BCS.BMC.Models.TokenAuth
|
||||
{
|
||||
public class ForgotPasswordUserAndCodeInput
|
||||
{
|
||||
public string CompanyUrl { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string Code { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BCS.BMC.Models.TokenAuth
|
||||
{
|
||||
public class ForgotPasswordUserAndPwdInput
|
||||
{
|
||||
public string CompanyUrl { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BCS.BMC.Models.TokenAuth
|
||||
{
|
||||
public class ForgotPasswordUserResponse : result
|
||||
{
|
||||
public string result { get; set; }
|
||||
public string type { get; set; }
|
||||
}
|
||||
}
|
@ -208,8 +208,8 @@ namespace BCS.BMC.Web.Controllers
|
||||
string baseUrl = "";
|
||||
foreach (var outputMessage in bmcMessageStatusInput)
|
||||
{
|
||||
var companyDetails = _companyMasterService.GetAllList().Where(x => x.Url.Trim() == outputMessage.CompanyUrl.Trim()).FirstOrDefault();
|
||||
baseUrl = companyDetails.Url + "api/services/bwac/updateBmcMessageStatus/UpdateMessageStatus";
|
||||
// var companyDetails = _companyMasterService.GetAllList().Where(x => x.Url.Trim() == outputMessage.CompanyUrl.Trim()).FirstOrDefault();
|
||||
baseUrl = outputMessage.CompanyUrl + "api/services/bwac/updateBmcMessageStatus/UpdateMessageStatus";
|
||||
|
||||
}
|
||||
using (HttpClient client = new HttpClient())
|
||||
|
Loading…
x
Reference in New Issue
Block a user