Implement End point Registration and Login

This commit is contained in:
Palash Biswas 2022-10-19 11:28:11 +05:30
parent 94699dd23d
commit f6bbb415b9
6 changed files with 154 additions and 4 deletions

View File

@ -37,6 +37,7 @@ using System.Net.Http.Headers;
using Newtonsoft.Json; using Newtonsoft.Json;
using Abp.Json; using Abp.Json;
namespace BCS.BMC.CompanyMasters namespace BCS.BMC.CompanyMasters
{ {
public class CompanyMasterAppService : ICompanyMasterAppService public class CompanyMasterAppService : ICompanyMasterAppService

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BCS.BMC.CompanyMasters.Dto
{
public class UserDetailsDto
{
public int Id { get; set; }
public string Name { get; set; }
public string SurName { get; set; }
public string EmailAddress { get; set; }
public bool IsActive { get; set; }
}
}

View File

@ -17,7 +17,6 @@ using BCS.BMC.Authorization;
using BCS.BMC.Authorization.Users; using BCS.BMC.Authorization.Users;
using BCS.BMC.Models.TokenAuth; using BCS.BMC.Models.TokenAuth;
using BCS.BMC.MultiTenancy; using BCS.BMC.MultiTenancy;
//using System.Web.Mvc;
using BCS.BMC.CompanyMasters.Dto; using BCS.BMC.CompanyMasters.Dto;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
@ -25,6 +24,9 @@ using Newtonsoft.Json;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using BCS.BMC.BMC.CompanyMasters; using BCS.BMC.BMC.CompanyMasters;
using Abp.Domain.Repositories; using Abp.Domain.Repositories;
using System.Runtime.Intrinsics.X86;
using System.Text;
using System.IO;
namespace BCS.BMC.Controllers namespace BCS.BMC.Controllers
{ {
@ -39,7 +41,7 @@ namespace BCS.BMC.Controllers
private readonly IExternalAuthManager _externalAuthManager; private readonly IExternalAuthManager _externalAuthManager;
private readonly UserRegistrationManager _userRegistrationManager; private readonly UserRegistrationManager _userRegistrationManager;
private readonly IRepository<CompanyMaster, int> _companyMaster; private readonly IRepository<CompanyMaster, int> _companyMaster;
ResponseMessageModel responsemessage = new ResponseMessageModel();
public TokenAuthController( public TokenAuthController(
LogInManager logInManager, LogInManager logInManager,
ITenantCache tenantCache, ITenantCache tenantCache,
@ -258,5 +260,80 @@ namespace BCS.BMC.Controllers
} }
return Ok(); 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();
}
} }
} }

View File

@ -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 LoginInputModel
{
public string CompanyUrl { get; set; }
public string UsernameOrEmailAddress { get; set; }
public string Password { get; set; }
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BCS.BMC.Models.TokenAuth
{
public class RegistrationInput
{
public string Firstname { get; set; }
public string Lastname { get; set; }
public string Email { get; set; }
public string Phoneno { get; set; }
public string Password { get; set; }
public string Status { get; set; }
public string Protocol { get; set; }
public string Subdomain { get; set; }
public string Domain { get; set; }
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BCS.BMC.Models.TokenAuth
{
public class ResponseMessageModel
{
public Error error { get; set; }
}
public class Error
{
public string message { get; set; }
}
}