Compare commits
2 Commits
5f38e0e3ef
...
a9fdec8332
Author | SHA1 | Date | |
---|---|---|---|
a9fdec8332 | |||
0ede4ee972 |
@ -28,6 +28,7 @@ using System.Runtime.Intrinsics.X86;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Abp.AutoMapper;
|
using Abp.AutoMapper;
|
||||||
|
using Abp.Domain.Entities;
|
||||||
|
|
||||||
namespace BCS.BMC.Controllers
|
namespace BCS.BMC.Controllers
|
||||||
{
|
{
|
||||||
@ -248,42 +249,56 @@ namespace BCS.BMC.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[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);
|
Uri uri = new Uri(input.InputUrl, UriKind.Absolute);
|
||||||
var domain = uri.Host;
|
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)
|
if (company == null)
|
||||||
{
|
{
|
||||||
return BadRequest();
|
return BadRequest("Url Not Found");
|
||||||
}
|
}
|
||||||
return Ok();
|
return Ok("Success");
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> Login([FromBody] LoginInputModel input)
|
public async Task<IActionResult> Login([FromBody] LoginInputModel input)
|
||||||
{
|
{
|
||||||
if (input.CompanyUrl == null)
|
var subDomainName = "";
|
||||||
|
var protocol = "";
|
||||||
|
if (string.IsNullOrWhiteSpace(input.CompanyUrl))
|
||||||
{
|
{
|
||||||
return BadRequest();
|
return BadRequest("Please Enter A Valid Url");
|
||||||
}
|
}
|
||||||
|
|
||||||
var company = await _companyMaster.FirstOrDefaultAsync(x => x.Url == input.CompanyUrl.ToString());
|
|
||||||
if(company == null)
|
|
||||||
{
|
|
||||||
return BadRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
using (HttpClient client = new HttpClient())
|
using (HttpClient client = new HttpClient())
|
||||||
{
|
{
|
||||||
Uri uri = new Uri(input.CompanyUrl);
|
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
|
var data = new
|
||||||
{
|
{
|
||||||
usernameOrEmailAddress = input.UsernameOrEmailAddress,
|
usernameOrEmailAddress = input.UsernameOrEmailAddress,
|
||||||
@ -294,29 +309,47 @@ namespace BCS.BMC.Controllers
|
|||||||
requestContent.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");
|
requestContent.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");
|
||||||
HttpResponseMessage response = await client.PostAsync(baseUrl, requestContent);
|
HttpResponseMessage response = await client.PostAsync(baseUrl, requestContent);
|
||||||
|
|
||||||
response.EnsureSuccessStatusCode();
|
|
||||||
if (response.IsSuccessStatusCode)
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
var responseStream = await response.Content.ReadAsStringAsync();
|
var responseStream = await response.Content.ReadAsStringAsync();
|
||||||
return Ok(responseStream);
|
LoginOrRegisterResponseMessageModel result = JsonConvert.DeserializeObject<LoginOrRegisterResponseMessageModel>(responseStream);
|
||||||
|
return Ok(result);
|
||||||
}
|
}
|
||||||
return BadRequest();
|
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 Ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> Registration([FromBody] RegistrationInput input)
|
public async Task<IActionResult> Registration([FromBody] RegistrationInput 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())
|
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
|
var data = new
|
||||||
{
|
{
|
||||||
tenancyName = "testmsnyc",
|
|
||||||
phoneNo = input.Phoneno,
|
phoneNo = input.Phoneno,
|
||||||
userName = input.Email,
|
userName = input.UserNameOrEmail,
|
||||||
password = input.Password
|
password = input.Password
|
||||||
};
|
};
|
||||||
var requestJson = JsonConvert.SerializeObject(data);
|
var requestJson = JsonConvert.SerializeObject(data);
|
||||||
@ -324,11 +357,12 @@ namespace BCS.BMC.Controllers
|
|||||||
requestContent.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");
|
requestContent.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");
|
||||||
HttpResponseMessage response = await client.PostAsync(baseUrl, requestContent);
|
HttpResponseMessage response = await client.PostAsync(baseUrl, requestContent);
|
||||||
|
|
||||||
|
|
||||||
if (response.IsSuccessStatusCode)
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
var responseStream = await response.Content.ReadAsStringAsync();
|
var responseStream = await response.Content.ReadAsStringAsync();
|
||||||
return Ok(responseStream);
|
LoginOrRegisterResponseMessageModel result = JsonConvert.DeserializeObject<LoginOrRegisterResponseMessageModel>(responseStream);
|
||||||
|
return Ok(result);
|
||||||
}
|
}
|
||||||
else if (response.StatusCode == HttpStatusCode.InternalServerError)
|
else if (response.StatusCode == HttpStatusCode.InternalServerError)
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BCS.BMC.Models.TokenAuth
|
||||||
|
{
|
||||||
|
public class LoginOrRegisterResponseMessageModel
|
||||||
|
{
|
||||||
|
public result result { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class result
|
||||||
|
{
|
||||||
|
|
||||||
|
public int statusCode { get; set; }
|
||||||
|
public string userName { get; set; }
|
||||||
|
public string userId { get; set; }
|
||||||
|
public string employeeId { get; set; }
|
||||||
|
public string phoneNo { get; set; }
|
||||||
|
public string profilePictureId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -10,11 +10,12 @@ namespace BCS.BMC.Models.TokenAuth
|
|||||||
{
|
{
|
||||||
public string Firstname { get; set; }
|
public string Firstname { get; set; }
|
||||||
public string Lastname { get; set; }
|
public string Lastname { get; set; }
|
||||||
public string Email { get; set; }
|
public string UserNameOrEmail { get; set; }
|
||||||
public string Phoneno { get; set; }
|
public string Phoneno { get; set; }
|
||||||
public string Password { get; set; }
|
public string Password { get; set; }
|
||||||
public string Status { get; set; }
|
public string Status { get; set; }
|
||||||
public string Protocol { get; set; }
|
public string Protocol { get; set; }
|
||||||
|
public string CompanyUrl { get; set; }
|
||||||
public string Subdomain { get; set; }
|
public string Subdomain { get; set; }
|
||||||
public string Domain { get; set; }
|
public string Domain { get; set; }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user