|
|
@ -28,6 +28,7 @@ using System.Runtime.Intrinsics.X86; |
|
|
|
using System.Text; |
|
|
|
using System.IO; |
|
|
|
using Abp.AutoMapper; |
|
|
|
using Abp.Domain.Entities; |
|
|
|
|
|
|
|
namespace BCS.BMC.Controllers |
|
|
|
{ |
|
|
@ -248,42 +249,56 @@ namespace BCS.BMC.Controllers |
|
|
|
} |
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
public async Task<ActionResult> ValidateTenancy([FromBody] GetUrlDto input) |
|
|
|
public async Task<IActionResult> ValidateTenancy([FromBody] GetUrlDto input) |
|
|
|
{ |
|
|
|
Uri uri = new Uri(input.InputUrl, UriKind.Absolute); |
|
|
|
var domain = uri.Host; |
|
|
|
|
|
|
|
if (input.InputUrl == null) |
|
|
|
if (string.IsNullOrWhiteSpace(input.InputUrl)) |
|
|
|
{ |
|
|
|
return BadRequest(); |
|
|
|
return BadRequest("Please Enter A Valid Url"); |
|
|
|
} |
|
|
|
var company = await _companyMaster.FirstOrDefaultAsync(x => x.Url == input.InputUrl.ToString() || x.DomainName == domain); |
|
|
|
var company = await _companyMaster.FirstOrDefaultAsync(x => x.DomainName == domain); |
|
|
|
if (company == null) |
|
|
|
{ |
|
|
|
return BadRequest(); |
|
|
|
return BadRequest("Url Not Found"); |
|
|
|
} |
|
|
|
return Ok(); |
|
|
|
return Ok("Success"); |
|
|
|
} |
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
public async Task<IActionResult> Login([FromBody] LoginInputModel input) |
|
|
|
{ |
|
|
|
if (input.CompanyUrl == null) |
|
|
|
{ |
|
|
|
return BadRequest(); |
|
|
|
} |
|
|
|
|
|
|
|
var company = await _companyMaster.FirstOrDefaultAsync(x => x.Url == input.CompanyUrl.ToString()); |
|
|
|
if(company == null) |
|
|
|
{ |
|
|
|
var subDomainName = ""; |
|
|
|
var protocol = ""; |
|
|
|
if (string.IsNullOrWhiteSpace(input.CompanyUrl)) |
|
|
|
{ |
|
|
|
return BadRequest(); |
|
|
|
return BadRequest("Please Enter A Valid Url"); |
|
|
|
} |
|
|
|
|
|
|
|
using (HttpClient client = new HttpClient()) |
|
|
|
{ |
|
|
|
Uri uri = new Uri(input.CompanyUrl); |
|
|
|
var baseUrl = uri + "api/BmcLogin"; |
|
|
|
|
|
|
|
var host = uri.Host; |
|
|
|
protocol = uri.Scheme; |
|
|
|
if (host.Split('.').Length > 2) |
|
|
|
{ |
|
|
|
int lastIndex = host.LastIndexOf("."); |
|
|
|
int index = host.LastIndexOf(".", lastIndex - 1); |
|
|
|
var subdomain = host.Substring(0, index); |
|
|
|
if (subdomain != "www") |
|
|
|
{ |
|
|
|
subDomainName = subdomain; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var company = await _companyMaster.FirstOrDefaultAsync(x => x.DomainName == host); |
|
|
|
if (company == null) |
|
|
|
{ |
|
|
|
return BadRequest("Invalid Company Url"); |
|
|
|
} |
|
|
|
|
|
|
|
// var baseUrl = uri + "api/BmcLogin";
|
|
|
|
var baseUrl = protocol + "://" + host + "/api/BmcLogin"; |
|
|
|
var data = new |
|
|
|
{ |
|
|
|
usernameOrEmailAddress = input.UsernameOrEmailAddress, |
|
|
@ -294,29 +309,36 @@ namespace BCS.BMC.Controllers |
|
|
|
requestContent.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json"); |
|
|
|
HttpResponseMessage response = await client.PostAsync(baseUrl, requestContent); |
|
|
|
|
|
|
|
response.EnsureSuccessStatusCode(); |
|
|
|
|
|
|
|
if (response.IsSuccessStatusCode) |
|
|
|
{ |
|
|
|
var responseStream = await response.Content.ReadAsStringAsync(); |
|
|
|
return Ok(responseStream); |
|
|
|
LoginOrRegisterResponseMessageModel result = JsonConvert.DeserializeObject<LoginOrRegisterResponseMessageModel>(responseStream); |
|
|
|
return Ok(result); |
|
|
|
} |
|
|
|
else if (response.StatusCode == HttpStatusCode.InternalServerError) |
|
|
|
{ |
|
|
|
var contents = await response.Content.ReadAsStringAsync(); |
|
|
|
ResponseMessageModel result = JsonConvert.DeserializeObject<ResponseMessageModel>(contents); |
|
|
|
|
|
|
|
return BadRequest(result.error.message == "Login Failed" ? "Invalid Username Or Password" : result.error.message); |
|
|
|
} |
|
|
|
return BadRequest(); |
|
|
|
return Ok(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
public async Task<IActionResult> Registration([FromBody] RegistrationInput input) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
using (HttpClient client = new HttpClient()) |
|
|
|
{ |
|
|
|
var baseUrl = input.Subdomain + "/api/services/bwac/employeeRegister/RegisterEmployeeAsNewUser"; |
|
|
|
|
|
|
|
var baseUrl = input.CompanyUrl + "/api/services/bwac/employeeRegister/RegisterEmployeeAsNewUser"; |
|
|
|
|
|
|
|
var data = new |
|
|
|
{ |
|
|
|
tenancyName = "testmsnyc", |
|
|
|
phoneNo = input.Phoneno, |
|
|
|
userName = input.Email, |
|
|
|
userName = input.UserNameOrEmail, |
|
|
|
password = input.Password |
|
|
|
}; |
|
|
|
var requestJson = JsonConvert.SerializeObject(data); |
|
|
@ -324,11 +346,13 @@ namespace BCS.BMC.Controllers |
|
|
|
requestContent.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json"); |
|
|
|
HttpResponseMessage response = await client.PostAsync(baseUrl, requestContent); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (response.IsSuccessStatusCode) |
|
|
|
{ |
|
|
|
var responseStream = await response.Content.ReadAsStringAsync(); |
|
|
|
return Ok(responseStream); |
|
|
|
var responseStream = await response.Content.ReadAsStringAsync(); |
|
|
|
LoginOrRegisterResponseMessageModel result = JsonConvert.DeserializeObject<LoginOrRegisterResponseMessageModel>(responseStream); |
|
|
|
// result.result.statusCode =;
|
|
|
|
return Ok(result); |
|
|
|
} |
|
|
|
else if (response.StatusCode == HttpStatusCode.InternalServerError) |
|
|
|
{ |
|
|
|