Example #1
0
        public IActionResult MyProfile(Models.MyProfileViewModel v)
        {
            if (ModelState.IsValid)
            {
                if (string.IsNullOrEmpty(v.EmailAddres) == true)
                {
                    this.AddMessage("Chybí e-mail adresa.");
                    return(MyProfile());
                }
                BO.j02Person c = Factory.j02PersonBL.Load(Factory.CurrentUser.j02ID);
                c.j02Email = v.EmailAddres;
                if (Factory.j02PersonBL.Save(c) > 0)
                {
                    BO.j03User cUser = Factory.j03UserBL.Load(Factory.CurrentUser.pid);
                    if (v.IsGridClipboard == true)
                    {
                        cUser.j03GridSelectionModeFlag = 1;
                    }
                    else
                    {
                        cUser.j03GridSelectionModeFlag = 0;
                    }
                    Factory.j03UserBL.Save(cUser);
                    Factory.CurrentUser.AddMessage("Změny uloženy", "info");
                }
            }

            return(MyProfile());
        }
Example #2
0
        public Result VerifyHash(string strPwd, string strLogin, BO.j03User cSavedJ03)
        {
            var hasher  = new BO.COM.PasswordHasher();
            var overeni = hasher.VerifyHashedPassword(cSavedJ03.j03PasswordHash, getSul(strLogin, strPwd, cSavedJ03.pid));

            if (overeni == BO.COM.PasswordVerificationResult.Failed)
            {
                return(new Result(true, "Ověření uživatele se nezdařilo - pravděpodobně chybné heslo nebo jméno!"));
            }
            else
            {
                return(new Result(false));
            }
        }
Example #3
0
        public string Pwd2Hash(string strPwd, BO.j03User cJ03)
        {
            var hasher = new BO.COM.PasswordHasher();

            return(hasher.HashPassword(getSul(cJ03.j03Login, strPwd, cJ03.pid)));
        }
Example #4
0
        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));
        }
Example #5
0
        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));
            }
        }