MFA
This commit is contained in:
parent
b4e3bf9f21
commit
1724b5cf52
|
|
@ -23,7 +23,7 @@ export class User extends BaseObject {
|
|||
public employeeID?: number;
|
||||
public changePasswordAtNextLogon: boolean;
|
||||
public userID: number;
|
||||
public payrollTypeID?: number;
|
||||
public PayrollTypeID?: number;
|
||||
reason: string;
|
||||
authorizedBy: number;
|
||||
authorizedDate: Date;
|
||||
|
|
|
|||
|
|
@ -284,4 +284,7 @@ export class AuthService {
|
|||
})
|
||||
);
|
||||
}
|
||||
getIsFromUser(): boolean {
|
||||
return this.isFromUserSubject.value;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,13 +97,21 @@ export class AppTopBarComponent implements OnInit, DoCheck, OnDestroy {
|
|||
this.loginName = user.UserName;
|
||||
this.isSuperUser = true;
|
||||
var spItem = localStorage.getItem('switchUserID');
|
||||
if (spItem != undefined && spItem != null) {
|
||||
if (spItem != undefined && spItem != null && spItem != "undefined") {
|
||||
this.isSuperUser = false;
|
||||
this.swithtypeName = "Switch to Super-User";
|
||||
this.switchUserID = parseInt(localStorage.getItem('switchUserID'));
|
||||
}
|
||||
else if (user.UserType == EnumUserType.SuperUser && user.EmployeeID != undefined) {
|
||||
this.swithtypeName = "Switch to ESS";
|
||||
else if (user.UserType == EnumUserType.SuperUser && (!user.EmployeeID || user.EmployeeID === 0 || user.EmployeeID === "0")) {
|
||||
this.swithtypeName = undefined;
|
||||
}
|
||||
else if (user.UserType == EnumUserType.SuperUser && user.EmployeeID != undefined && user.EmployeeID != 0 && user.EmployeeID != "0") {
|
||||
if(this.authService.getIsFromUser()){
|
||||
this.swithtypeName = "Switch to Admin";
|
||||
}
|
||||
else{
|
||||
this.swithtypeName = "Switch to ESS";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -227,10 +235,15 @@ export class AppTopBarComponent implements OnInit, DoCheck, OnDestroy {
|
|||
this.switchUserID = undefined;
|
||||
var userid = undefined;
|
||||
this.authService.getSwitchUserId(EnumUserType.SuperUser).subscribe(next => {
|
||||
userid = next;
|
||||
if(next == 0){
|
||||
userid = undefined;
|
||||
this.swithtypeName = undefined;
|
||||
}
|
||||
else{
|
||||
userid = next;
|
||||
}
|
||||
}, error => {
|
||||
this.swithtypeName = undefined;
|
||||
console.log(error);
|
||||
}, () => {
|
||||
if (userid != 0){
|
||||
this.switchUserID = userid;
|
||||
|
|
@ -238,9 +251,18 @@ export class AppTopBarComponent implements OnInit, DoCheck, OnDestroy {
|
|||
}
|
||||
});
|
||||
}
|
||||
else if (user.UserType == EnumUserType.SuperUser && user.EmployeeID != undefined)
|
||||
else if (user.UserType == EnumUserType.SuperUser && (!user.EmployeeID || user.EmployeeID === 0 || user.EmployeeID === "0"))
|
||||
{
|
||||
this.swithtypeName = "Switch to ESS";
|
||||
this.swithtypeName = undefined;
|
||||
}
|
||||
else if (user.UserType == EnumUserType.SuperUser && user.EmployeeID != undefined && user.EmployeeID != 0 && user.EmployeeID != "0")
|
||||
{
|
||||
if(this.authService.getIsFromUser()){
|
||||
this.swithtypeName = "Switch to Admin";
|
||||
}
|
||||
else{
|
||||
this.swithtypeName = "Switch to ESS";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -308,8 +330,9 @@ export class AppTopBarComponent implements OnInit, DoCheck, OnDestroy {
|
|||
switchTheUser(oUser: User) {
|
||||
const data = {
|
||||
user: oUser,
|
||||
payrollTypeId: oUser.payrollTypeID,
|
||||
payrollTypeId: oUser.PayrollTypeID,
|
||||
};
|
||||
debugger;
|
||||
this.loadingPanel.ShowLoadingPanel = true;
|
||||
this.authService.SwtichUserMode(data).subscribe(
|
||||
(resp: any) => {
|
||||
|
|
|
|||
|
|
@ -280,7 +280,7 @@ export class LandingPageComponent implements OnInit {
|
|||
this.currentUser.userType = EnumUserType.Employee
|
||||
const data = {
|
||||
user: this.currentUser,
|
||||
payrollTypeId: this.currentUser.payrollTypeID,
|
||||
payrollTypeId: this.currentUser.PayrollTypeID,
|
||||
};
|
||||
this.authService.SwtichUserMode(data).subscribe(
|
||||
(resp: any) => {
|
||||
|
|
|
|||
|
|
@ -356,7 +356,7 @@ namespace HRM.UI.Controllers
|
|||
if (userFromRepo != null)
|
||||
{
|
||||
if (userForLoginDto.nextPayProcessDate == null || userForLoginDto.payrollTypeid == 0)
|
||||
{
|
||||
{
|
||||
List<PayrollType> payrollTypes = new List<PayrollType>();
|
||||
payrollTypes = this._payrollTypeService.GetPayrollTypes(userForLoginDto.Username.ToLower());
|
||||
if (payrollTypes != null && payrollTypes.Count > 0)
|
||||
|
|
@ -365,6 +365,36 @@ namespace HRM.UI.Controllers
|
|||
userForLoginDto.payrollTypeid = payrollTypes[0].ID;
|
||||
}
|
||||
}
|
||||
if (isMFA)
|
||||
{
|
||||
int ID = userFromRepo.ID;
|
||||
mfaCode = this.processMFA();
|
||||
var mfaSessionId = Guid.NewGuid().ToString();
|
||||
decimal minutes = mFATimer > 0 ? mFATimer : 2.0m;
|
||||
TimeSpan otpValidity = TimeSpan.FromSeconds((double)(minutes * 60));
|
||||
_cache.Remove($"MFA_{mfaSessionId}");
|
||||
var challenge = new MfaChallenge
|
||||
{
|
||||
UserId = ID,
|
||||
OTP = mfaCode,
|
||||
CreatedAt = DateTime.Now,
|
||||
ExpiredAt = DateTime.Now.Add(otpValidity),
|
||||
AttemptCount = 0
|
||||
};
|
||||
var cacheOptions = new MemoryCacheEntryOptions
|
||||
{
|
||||
AbsoluteExpirationRelativeToNow = otpValidity,
|
||||
Priority = CacheItemPriority.High
|
||||
};
|
||||
_cache.Set($"MFA_{mfaSessionId}", challenge, cacheOptions);
|
||||
WriteToFile("Code ready");
|
||||
this.SendMfaCode(mfaCode, time, userFromRepo);
|
||||
return Ok(new
|
||||
{
|
||||
mfaRequired = true,
|
||||
mfaSessionId = mfaSessionId,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
//userFromRepo = _userService.GetByLoginIDAndPassword(userForLoginDto.Username.ToLower(), userForLoginDto.Password);
|
||||
|
|
@ -600,13 +630,11 @@ namespace HRM.UI.Controllers
|
|||
otpBodyMail = "<p>Your login verification code is: <b>" + mfaCode + "</b></p>";
|
||||
//otpBodyMail += "<p>This code is valid till " + time + ".</p>";
|
||||
otpBodyMail += "<p>This code will expire in next 2 minutes.</p>";
|
||||
|
||||
otpBodySMS = "Your login verification code is: " + mfaCode + ". This code will expire in next 2 minutes.";
|
||||
#endregion
|
||||
|
||||
#region Mail
|
||||
string notificationtypeMail = new SystemConfigarationService().GetconfigStringValue(EnumConfigurationType.Logic, "mfa", "notificationtypeMail");
|
||||
|
||||
if (notificationtypeMail.ToLower() == "yes")
|
||||
{
|
||||
if (!string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(name))
|
||||
|
|
@ -623,30 +651,27 @@ namespace HRM.UI.Controllers
|
|||
WriteToFile($"Mail is sending: {email}, {name}, {mobile}");
|
||||
mailSender.ThreadSendMail(emailSettings);
|
||||
}
|
||||
|
||||
else throw new Exception("Mail Address not found.");
|
||||
|
||||
WriteToFile($"Mail has been sent: {email}, {name}, {mobile}");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SMS
|
||||
string notificationtypeSMS = new SystemConfigarationService().GetconfigStringValue(EnumConfigurationType.Logic, "mfa", "notificationtypeSMS");
|
||||
WriteToFile($"SMS init");
|
||||
|
||||
if (!string.IsNullOrEmpty(mobile))
|
||||
{
|
||||
string mobileNo = new string(mobile.Where(char.IsDigit).ToArray());
|
||||
if (mobileNo.Length == 11) mobileNo = "880" + mobileNo;
|
||||
WriteToFile($"SMS is sending: {email}, {name}, {mobile}");
|
||||
|
||||
await _smsService.SendLoginOtp(mobileNo, otpBodySMS);
|
||||
|
||||
WriteToFile($"SMS has been sent: {email}, {name}, {mobile}");
|
||||
if (notificationtypeSMS.ToLower() == "yes")
|
||||
{
|
||||
WriteToFile($"SMS init");
|
||||
if (!string.IsNullOrEmpty(mobile))
|
||||
{
|
||||
string mobileNo = new string(mobile.Where(char.IsDigit).ToArray());
|
||||
if (mobileNo.Length == 11) mobileNo = "880" + mobileNo;
|
||||
WriteToFile($"SMS is sending: {email}, {name}, {mobile}");
|
||||
await _smsService.SendLoginOtp(mobileNo, otpBodySMS);
|
||||
WriteToFile($"SMS has been sent: {email}, {name}, {mobile}");
|
||||
}
|
||||
else throw new Exception("Mobile Number not found.");
|
||||
}
|
||||
else throw new Exception("Mobile Number not found.");
|
||||
|
||||
#endregion
|
||||
}
|
||||
private void WriteToFile(string text)
|
||||
|
|
@ -829,7 +854,8 @@ namespace HRM.UI.Controllers
|
|||
}
|
||||
#endregion
|
||||
|
||||
token = this.CreateToten(oempUser, omp.PayrollTypeID, null);
|
||||
//token = this.CreateToten(oempUser, omp.PayrollTypeID, null);
|
||||
token = this.CreateTokenNew(oempUser, omp.PayrollTypeID, null, null);
|
||||
}
|
||||
else if (ouser.UserType == EnumUserType.User)
|
||||
{
|
||||
|
|
@ -840,7 +866,15 @@ namespace HRM.UI.Controllers
|
|||
}
|
||||
else payrollTypeId = (int)item["payrollTypeId"].ToObject<int>();
|
||||
PayrollType optype = new PayrollTypeService().Get(payrollTypeId);
|
||||
User guser = this._userService.Get((int)currentUser.EmployeeID, EnumUserType.User);
|
||||
User guser = null;
|
||||
if (currentUser.UserType == EnumUserType.SuperUser && (currentUser.EmployeeID == null || currentUser.EmployeeID == 0))
|
||||
{
|
||||
return BadRequest("Admin access is restricted.");
|
||||
}
|
||||
else
|
||||
{
|
||||
guser = this._userService.Get((int)currentUser.EmployeeID, EnumUserType.User);
|
||||
}
|
||||
if (guser == null)
|
||||
{
|
||||
return BadRequest("Employee is not a Admin user.");
|
||||
|
|
@ -854,14 +888,29 @@ namespace HRM.UI.Controllers
|
|||
if (guser != null)
|
||||
{
|
||||
new UserService().SaveUserLoginHistory(guser.ID);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
|
||||
token = this.CreateToten(guser, optype.ID, optype.NextPayProcessDate);
|
||||
//token = this.CreateToten(guser, optype.ID, optype.NextPayProcessDate);
|
||||
token = this.CreateTokenNew(guser, optype.ID, optype.NextPayProcessDate, null);
|
||||
}
|
||||
else if (ouser.UserType == EnumUserType.SuperUser)
|
||||
else if (ouser.UserType == EnumUserType.SuperUser)
|
||||
{
|
||||
User guser = this._userService.Get((int)currentUser.EmployeeID, EnumUserType.SuperUser);
|
||||
if (item["payrollTypeId"] == null)
|
||||
{
|
||||
|
||||
}
|
||||
payrollTypeId = (int)item["payrollTypeId"].ToObject<int>();
|
||||
PayrollType optype = new PayrollTypeService().Get(payrollTypeId);
|
||||
User guser = null;
|
||||
if (currentUser.EmployeeID == null || currentUser.EmployeeID == 0)
|
||||
{
|
||||
return BadRequest("You do not have permission to access this feature.");
|
||||
}
|
||||
else
|
||||
{
|
||||
guser = this._userService.Get((int)currentUser.EmployeeID, EnumUserType.SuperUser);
|
||||
}
|
||||
if (guser == null)
|
||||
{
|
||||
return BadRequest("Employee is not a Super-User.");
|
||||
|
|
@ -878,7 +927,8 @@ namespace HRM.UI.Controllers
|
|||
}
|
||||
#endregion
|
||||
|
||||
token = this.CreateToten(guser, null, null);
|
||||
//token = this.CreateToten(guser, null, null);
|
||||
token = this.CreateTokenNew(guser, optype.ID, optype.NextPayProcessDate, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user