|
|
@ -17,7 +17,6 @@ using BCS.BMC.Authorization; |
|
|
|
using BCS.BMC.Authorization.Users; |
|
|
|
using BCS.BMC.Models.TokenAuth; |
|
|
|
using BCS.BMC.MultiTenancy; |
|
|
|
//using System.Web.Mvc;
|
|
|
|
using BCS.BMC.CompanyMasters.Dto; |
|
|
|
using System.Net; |
|
|
|
using System.Net.Http; |
|
|
@ -25,6 +24,9 @@ using Newtonsoft.Json; |
|
|
|
using System.Net.Http.Headers; |
|
|
|
using BCS.BMC.BMC.CompanyMasters; |
|
|
|
using Abp.Domain.Repositories; |
|
|
|
using System.Runtime.Intrinsics.X86; |
|
|
|
using System.Text; |
|
|
|
using System.IO; |
|
|
|
|
|
|
|
namespace BCS.BMC.Controllers |
|
|
|
{ |
|
|
@ -39,7 +41,7 @@ namespace BCS.BMC.Controllers |
|
|
|
private readonly IExternalAuthManager _externalAuthManager; |
|
|
|
private readonly UserRegistrationManager _userRegistrationManager; |
|
|
|
private readonly IRepository<CompanyMaster, int> _companyMaster; |
|
|
|
|
|
|
|
ResponseMessageModel responsemessage = new ResponseMessageModel(); |
|
|
|
public TokenAuthController( |
|
|
|
LogInManager logInManager, |
|
|
|
ITenantCache tenantCache, |
|
|
@ -128,7 +130,7 @@ namespace BCS.BMC.Controllers |
|
|
|
} |
|
|
|
|
|
|
|
var accessToken = CreateAccessToken(CreateJwtClaims(loginResult.Identity)); |
|
|
|
|
|
|
|
|
|
|
|
return new ExternalAuthenticateResultModel |
|
|
|
{ |
|
|
|
AccessToken = accessToken, |
|
|
@ -257,6 +259,81 @@ namespace BCS.BMC.Controllers |
|
|
|
return BadRequest(); |
|
|
|
} |
|
|
|
return Ok(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[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) |
|
|
|
{ |
|
|
|
return BadRequest(); |
|
|
|
} |
|
|
|
|
|
|
|
using (HttpClient client = new HttpClient()) |
|
|
|
{ |
|
|
|
Uri uri = new Uri(input.CompanyUrl); |
|
|
|
var baseUrl = uri + "api/BmcLogin"; |
|
|
|
|
|
|
|
var data = new |
|
|
|
{ |
|
|
|
usernameOrEmailAddress = input.UsernameOrEmailAddress, |
|
|
|
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); |
|
|
|
|
|
|
|
response.EnsureSuccessStatusCode(); |
|
|
|
if (response.IsSuccessStatusCode) |
|
|
|
{ |
|
|
|
var responseStream = await response.Content.ReadAsStringAsync(); |
|
|
|
return Ok(responseStream); |
|
|
|
} |
|
|
|
return BadRequest(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
public async Task<IActionResult> Registration([FromBody] RegistrationInput input) |
|
|
|
{ |
|
|
|
|
|
|
|
using (HttpClient client = new HttpClient()) |
|
|
|
{ |
|
|
|
var baseUrl = input.Subdomain + "/api/services/bwac/employeeRegister/RegisterEmployeeAsNewUser"; |
|
|
|
|
|
|
|
var data = new |
|
|
|
{ |
|
|
|
tenancyName = "testmsnyc", |
|
|
|
phoneNo = input.Phoneno, |
|
|
|
userName = input.Email, |
|
|
|
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) |
|
|
|
{ |
|
|
|
var responseStream = await response.Content.ReadAsStringAsync(); |
|
|
|
return Ok(responseStream); |
|
|
|
} |
|
|
|
else if (response.StatusCode == HttpStatusCode.InternalServerError) |
|
|
|
{ |
|
|
|
var contents = await response.Content.ReadAsStringAsync(); |
|
|
|
ResponseMessageModel result = JsonConvert.DeserializeObject<ResponseMessageModel>(contents); |
|
|
|
return BadRequest(result); |
|
|
|
} |
|
|
|
} |
|
|
|
return BadRequest(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |