upgrade to v8 remove automap too.
This commit is contained in:
@@ -1,23 +1,22 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<UserSecretsId>punt</UserSecretsId>
|
<UserSecretsId>punt</UserSecretsId>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.21" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.11" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.21" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.11" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.21" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.11" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.21" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.11" />
|
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.14.0" />
|
||||||
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.12.0" />
|
|
||||||
<PackageReference Include="SpreadsheetLight" Version="3.5.0" />
|
<PackageReference Include="SpreadsheetLight" Version="3.5.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.4" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\CommonAD\CommonAD6.csproj" />
|
<ProjectReference Include="..\..\CommonAD6\CommonAD6.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ VisualStudioVersion = 17.4.33122.133
|
|||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarParkValidationAPI", "CarParkValidationAPI.csproj", "{74980A36-AF9D-44B4-991D-994E033AD54A}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarParkValidationAPI", "CarParkValidationAPI.csproj", "{74980A36-AF9D-44B4-991D-994E033AD54A}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonAD6", "..\..\CommonAD\CommonAD6.csproj", "{9EF32775-1957-4B84-9A05-C6AB69D1ABD5}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommonAD6", "..\..\CommonAD6\CommonAD6.csproj", "{05B28DB7-0D54-1EAB-130D-4A1DEE9C3A27}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -17,10 +17,10 @@ Global
|
|||||||
{74980A36-AF9D-44B4-991D-994E033AD54A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{74980A36-AF9D-44B4-991D-994E033AD54A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{74980A36-AF9D-44B4-991D-994E033AD54A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{74980A36-AF9D-44B4-991D-994E033AD54A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{74980A36-AF9D-44B4-991D-994E033AD54A}.Release|Any CPU.Build.0 = Release|Any CPU
|
{74980A36-AF9D-44B4-991D-994E033AD54A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{9EF32775-1957-4B84-9A05-C6AB69D1ABD5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{05B28DB7-0D54-1EAB-130D-4A1DEE9C3A27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{9EF32775-1957-4B84-9A05-C6AB69D1ABD5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{05B28DB7-0D54-1EAB-130D-4A1DEE9C3A27}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{9EF32775-1957-4B84-9A05-C6AB69D1ABD5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{05B28DB7-0D54-1EAB-130D-4A1DEE9C3A27}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{9EF32775-1957-4B84-9A05-C6AB69D1ABD5}.Release|Any CPU.Build.0 = Release|Any CPU
|
{05B28DB7-0D54-1EAB-130D-4A1DEE9C3A27}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
using AutoMapper;
|
|
||||||
using CarParkValidationAPI.Entities;
|
|
||||||
using CarParkValidationAPI.Models;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace CarParkValidationAPI.Datas
|
|
||||||
{
|
|
||||||
public class AutoMapping: Profile
|
|
||||||
{
|
|
||||||
public AutoMapping()
|
|
||||||
{
|
|
||||||
CreateMap<ConcessionType, ConcessionTypeDto>()
|
|
||||||
.ForMember( dest => dest.Id, opt => opt.MapFrom(src => src.ConcessionTypeID))
|
|
||||||
.ForMember(dest => dest.Description , opt=> opt.MapFrom(src=> src.ConcessionDesc))
|
|
||||||
.ForMember(dest => dest.Display, opt => opt.MapFrom(src => src.ConcessionDisplay))
|
|
||||||
.ReverseMap();
|
|
||||||
CreateMap<ValidationPoint, ValidationPointDto>()
|
|
||||||
.ForMember(dest => dest.Id , opt => opt.MapFrom(src => src.ValidationPointID))
|
|
||||||
.ForMember(dest => dest.Display, opt => opt.MapFrom(src => src.DisplayName))
|
|
||||||
.ReverseMap();
|
|
||||||
/*etc...*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,7 @@ using CarParkValidationAPI.Datas;
|
|||||||
using CarParkValidationAPI.Interface;
|
using CarParkValidationAPI.Interface;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
using System;
|
||||||
using AutoMapper;
|
|
||||||
|
|
||||||
namespace CarParkValidationAPI.Repository
|
namespace CarParkValidationAPI.Repository
|
||||||
{
|
{
|
||||||
@@ -21,13 +21,13 @@ namespace CarParkValidationAPI.Repository
|
|||||||
private DataContext _context;
|
private DataContext _context;
|
||||||
private string _currentUser = "";
|
private string _currentUser = "";
|
||||||
private readonly AppSettings _appSettings;
|
private readonly AppSettings _appSettings;
|
||||||
private readonly IMapper _mapper;
|
|
||||||
public ConcessionTypeRepository(
|
public ConcessionTypeRepository(
|
||||||
DataContext context,
|
DataContext context,
|
||||||
IMapper mapper,
|
|
||||||
IOptions<AppSettings> appSettings)
|
IOptions<AppSettings> appSettings)
|
||||||
{
|
{
|
||||||
_mapper = mapper;
|
|
||||||
_context = context;
|
_context = context;
|
||||||
_appSettings = appSettings.Value;
|
_appSettings = appSettings.Value;
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ namespace CarParkValidationAPI.Repository
|
|||||||
string error = "";
|
string error = "";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
result = await _context.ConcessionTypes.Select(
|
result = await _context.ConcessionTypes.Select(
|
||||||
x => new ConcessionTypeDto()
|
x => new ConcessionTypeDto()
|
||||||
{
|
{
|
||||||
@@ -70,9 +70,9 @@ namespace CarParkValidationAPI.Repository
|
|||||||
Display = x.ConcessionDisplay,
|
Display = x.ConcessionDisplay,
|
||||||
Active = x.Active
|
Active = x.Active
|
||||||
}).ToListAsync();
|
}).ToListAsync();
|
||||||
*/
|
|
||||||
var olist = await _context.ConcessionTypes.ToListAsync();
|
//var olist = await _context.ConcessionTypes.ToListAsync();
|
||||||
result = _mapper.Map<List<ConcessionTypeDto>>(olist);
|
//result = _mapper.Map<List<ConcessionTypeDto>>(olist);
|
||||||
statuscode = 1;
|
statuscode = 1;
|
||||||
result.Sort((x, y) => x.Description.CompareTo(y.Description));
|
result.Sort((x, y) => x.Description.CompareTo(y.Description));
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,17 @@ namespace CarParkValidationAPI.Repository
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
result = await _context.ConcessionTypes.FindAsync(id);
|
result = await _context.ConcessionTypes.FindAsync(id);
|
||||||
dto = _mapper.Map<ConcessionTypeDto>(result);
|
dto = new();
|
||||||
|
if (result != null)
|
||||||
|
{
|
||||||
|
dto.Id = id;
|
||||||
|
dto.Active = result.Active;
|
||||||
|
dto.Description = result.ConcessionDesc;
|
||||||
|
dto.Display = result.ConcessionDisplay;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
// dto = _mapper.Map<ConcessionTypeDto>(result);
|
||||||
//dto = FillConcessionTypeDto(result);
|
//dto = FillConcessionTypeDto(result);
|
||||||
//result = _list.Find(x => x.Id == id);
|
//result = _list.Find(x => x.Id == id);
|
||||||
//var dto = await Task.Run(() => result);
|
//var dto = await Task.Run(() => result);
|
||||||
|
|||||||
@@ -1,262 +0,0 @@
|
|||||||
//using BCryptNet = BCrypt.Net.BCrypt;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using CarParkValidationAPI.Authorization;
|
|
||||||
using CarParkValidationAPI.Entities;
|
|
||||||
using CarParkValidationAPI.Helpers;
|
|
||||||
using CarParkValidationAPI.Models.Users;
|
|
||||||
using CarParkValidationAPI.Models;
|
|
||||||
using CarParkValidationAPI.Datas;
|
|
||||||
using CarParkValidationAPI.Interface;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using CommonAD.Models;
|
|
||||||
using CommonAD;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
|
|
||||||
namespace CarParkValidationAPI.Repository
|
|
||||||
{
|
|
||||||
public class UserFakeRepository : IUserService
|
|
||||||
{
|
|
||||||
private DataContext _context;
|
|
||||||
private IJwtUtils _jwtUtils;
|
|
||||||
private readonly AppSettings _appSettings;
|
|
||||||
|
|
||||||
public UserFakeRepository(
|
|
||||||
DataContext context,
|
|
||||||
IJwtUtils jwtUtils,
|
|
||||||
IOptions<AppSettings> appSettings)
|
|
||||||
{
|
|
||||||
_context = context;
|
|
||||||
_jwtUtils = jwtUtils;
|
|
||||||
_appSettings = appSettings.Value;
|
|
||||||
|
|
||||||
}
|
|
||||||
public AuthenticateResponse Authenticate(AuthenticateRequest model)
|
|
||||||
{
|
|
||||||
var user = _context.Users.SingleOrDefault(x => x.Username == model.Username);
|
|
||||||
|
|
||||||
// validate
|
|
||||||
// if (user == null || !BCryptNet.Verify(model.Password, user.PasswordHash))
|
|
||||||
if (user == null || (model.Password != user.PasswordHash))
|
|
||||||
throw new System.Exception("Username or password is incorrect");
|
|
||||||
|
|
||||||
// authentication successful so generate jwt token
|
|
||||||
var jwtToken = _jwtUtils.GenerateJwtToken(user);
|
|
||||||
|
|
||||||
return new AuthenticateResponse(user, jwtToken);
|
|
||||||
}
|
|
||||||
public async Task<ResultModel<AuthenticateResponse>> LoginApiAD(AuthenticateRequest model)
|
|
||||||
{
|
|
||||||
User user = new User();
|
|
||||||
int statusCode = 1;
|
|
||||||
if (model.Username.ToLower() == "admin")
|
|
||||||
{
|
|
||||||
user.FirstName = model.Username;
|
|
||||||
user.LastName = "LS Test";
|
|
||||||
user.Role = AdminRole.Admin;
|
|
||||||
user.Username = model.Username;
|
|
||||||
user.Email = "admin@mail.com";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
user.Username = model.Username;
|
|
||||||
user.FirstName = "FS Normal";
|
|
||||||
user.LastName = " LS Normal";
|
|
||||||
user.Email = "Normal@mail.com";
|
|
||||||
user.Role = AdminRole.Normal;
|
|
||||||
}
|
|
||||||
|
|
||||||
// authentication successful so generate jwt token
|
|
||||||
var jwtToken = _jwtUtils.GenerateJwtToken(user);
|
|
||||||
|
|
||||||
var retval = await Task.Run(() => new AuthenticateResponse(user, jwtToken));
|
|
||||||
return new ResultModel<AuthenticateResponse>()
|
|
||||||
{
|
|
||||||
Data = retval,
|
|
||||||
StatusCode = statusCode
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<ResultModel<AuthenticateResponse>> NLoginApiAD(AuthenticateRequest model)
|
|
||||||
{
|
|
||||||
User myUser = null;
|
|
||||||
AuthenticateResponse retval = null;
|
|
||||||
int statuscode = 0;
|
|
||||||
string webAPIUrl = _appSettings.LoginWebAPI;
|
|
||||||
|
|
||||||
var loginInfo = await CommonAD.WebAPIUtil.GetLoginADAsync(webAPIUrl, "CheckADCredentials", model.Username, model.Password);
|
|
||||||
if (loginInfo != null && loginInfo.result)
|
|
||||||
{
|
|
||||||
myUser = new User();
|
|
||||||
myUser.Email = loginInfo.email;
|
|
||||||
myUser.FirstName = loginInfo.firstName;
|
|
||||||
myUser.LastName = loginInfo.lastName;
|
|
||||||
myUser.Username = loginInfo.stafflinkNo;
|
|
||||||
//now check the adminuser table
|
|
||||||
var user = _context.AdminUsers.SingleOrDefault(x => x.StafflinkNo == model.Username);
|
|
||||||
if (user != null)
|
|
||||||
{
|
|
||||||
myUser.Role = user.RoleType;
|
|
||||||
myUser.Id = user.UserID;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
myUser.Role = AdminRole.Normal;
|
|
||||||
|
|
||||||
// validate
|
|
||||||
// if (user == null || !BCryptNet.Verify(model.Password, user.PasswordHash))
|
|
||||||
|
|
||||||
// authentication successful so generate jwt token
|
|
||||||
var jwtToken = _jwtUtils.GenerateJwtToken(myUser);
|
|
||||||
statuscode = 1;
|
|
||||||
retval = new AuthenticateResponse(myUser, jwtToken);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ResultModel<AuthenticateResponse>()
|
|
||||||
{
|
|
||||||
Data = retval,
|
|
||||||
StatusCode = statuscode
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<ResultModel<AuthenticateResponse>> LoginAD(AuthenticateRequest model)
|
|
||||||
{
|
|
||||||
User myUser = null;
|
|
||||||
AuthenticateResponse retval = null;
|
|
||||||
int statuscode = 0;
|
|
||||||
ADConfig adConfig = new ADConfig()
|
|
||||||
{
|
|
||||||
LDAPPassword = _appSettings.LDAPPassword,
|
|
||||||
LDAPPath = _appSettings.LDAPPath,
|
|
||||||
LDAPUser = _appSettings.LDAPUser,
|
|
||||||
ADTimeOutStr = _appSettings.ADTimeOut
|
|
||||||
};
|
|
||||||
myUser = await Task.Run(() => LoginADStaff(adConfig, model.Username, model.Password));
|
|
||||||
if (!string.IsNullOrEmpty(myUser.Username))
|
|
||||||
{
|
|
||||||
statuscode = 1;
|
|
||||||
// authentication successful so generate jwt token
|
|
||||||
var jwtToken = _jwtUtils.GenerateJwtToken(myUser);
|
|
||||||
|
|
||||||
retval = new AuthenticateResponse(myUser, jwtToken);
|
|
||||||
}
|
|
||||||
return new ResultModel<AuthenticateResponse>()
|
|
||||||
{
|
|
||||||
Data = retval,
|
|
||||||
StatusCode = statuscode
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<ResultModel<List<User>>> GetAllUsers()
|
|
||||||
{
|
|
||||||
var retval = await _context.Users.ToListAsync();
|
|
||||||
return new ResultModel<List<User>>()
|
|
||||||
{
|
|
||||||
Data = retval,
|
|
||||||
StatusCode = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<ResultModel<User>> GetById(int id)
|
|
||||||
{
|
|
||||||
var user = await _context.Users.FindAsync(id);
|
|
||||||
if (user == null) throw new KeyNotFoundException("User not found");
|
|
||||||
return new ResultModel<User>()
|
|
||||||
{
|
|
||||||
Data = user,
|
|
||||||
StatusCode = 1
|
|
||||||
};
|
|
||||||
}
|
|
||||||
public async Task<ResultModel<User>> SearchApiStaff(string staffLinkNo)
|
|
||||||
{
|
|
||||||
User myUser = null;
|
|
||||||
int statuscode = 0;
|
|
||||||
string webAPIUrl = _appSettings.LoginWebAPI;
|
|
||||||
var loginInfo = await CommonAD.WebAPIUtil.SearchStaffAsync(webAPIUrl, "SearchStaff", staffLinkNo);
|
|
||||||
if (loginInfo != null && loginInfo.result)
|
|
||||||
{
|
|
||||||
myUser = new User();
|
|
||||||
myUser.Email = loginInfo.email;
|
|
||||||
myUser.FirstName = loginInfo.firstName;
|
|
||||||
myUser.LastName = loginInfo.lastName;
|
|
||||||
myUser.Username = loginInfo.stafflinkNo;
|
|
||||||
statuscode = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ResultModel<User>()
|
|
||||||
{
|
|
||||||
Data = myUser,
|
|
||||||
StatusCode = statuscode
|
|
||||||
};
|
|
||||||
// return myUser;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<ResultModel<User>> SearchADStaff(string staffLinkNo)
|
|
||||||
{
|
|
||||||
int statuscode = 0;
|
|
||||||
ADConfig adConfig = new ADConfig()
|
|
||||||
{
|
|
||||||
LDAPPassword = _appSettings.LDAPPassword,
|
|
||||||
LDAPPath = _appSettings.LDAPPath,
|
|
||||||
LDAPUser = _appSettings.LDAPUser,
|
|
||||||
ADTimeOutStr = _appSettings.ADTimeOut
|
|
||||||
};
|
|
||||||
User myUser = await Task.Run(() => SearchADStaff(adConfig, staffLinkNo));
|
|
||||||
if (!string.IsNullOrEmpty(myUser.Username))
|
|
||||||
statuscode = 1;
|
|
||||||
return new ResultModel<User>()
|
|
||||||
{
|
|
||||||
Data = myUser,
|
|
||||||
StatusCode = statuscode
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
private User SearchADStaff(ADConfig adConfig, string username)
|
|
||||||
{
|
|
||||||
|
|
||||||
ADStaffLink staffLink = new ADStaffLink(adConfig);
|
|
||||||
MyADObject myADObj = staffLink.SearchStaff(username);
|
|
||||||
User user = new()
|
|
||||||
{
|
|
||||||
Username = myADObj.stafflinkNo,
|
|
||||||
Email = myADObj.email,
|
|
||||||
FirstName = myADObj.firstName,
|
|
||||||
LastName = myADObj.lastName
|
|
||||||
};
|
|
||||||
// myADObj.JobTitle;
|
|
||||||
return user;
|
|
||||||
|
|
||||||
// return null;
|
|
||||||
}
|
|
||||||
private User LoginADStaff(ADConfig adConfig, string username, string password)
|
|
||||||
{
|
|
||||||
|
|
||||||
ADStaffLink staffLink = new ADStaffLink(adConfig);
|
|
||||||
MyADObject myADObj = staffLink.CheckADCredentials(username, password);
|
|
||||||
User user = new()
|
|
||||||
{
|
|
||||||
Username = myADObj.stafflinkNo,
|
|
||||||
Email = myADObj.email,
|
|
||||||
FirstName = myADObj.firstName,
|
|
||||||
LastName = myADObj.lastName
|
|
||||||
};
|
|
||||||
// myADObj.JobTitle;
|
|
||||||
return user;
|
|
||||||
|
|
||||||
// return null;
|
|
||||||
}
|
|
||||||
public async Task<ResultModel<FileContent>> GetAllUserReport()
|
|
||||||
{
|
|
||||||
return new ResultModel<FileContent>
|
|
||||||
{
|
|
||||||
Data = null,
|
|
||||||
StatusCode = 1
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -112,22 +112,70 @@ namespace CarParkValidationAPI.Repository
|
|||||||
{
|
{
|
||||||
User myUser = null;
|
User myUser = null;
|
||||||
AuthenticateResponse retval = null;
|
AuthenticateResponse retval = null;
|
||||||
|
string error = "user name is not in DB or user Name profile is not generic";
|
||||||
int statuscode = 0;
|
int statuscode = 0;
|
||||||
ADConfig adConfig = new ADConfig()
|
string webAPIUrl = _appSettings.LoginWebAPI;
|
||||||
|
//KCO, D204KCO
|
||||||
|
//now check the adminuser table
|
||||||
|
//ward clerk
|
||||||
|
try
|
||||||
{
|
{
|
||||||
LDAPPassword = _appSettings.LDAPPassword,
|
var loginInfo = await CommonAD.WebAPIUtil.PostLoginADAsync(webAPIUrl, "CheckCredentials", model.Username, model.Password);
|
||||||
LDAPPath = _appSettings.LDAPPath,
|
if (loginInfo != null && loginInfo.result)
|
||||||
LDAPUser = _appSettings.LDAPUser,
|
{
|
||||||
ADTimeOutStr = _appSettings.ADTimeOut
|
myUser = new User();
|
||||||
};
|
myUser.Email = loginInfo.email;
|
||||||
myUser = await Task.Run(() => LoginADStaff(adConfig,model.Username, model.Password));
|
myUser.FirstName = loginInfo.firstName;
|
||||||
if (!string.IsNullOrEmpty(myUser.Username))
|
myUser.LastName = loginInfo.lastName;
|
||||||
{
|
myUser.Username = loginInfo.stafflinkNo;
|
||||||
statuscode = 1;
|
//myUser.Department = loginInfo.department;
|
||||||
// authentication successful so generate jwt token
|
//myUser.Position = loginInfo.jobTitle;
|
||||||
var jwtToken = _jwtUtils.GenerateJwtToken(myUser);
|
//myUser.ManagerEmail = loginInfo.managerEmail;
|
||||||
|
//myUser.Phone = loginInfo.phone;
|
||||||
|
//now check the adminuser table
|
||||||
|
var user = _context.AdminUsers.
|
||||||
|
SingleOrDefault(x => x.StafflinkNo == model.Username
|
||||||
|
&& true == x.Active);
|
||||||
|
if (user != null)
|
||||||
|
{
|
||||||
|
// myUser.Role = user.RoleType;
|
||||||
|
myUser.Id = user.UserID;
|
||||||
|
myUser.Role = user.RoleType;
|
||||||
|
//myUser.ValidationPointId = user.ValidationPointID ?? 0;
|
||||||
|
statuscode = 1;
|
||||||
|
}
|
||||||
|
else // allow
|
||||||
|
{
|
||||||
|
statuscode = 1;
|
||||||
|
myUser.Role = AdminRole.Normal;
|
||||||
|
myUser.Id = -1;
|
||||||
|
|
||||||
retval = new AuthenticateResponse(myUser, jwtToken);
|
//error = "user name does not exist in adminUser";
|
||||||
|
}
|
||||||
|
// validate
|
||||||
|
// if (user == null || !BCryptNet.Verify(model.Password, user.PasswordHash))
|
||||||
|
|
||||||
|
// authentication successful so generate jwt token
|
||||||
|
if (statuscode == 1)
|
||||||
|
{
|
||||||
|
var jwtToken = _jwtUtils.GenerateJwtToken(myUser);
|
||||||
|
retval = new AuthenticateResponse(myUser, jwtToken);
|
||||||
|
error = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error = "user name or password is not correct";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
retval = null;
|
||||||
|
error = ex.ToString();
|
||||||
|
statuscode = 0;
|
||||||
|
throw ex;
|
||||||
}
|
}
|
||||||
return new ResultModel<AuthenticateResponse>()
|
return new ResultModel<AuthenticateResponse>()
|
||||||
{
|
{
|
||||||
@@ -185,58 +233,36 @@ namespace CarParkValidationAPI.Repository
|
|||||||
public async Task<ResultModel<User>> SearchADStaff(string staffLinkNo)
|
public async Task<ResultModel<User>> SearchADStaff(string staffLinkNo)
|
||||||
{
|
{
|
||||||
int statuscode = 0;
|
int statuscode = 0;
|
||||||
ADConfig adConfig = new ADConfig()
|
User myUser = null;
|
||||||
|
AuthenticateResponse retval = null;
|
||||||
|
|
||||||
|
|
||||||
|
string webAPIUrl = _appSettings.LoginWebAPI;
|
||||||
|
var loginInfo = await CommonAD.WebAPIUtil.SearchStaffAsync(webAPIUrl, "SearchStaff", staffLinkNo);
|
||||||
|
if (!string.IsNullOrEmpty(loginInfo.firstName))
|
||||||
{
|
{
|
||||||
LDAPPassword = _appSettings.LDAPPassword,
|
myUser = new();
|
||||||
LDAPPath = _appSettings.LDAPPath,
|
myUser.FirstName = loginInfo.firstName;
|
||||||
LDAPUser = _appSettings.LDAPUser,
|
myUser.LastName = loginInfo.lastName;
|
||||||
ADTimeOutStr = _appSettings.ADTimeOut
|
myUser.Username = staffLinkNo;
|
||||||
};
|
myUser.Email = loginInfo.email;
|
||||||
User myUser = await Task.Run(() => SearchADStaff(adConfig, staffLinkNo));
|
/*
|
||||||
if (!string.IsNullOrEmpty(myUser.Username))
|
myUser.Department = loginInfo.department;
|
||||||
|
myUser.Position = loginInfo.jobTitle;
|
||||||
|
myUser.Phone = loginInfo.phone;
|
||||||
|
myUser.ManagerEmail = loginInfo.managerEmail;
|
||||||
|
*/
|
||||||
statuscode = 1;
|
statuscode = 1;
|
||||||
|
}
|
||||||
return new ResultModel<User>()
|
return new ResultModel<User>()
|
||||||
{
|
{
|
||||||
Data = myUser,
|
Data = myUser,
|
||||||
StatusCode = statuscode
|
StatusCode = statuscode
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
private User SearchADStaff(ADConfig adConfig, string username)
|
|
||||||
{
|
|
||||||
|
|
||||||
ADStaffLink staffLink = new ADStaffLink(adConfig);
|
|
||||||
MyADObject myADObj = staffLink.SearchStaff(username);
|
|
||||||
User user = new()
|
|
||||||
{
|
|
||||||
Username = myADObj.stafflinkNo,
|
|
||||||
Email = myADObj.email,
|
|
||||||
FirstName = myADObj.firstName,
|
|
||||||
LastName = myADObj.lastName
|
|
||||||
};
|
|
||||||
// myADObj.JobTitle;
|
|
||||||
return user;
|
|
||||||
|
|
||||||
// return null;
|
|
||||||
}
|
|
||||||
private User LoginADStaff(ADConfig adConfig, string username, string password)
|
|
||||||
{
|
|
||||||
|
|
||||||
ADStaffLink staffLink = new ADStaffLink(adConfig);
|
|
||||||
MyADObject myADObj = staffLink.CheckADCredentials(username,password);
|
|
||||||
User user = new()
|
|
||||||
{
|
|
||||||
Username = myADObj.stafflinkNo,
|
|
||||||
Email = myADObj.email,
|
|
||||||
FirstName = myADObj.firstName,
|
|
||||||
LastName = myADObj.lastName
|
|
||||||
};
|
|
||||||
// myADObj.JobTitle;
|
|
||||||
return user;
|
|
||||||
|
|
||||||
// return null;
|
|
||||||
}
|
|
||||||
private string GetVPDesc(int? idn)
|
private string GetVPDesc(int? idn)
|
||||||
{
|
{
|
||||||
string result = "";
|
string result = "";
|
||||||
|
|||||||
+1
-1
@@ -66,7 +66,7 @@ namespace CarParkValidationAPI
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddAutoMapper(typeof(Startup));
|
// services.AddAutoMapper(typeof(Startup));
|
||||||
//**
|
//**
|
||||||
//publish need to take comment out
|
//publish need to take comment out
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user