private void Write2Accesslog(BO.LoggingUser lu) { BO.j90LoginAccessLog c = new BO.j90LoginAccessLog() { j90BrowserUserAgent = lu.Browser_UserAgent, j90BrowserAvailWidth = lu.Browser_AvailWidth, j90BrowserAvailHeight = lu.Browser_AvailHeight, j90BrowserInnerWidth = lu.Browser_InnerWidth, j90BrowserInnerHeight = lu.Browser_InnerHeight }; if (_f.CurrentUser != null) { c.j03ID = _f.CurrentUser.pid; } var uaParser = UAParser.Parser.GetDefault(); UAParser.ClientInfo client_info = uaParser.Parse(lu.Browser_UserAgent); c.j90BrowserOS = client_info.OS.Family + " " + client_info.OS.Major; c.j90BrowserFamily = client_info.UA.Family + " " + client_info.UA.Major; c.j90BrowserDeviceFamily = client_info.Device.Family; c.j90BrowserDeviceType = lu.Browser_DeviceType; c.j90LoginMessage = lu.Message; c.j90LoginName = lu.Login; c.j90CookieExpiresInHours = lu.CookieExpiresInHours; c.j90LocationHost = lu.Browser_Host; _f.Write2AccessLog(c); }
public ActionResult UserLogin() { if (User.Identity.IsAuthenticated) { TryLogout(); } var v = new BO.LoggingUser(); return(View(v)); }
public IActionResult ChangePassword(Models.ChangePasswordViewModel v) { var cJ03 = Factory.j03UserBL.Load(Factory.CurrentUser.pid); var lu = new BO.LoggingUser(); var ret = lu.ValidateChangePassword(v.NewPassword, v.CurrentPassword, v.VerifyPassword, cJ03); if (ret.Flag == BO.ResultEnum.Success) { cJ03.j03PasswordHash = lu.Pwd2Hash(v.NewPassword, cJ03); cJ03.j03IsMustChangePassword = false; if (Factory.j03UserBL.Save(cJ03) > 0) { Factory.CurrentUser.AddMessage("Heslo bylo změněno.", "info"); return(RedirectToAction("Index")); } } else { Factory.CurrentUser.AddMessage(ret.Message); } return(View(v)); }
private bool ValidateBeforeSave(BO.j02Person c, j02RecordViewModel v) { if (v.IsUserProfile) { if (!string.IsNullOrEmpty(v.ResetPassword)) { var lu = new BO.LoggingUser(); var res = lu.ValidatePassword(v.ResetPassword); if (res.Flag == BO.ResultEnum.Failed) { Factory.CurrentUser.AddMessage(res.Message); return(false); } } if (string.IsNullOrEmpty(v.UserProfile.j03Login) || v.UserProfile.j04ID == 0) { Factory.CurrentUser.AddMessage("Uživatel musí mít vyplněný uživatelský účet."); return(false); } if ((c.j03ID == 0 && string.IsNullOrEmpty(v.ResetPassword))) { Factory.CurrentUser.AddMessage("Pro nového uživatele musíte definovat výchozí heslo."); return(false); } if (c.p28ID == 0 || Factory.p21LicenseBL.HasClientValidLicense(c.p28ID) == false) { Factory.CurrentUser.AddMessage("Osoba s uživatelským účtem musí mít vazbu na subjekt (firmu) s platnou licencí užívat tento software."); return(false); } if (Factory.j03UserBL.GetList(new BO.myQuery("j03User")).Where(p => p.pid != c.j03ID && p.j03Login.ToUpper() == v.UserProfile.j03Login.ToUpper()).Count() > 0) { Factory.CurrentUser.AddMessage("Uživatel s tímto loginem již existuje."); return(false); } } return(true); }
public IActionResult Record(Models.j02RecordViewModel v) { if (ModelState.IsValid) { BO.j02Person c = new BO.j02Person(); if (v.Rec.pid > 0) { c = Factory.j02PersonBL.Load(v.Rec.pid); } c.p28ID = v.Rec.p28ID; c.j02TitleBeforeName = v.Rec.j02TitleBeforeName; c.j02TitleAfterName = v.Rec.j02TitleAfterName; c.j02FirstName = v.Rec.j02FirstName; c.j02LastName = v.Rec.j02LastName; c.j02Email = v.Rec.j02Email; c.j02Tel1 = v.Rec.j02Tel1; c.j02Tel2 = v.Rec.j02Tel2; c.j02JobTitle = v.Rec.j02JobTitle; c.j02ID_Owner = v.Rec.j02ID_Owner; c.ValidUntil = v.Toolbar.GetValidUntil(c); c.ValidFrom = v.Toolbar.GetValidFrom(c); if (ValidateBeforeSave(c, v)) { v.Rec.pid = Factory.j02PersonBL.Save(c); if (v.Rec.pid > 0) { Factory.o51TagBL.SaveTagging("j02", v.Rec.pid, v.TagPids); c = Factory.j02PersonBL.Load(v.Rec.pid); if (v.IsUserProfile == false) { v.SetJavascript_CallOnLoad(v.Rec.pid); return(View(v)); } } if (c.pid > 0 && v.IsUserProfile == true) { BO.j03User cU = new BO.j03User(); cU.j02ID = c.pid; if (c.j03ID > 0) { cU = Factory.j03UserBL.Load(c.j03ID); } cU.j04ID = v.UserProfile.j04ID; cU.j03Login = v.UserProfile.j03Login; cU.j03IsMustChangePassword = v.UserProfile.j03IsMustChangePassword; cU.ValidUntil = c.ValidUntil; if (c.j03ID == 0) { var recJ04 = Factory.j04UserRoleBL.Load(cU.j04ID); if (recJ04.j04IsClientRole) { cU.j03EnvironmentFlag = 2; //client prostředí } else { cU.j03EnvironmentFlag = 1; //master prostředí } } if (!string.IsNullOrEmpty(v.ResetPassword)) { var lu = new BO.LoggingUser(); cU.j03PasswordHash = lu.Pwd2Hash(v.ResetPassword, cU); } int intJ03ID = Factory.j03UserBL.Save(cU); if (intJ03ID > 0) { if (cU.j03ID == 0) //nahodit první heslo pro nového uživatele { cU = Factory.j03UserBL.Load(intJ03ID); var lu = new BO.LoggingUser(); cU.j03PasswordHash = lu.Pwd2Hash(v.ResetPassword, cU); Factory.j03UserBL.Save(cU); } v.SetJavascript_CallOnLoad(v.Rec.pid); return(View(v)); } } } } RefreshState(v); this.Notify_RecNotSaved(); return(View(v)); }
public ActionResult UserLogin([Bind] BO.LoggingUser lu, string returnurl) { _f.InhaleUserByLogin(lu.Login); if (_f.CurrentUser == null) { lu.Message = "Přihlášení se nezdařilo - pravděpodobně chybné heslo nebo jméno!"; Write2Accesslog(lu); return(View(lu)); } if (_f.CurrentUser.isclosed) { lu.Message = "Uživatelský účet je uzavřený pro přihlašování!"; Write2Accesslog(lu); return(View(lu)); } BO.j03User cJ03 = _f.j03UserBL.LoadByLogin(lu.Login); BO.j04UserRole cJ04 = _f.j04UserRoleBL.Load(cJ03.j04ID); if (cJ04.j04IsClientRole && _f.p21LicenseBL.HasClientValidLicense(_f.CurrentUser.p28ID) == false) { lu.Message = "Subjekt, s kterým je svázaný váš osobní profil, nemá ani jednu platnou licenci!"; Write2Accesslog(lu); return(View(lu)); } if (lu.Password == "hash") { lu.Message = lu.Pwd2Hash("123456", cJ03); return(View(lu)); } var ret = lu.VerifyHash(lu.Password, lu.Login, cJ03); if (ret.Flag == BO.ResultEnum.Failed) { lu.Message = "Ověření uživatele se nezdařilo - pravděpodobně chybné heslo nebo jméno!"; Write2Accesslog(lu); return(View(lu)); } //ověřený if (cJ03.j02Email == null) { cJ03.j02Email = "*****@*****.**"; } var userClaims = new List <Claim>() { new Claim(ClaimTypes.Name, lu.Login), new Claim("access_token", "hovado1"), new Claim(ClaimTypes.Email, cJ03.j02Email) }; var grandmaIdentity = new ClaimsIdentity(userClaims, "User Identity"); var userPrincipal = new ClaimsPrincipal(new[] { grandmaIdentity }); //prodloužit expiraci cookie na CookieExpiresInHours hodin var xx = new AuthenticationProperties() { IsPersistent = true, ExpiresUtc = DateTime.Now.AddHours(lu.CookieExpiresInHours) }; HttpContext.SignInAsync(userPrincipal, xx); Write2Accesslog(lu); if (returnurl == null) { return(RedirectToAction("Index", "Home")); } else { return(Redirect(returnurl)); } }