Browse Source

Implement End point Registration and Login

feature/Registration
Palash Biswas 2 years ago
parent
commit
f6bbb415b9
6 changed files with 154 additions and 4 deletions
  1. +1
    -0
      BCS.BMC/src/BCS.BMC.Application/CompanyMasters/CompanyMasterAppService.cs
  2. +17
    -0
      BCS.BMC/src/BCS.BMC.Application/CompanyMasters/Dto/UserDetailsDto.cs
  3. +81
    -4
      BCS.BMC/src/BCS.BMC.Web.Core/Controllers/TokenAuthController.cs
  4. +15
    -0
      BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/LoginInputModel.cs
  5. +21
    -0
      BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/RegistrationInput.cs
  6. +19
    -0
      BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/ResponseMessageModel.cs

+ 1
- 0
BCS.BMC/src/BCS.BMC.Application/CompanyMasters/CompanyMasterAppService.cs View File

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


+ 17
- 0
BCS.BMC/src/BCS.BMC.Application/CompanyMasters/Dto/UserDetailsDto.cs 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; }
}
}

+ 81
- 4
BCS.BMC/src/BCS.BMC.Web.Core/Controllers/TokenAuthController.cs View File

@ -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();
}
}
}

+ 15
- 0
BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/LoginInputModel.cs 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; }
}
}

+ 21
- 0
BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/RegistrationInput.cs 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; }
}
}

+ 19
- 0
BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/ResponseMessageModel.cs 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; }
}
}

Loading…
Cancel
Save