public HttpResponseMessage GetLoginPolicies(string ipAddress) { var dateStart = DateTime.Now; _performancelog.Debug($"Start,PolicyController,GetLoginPolicies,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}"); ErrorMessage error; string message; var posId = _loginManager.Authenticate(ipAddress, out message, out error); if (!string.IsNullOrEmpty(error.MessageStyle.Message)) { _performancelog.Debug($"End,PolicyController,GetLoginPolicies,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}"); return(Request.CreateResponse( error.StatusCode, new InvalidLoginReponseModel { Error = error.MessageStyle, ShutDownPOS = error.ShutDownPos })); } if (posId == 0) { var offSet = _policyManager.LoadStoreInfo().OffSet; _performancelog.Debug($"End,PolicyController,GetLoginPolicies,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}"); return(Request.CreateResponse( HttpStatusCode.Unauthorized, new InvalidLoginReponseModel { Error = new MessageStyle { Message = _resourceManager.GetResString(8198, offSet) }, ShutDownPOS = error.ShutDownPos })); } if (!_tillManager.IsActiveTillAvailable(posId, out error)) { _performancelog.Debug($"End,PolicyController,GetLoginPolicies,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}"); return(Request.CreateResponse( error.StatusCode, new InvalidLoginReponseModel { Error = error.MessageStyle, ShutDownPOS = error.ShutDownPos })); } var policies = _policyManager.GetLoginPolicies(ipAddress, posId); _performancelog.Debug($"End,PolicyController,GetLoginPolicies,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}"); return(Request.CreateResponse(HttpStatusCode.OK, new { policies, message })); }
public async Task <IActionResult> Login([FromBody] LoginRequest request) { var user = await _userManager.GetItem(request); if (user == null) { return(Unauthorized()); } var loginResponse = await _loginManager.Authenticate(user); return(Ok(loginResponse)); }
public void AuthenticateTest() { var expected = 1; var ipAddress = "172.16.0.0"; string message; ErrorMessage error; _policyManager.Setup(l => l.LoadSecurityInfo()).Returns(LoadSecurityInfo); _loginManager = new LoginManager(_utilityService.Object, _userService.Object, _loginService.Object, _resourceManager, _tillService.Object, _shiftService.Object, _policyManager.Object); var actual = _loginManager.Authenticate(ipAddress, out message, out error); Assert.IsNotNull(error.MessageStyle.Message); }
public void AuthenticateForExpiringDateTest() { _policyManager.Setup(l => l.LoadSecurityInfo()).Returns(LoadEmptySecurityCodeAdvancedInstallDateInfo()); _loginManager = new LoginManager(_utilityService.Object, _userService.Object, _loginService.Object, _resourceManager, _tillService.Object, _shiftService.Object, _policyManager.Object); var expected = "License Expired. Please get a Valid Security Code from your Dealer."; var ipAddress = "172.0.0.0"; string message; ErrorMessage error; _loginManager.Authenticate(ipAddress, out message, out error); Assert.AreEqual(expected, error.MessageStyle.Message); Assert.AreEqual(System.Net.HttpStatusCode.Unauthorized, error.StatusCode); Assert.IsTrue(error.ShutDownPos); }
public void AuthenticateForInvalidDateTest() { _policyManager.Setup(l => l.LoadSecurityInfo()).Returns(LoadInvalidDateInfo()); _loginManager = new LoginManager(_utilityService.Object, _userService.Object, _loginService.Object, _resourceManager, _tillService.Object, _shiftService.Object, _policyManager.Object); var expected = "You don't have permission to login to POS. Please contact your Dealer."; var ipAddress = "172.0.0.0"; string message; ErrorMessage error; _loginManager.Authenticate(ipAddress, out message, out error); Assert.AreEqual(expected, error.MessageStyle.Message); Assert.AreEqual(System.Net.HttpStatusCode.Unauthorized, error.StatusCode); Assert.IsTrue(error.ShutDownPos); }
public IActionResult Authenticate([FromBody] AuthenticationRequest authenticationRequest) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var response = _loginManager.Authenticate(authenticationRequest); return(new JsonResult(response)); } catch (Exception) { var response = new AuthenticationResponse { status = false, authToken = "" }; return(new JsonResult(response)); } }
public bool LogOnUser(string userName, string password) { _loginManager.Authenticate(userName, password); return(_loginManager.IsAuthenticated); }
public HttpResponseMessage GetActiveTheme(string ipAddress) { var dateStart = DateTime.Now; _performancelog.Debug($"Start,ThemeV1Controller,GetActiveTheme,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}"); ErrorMessage error; string message; var posId = _loginManager.Authenticate(ipAddress, out message, out error); if (!string.IsNullOrEmpty(error.MessageStyle.Message)) { _performancelog.Debug($"End,ThemeV1Controller,GetActiveTheme,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}"); return(Request.CreateResponse( error.StatusCode, new InvalidLoginReponseModel { Error = error.MessageStyle, ShutDownPOS = error.ShutDownPos })); } if (posId == 0) { _performancelog.Debug($"End,ThemeV1Controller,GetActiveTheme,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}"); var store = CacheManager.GetStoreInfo(); var offSet = store?.OffSet ?? 0; return(Request.CreateResponse( HttpStatusCode.Unauthorized, new InvalidLoginReponseModel { Error = new MessageStyle { Message = _resourceManager.GetResString(8198, offSet) }, ShutDownPOS = error.ShutDownPos })); } var theme = _themeManager.GetActiveTheme(); if (theme != null) { return(Request.CreateResponse (HttpStatusCode.OK, new ThemeModel { BackgroundColor1Light = theme.Data.FirstOrDefault(x => x.Name == "BackgroundColor1Light")?.ColorCode, BackgroundColor1Dark = theme.Data.FirstOrDefault(x => x.Name == "BackgroundColor1Dark")?.ColorCode, BackgroundColor2 = theme.Data.FirstOrDefault(x => x.Name == "BackgroundColor2")?.ColorCode, ButtonFooterConfirmationColor = theme.Data.FirstOrDefault(x => x.Name == "ButtonFooterConfirmationColor")?.ColorCode, ButtonFooterWarningColor = theme.Data.FirstOrDefault(x => x.Name == "ButtonFooterWarningColor")?.ColorCode, HeaderBackgroundColor = theme.Data.FirstOrDefault(x => x.Name == "ButtonBackgroundColor")?.ColorCode, HeaderForegroundColor = theme.Data.FirstOrDefault(x => x.Name == "ButtonForegroundColor")?.ColorCode, ButtonFooterColor = theme.Data.FirstOrDefault(x => x.Name == "ButtonFooterColor")?.ColorCode, LabelTextForegroundColor = theme.Data.FirstOrDefault(x => x.Name == "LabelTextForegroundColor")?.ColorCode })); } return(Request.CreateResponse( HttpStatusCode.NotFound, new ErrorResponse { Error = new MessageStyle { Message = "There are no themes defined!" } })); }