public ActionResult ZmenitHeslo(string stareHeslo, string noveHeslo, string noveHesloZnovu)
        {
            UzivatelDao uzivatelDao   = new UzivatelDao();
            Uzivatel    staryUzivatel = uzivatelDao.GetById(LoggedUser.Id);

            if (Crypto.VerifyHashedPassword(LoggedUser.Heslo, stareHeslo))
            {
                if (noveHeslo == noveHesloZnovu)
                {
                    staryUzivatel.Heslo = Crypto.HashPassword(noveHeslo);
                    uzivatelDao.Update(staryUzivatel);
                    Success("Heslo úspěšně změněno");
                }
                else
                {
                    Error("Nová hesla se neshodují");
                }
            }
            else
            {
                Error("Zadali jste špatné původní heslo");
            }

            return(RedirectToAction("ZmenaHesla"));
        }
Example #2
0
        public ActionResult Update(Uzivatel u)
        {
            UzivatelDao ud  = new UzivatelDao();
            AdresaDao   ad  = new AdresaDao();
            PscDao      pd  = new PscDao();
            PSC         psc = pd.FindPsc(u.adresa.psc.psc);

            if (psc != null)
            {
                u.adresa.psc = psc;
            }
            else
            {
                pd.Create(u.adresa.psc);
            }
            Adresa adresa = ad.FindAdresa(u.adresa.mesto, u.adresa.ulice, u.adresa.cp, u.adresa.psc);

            if (adresa != null)
            {
                u.adresa = adresa;
            }
            else
            {
                ad.Create(u.adresa);
            }
            u.prava = u.prava;
            ud.Update(u);
            TempData["x"] = "Profil upraven";
            return(RedirectToAction("Index", "Profil"));
        }
Example #3
0
        public static bool UserExists(string windowsId)
        {
            var dao  = new UzivatelDao();
            var item = dao.GetByWindowsId(windowsId.Trim().ToUpper());

            return(item != null);
        }
Example #4
0
        // GET: Uzivatel
        public ActionResult Index()
        {
            var dao  = new UzivatelDao();
            var list = dao.GetAll();

            return(View(list));
        }
Example #5
0
        public ActionResult Prihlaseni(string login, string password)
        {
            UzivatelDao uzivatelDao = new UzivatelDao();
            Uzivatel    u           = uzivatelDao.GetByLogin(login);

            if (u != null)
            {
                if (Membership.ValidateUser(login, PasswordHasher.hashPassword(password)))
                {
                    TempData["x"] = "Úspěšně přihlášen";
                    FormsAuthentication.SetAuthCookie(login, false);
                    if (u.prava.nazev == "Zakaznik")
                    {
                        return(RedirectToAction("Index", "Home", new { area = "" }));
                    }
                    if (u.prava.nazev == "Administrator" || u.prava.nazev == "Zamestnanec")
                    {
                        return(RedirectToAction("Index", "Home", new { area = "Admin" }));
                    }
                    return(RedirectToAction("Index", "Login"));
                }
                TempData["error"] = "Špatně zadané heslo";
                return(RedirectToAction("Index", "Login"));
            }

            TempData["error"] = "uživatel nenalezen";
            return(RedirectToAction("Index", "Login"));
        }
        public override bool ValidateUser(string username, string password)
        {
            UzivatelDao userDao = new UzivatelDao();
            Uzivatel    user    = userDao.GetByLoginAndPassword(username, password);

            return(user != null);
        }
Example #7
0
        public ActionResult Create(Uzivatel collection)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var dao = new UzivatelDao();
                    collection.WindowsId = collection.WindowsId.ToUpper();
                    collection.Id        = (int)dao.Create(collection);
                    if (collection.Role.Id > 0)
                    {
                        var permDao = new PermissionDao();
                        permDao.Create(new Permission()
                        {
                            Role      = collection.Role,
                            WindowsId = collection.WindowsId
                        });
                    }

                    TempData[MessagesHelper.Success] = Resources.UzivatelTexts.UserAdded;
                    return(RedirectToAction("Index"));
                }
                else
                {
                    TempData[MessagesHelper.Warning] = "Zkontrolujte zadané údaje";
                }
            }
            catch
            {
                TempData[MessagesHelper.Warning] = "Zkontrolujte zadané údaje";
            }
            return(View(collection));
        }
Example #8
0
        public ActionResult EditUzivatel(int id)
        {
            var dao  = new UzivatelDao();
            var item = dao.GetById(id);

            return(View(item));
        }
Example #9
0
        public ActionResult Index()
        {
            UzivatelDao userDao = new UzivatelDao();
            Uzivatel    user    = userDao.GetByLogin(User.Identity.Name);

            return(View(user));
        }
        public ActionResult Vytvorit(Uzivatel uzivatel, int skupinaId)
        {
            UzivatelDao uzivatelDao  = new UzivatelDao();
            Uzivatel    novyUzivatel = uzivatelDao.GetByLogin(uzivatel.Login);

            if (novyUzivatel != null)
            {
                TempData["error-message"] = "Uživatel s tímto uživ. jménem již existuje";
                return(RedirectToAction("PridatUzivatele"));
            }

            SkupinaDao skupinaDao = new SkupinaDao();
            Skupina    skupina    = skupinaDao.GetById(skupinaId);

            skupinaDao.CloseSession();

            UzivatelskaRoleDao uzivatelskaRoleDao = new UzivatelskaRoleDao();
            UzivatelskaRole    role = uzivatelskaRoleDao.GetRoleWithName("uzivatel");

            uzivatelskaRoleDao.CloseSession();

            Uzivatel admin = uzivatelDao.GetByLogin(User.Identity.Name);

            uzivatel.Skupina  = skupina;
            uzivatel.Vytvoril = admin;
            uzivatel.Role     = role;

            if (ModelState.IsValid)
            {
                uzivatelDao.CreateWithHashedPassword(uzivatel);
                TempData["message-success"] = "Uživatel úspěšne přidán";
            }

            return(RedirectToAction("Index", "Uzivatel"));
        }
Example #11
0
        public ActionResult Index(int?strana)
        {
            UzivatelDao uzivatelDao = new UzivatelDao();
            Uzivatel    uzivatel    = uzivatelDao.GetByLogin(User.Identity.Name);
            SkupinaDao  skupinaDao  = new SkupinaDao();

            int page = strana.HasValue ? strana.Value : 1;
            int totalItems;

            IList <Skupina> skupiny = skupinaDao.GetMyGroupsPaged(LoggedUser, ItemsOnPage, page, out totalItems);

            ViewBag.Pages       = (int)Math.Ceiling((double)totalItems / (double)ItemsOnPage);
            ViewBag.CurrentPage = page;

            ViewBag.ListJePrazdny = false;

            if (skupiny.Count == 0)
            {
                ViewBag.ListJePrazdny = true;
            }

            ViewBag.MeSkupiny = skupiny;

            return(View());
        }
        public ActionResult UpravitInformace()
        {
            UzivatelDao uzivatelDao = new UzivatelDao();
            Uzivatel    uzivatel    = uzivatelDao.GetById(LoggedUser.Id);

            return(View(uzivatel));
        }
Example #13
0
        public ActionResult Index()
        {
            Uzivatel          u         = new UzivatelDao().GetByLogin(User.Identity.Name);
            RezervaceDao      rd        = new RezervaceDao();
            IList <Rezervace> rezervace = rd.GetByUser(u.Id);

            return(View(rezervace));
        }
Example #14
0
        public JsonResult SearchUzivatel(string query)
        {
            UzivatelDao      uzivatelDao = new UzivatelDao();
            IList <Uzivatel> uzivatele   = uzivatelDao.SearchByLogin(query);
            List <string>    names       = (from Uzivatel u in uzivatele select u.login).ToList();

            return(Json(names, JsonRequestBehavior.AllowGet));
        }
Example #15
0
        public ActionResult RemoveDilnaFromUzivatel(int uzivatelId, int dilnaId)
        {
            var dao  = new UzivatelDao();
            var item = dao.GetById(uzivatelId);

            item.DilnyUzivatelu.Remove(item.DilnyUzivatelu.Single(s => s.Dilna.Id == dilnaId));
            dao.Update(item);
            return(RedirectToAction("EditUzivatel", new { id = uzivatelId }));
        }
        public ActionResult Odstranit(int id)
        {
            UzivatelDao uzivatelDao = new UzivatelDao();
            Uzivatel    uzivatel    = uzivatelDao.GetById(id);

            uzivatelDao.Delete(uzivatel);
            TempData["message-success"] = "Uživatel byl úspěšně odstraněn";
            return(RedirectToAction("Index", "Uzivatel"));
        }
Example #17
0
        public JsonResult doesUserNameExist(string login)
        {
            UzivatelDao ud = new UzivatelDao();

            login.Trim();
            Uzivatel user = ud.GetByLogin(login);

            return(Json(user == null));
        }
        public ActionResult Editace(int id)
        {
            UzivatelDao uzivatelDao = new UzivatelDao();
            Uzivatel    uzivatel    = uzivatelDao.GetById(id);

            SkupinaDao      skupinaDao = new SkupinaDao();
            IList <Skupina> skupiny    = skupinaDao.GetMyGroups(LoggedUser);

            ViewBag.Skupiny = skupiny;
            return(View(uzivatel));
        }
Example #19
0
        public ActionResult Search(string phrase)
        {
            UzivatelDao      uzivatelDao = new UzivatelDao();
            IList <Uzivatel> uzivatele   = uzivatelDao.SearchByLogin(phrase);

            if (Request.IsAjaxRequest())
            {
                return(PartialView("Index", uzivatele));
            }
            return(View("Index", uzivatele));
        }
Example #20
0
        public ActionResult OdstranitUzivateleZeSkupiny(int uzivatelId, int skupinaId)
        {
            UzivatelDao uzivatelDao = new UzivatelDao();
            Uzivatel    uzivatel    = uzivatelDao.GetById(uzivatelId);

            uzivatel.Skupina = null;
            uzivatelDao.Update(uzivatel);
            TempData["message-success"] =
                "Uživatel " + uzivatel.Jmeno + " " + uzivatel.Prijmeni + " byl úspěšně odebrán ze skupiny";
            return(RedirectToAction("Detail", new { id = skupinaId }));
        }
Example #21
0
        public static IList <SelectListItem> GetSelectListUzivatele()
        {
            var dao  = new UzivatelDao();
            var list = dao.GetAll();

            return(list.OrderBy(x => x.Prijmeni).Select(m => new SelectListItem()
            {
                Value = m.Id.ToString(),
                Text = m.ToString()
            }).ToList());
        }
Example #22
0
        public IEnumerable <UzivatelShort> Get()
        {
            var dao = new UzivatelDao();

            return(dao.GetAll().Select(item => new UzivatelShort()
            {
                Jmeno = item.Jmeno,
                Prijmeni = item.Prijmeni,
                WindowsId = item.WindowsId
            })
                   .ToList());
        }
Example #23
0
        public IEnumerable <UzivatelShort> Get(int oddeleniId)
        {
            var dao = new UzivatelDao();

            return(dao.GetAllNotVedouciOddeleni(new OddeleniDao().GetById(oddeleniId)).Select(item => new UzivatelShort()
            {
                Jmeno = item.Jmeno,
                Prijmeni = item.Prijmeni,
                WindowsId = item.WindowsId
            })
                   .ToList());
        }
Example #24
0
        public ActionResult Edit(int id)
        {
            var dao  = new UzivatelDao();
            var item = dao.GetById(id);

            if (item == null)
            {
                return(RedirectToAction("Index"));
            }
            item.LoadPermission();
            return(View(item));
        }
Example #25
0
        public ActionResult Detail(int?id)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction("Index"));
            }
            Uzivatel     u  = new UzivatelDao().GetById(id.Value);
            RezervaceDao rd = new RezervaceDao();

            ViewBag.Rezervace = rd.GetByUser(u.Id);
            return(View(u));
        }
Example #26
0
        public override string[] GetRolesForUser(string username)
        {
            UzivatelDao knihovnaUserDao = new UzivatelDao();
            Uzivatel    user            = knihovnaUserDao.GetByLogin(username);

            if (user == null)
            {
                return(new string[] {});
            }

            return(new string[] { user.prava.nazev });
        }
Example #27
0
        public override bool IsUserInRole(string username, string roleName)
        {
            UzivatelDao uzivatelDao = new UzivatelDao();
            Uzivatel    user        = uzivatelDao.GetByLogin(username);

            if (user == null)
            {
                return(false);
            }

            return(user.prava.nazev == roleName);
        }
Example #28
0
        // GET: Admin/Uzivatele
        public ActionResult Index(int?page)
        {
            int pg;
            int itemsOnPage = 20;

            if (page.HasValue)
            {
                pg = page.Value;
            }
            else
            {
                pg = 1;
            }
            pg = (pg <= 0) ? 1 : pg;
            int totalUsers;
            int totalPages;

            UzivatelDao      uzivatelDao = new UzivatelDao();
            IList <Uzivatel> uzivatele   = uzivatelDao.GetUsersPaged(itemsOnPage, pg, out totalUsers);

            totalPages = totalUsers / itemsOnPage;
            if (totalPages == 0)
            {
                totalPages = 1;
            }
            if (pg > totalPages)
            {
                pg        = totalPages;
                uzivatele = uzivatelDao.GetUsersPaged(itemsOnPage, pg, out totalUsers);
            }

            ViewBag.Pages       = (int)Math.Ceiling((double)totalUsers / (double)itemsOnPage);
            ViewBag.CurrentPage = pg;
            if (pg < 3)
            {
                ViewBag.FirstPage = 1;
                ViewBag.LastPage  = 5;
            }
            else
            {
                ViewBag.FirstPage = pg - 2;
                ViewBag.LastPage  = pg + 2;
            }
            if (ViewBag.LastPage > totalPages)
            {
                ViewBag.LastPage = totalPages;
            }

            return(View(uzivatele));
        }
Example #29
0
        public ActionResult Edit(int id, Uzivatel collection)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var dao = new UzivatelDao();
                    collection.WindowsId = collection.WindowsId.ToUpper();
                    dao.Update(collection);

                    var permDao  = new PermissionDao();
                    var permItem = permDao.GetByUser(collection);
                    if (collection.Role.Id == 0)
                    {
                        if (permItem != null)
                        {
                            permDao.Delete(permItem);
                        }
                    }
                    else
                    {
                        if (permItem == null)
                        {
                            permDao.Create(new Permission()
                            {
                                Role      = collection.Role,
                                WindowsId = collection.WindowsId
                            });
                        }
                        else if (permItem.Role.Id != collection.Role.Id)
                        {
                            permItem.Role.Id = collection.Role.Id;
                            permDao.Update(permItem);
                        }
                    }

                    TempData[MessagesHelper.Success] = Resources.UzivatelTexts.UserUpdated;
                    return(RedirectToAction("Index"));
                }
                else
                {
                    TempData[MessagesHelper.Warning] = "Zkontrolujte zadané údaje";
                }
            }
            catch
            {
                TempData[MessagesHelper.Warning] = "Zkontrolujte zadané údaje";
            }
            return(View(collection));
        }
Example #30
0
        public ActionResult Autorizuj(int?id)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction("Index"));
            }
            UzivatelDao      uzivatelDao = new UzivatelDao();
            Uzivatel         u           = uzivatelDao.GetById(id.Value);
            UzivatelskaPrava prava       = new UzivatelskaPravaDao().FindPrava(2);

            u.prava = prava;
            uzivatelDao.Update(u);
            return(RedirectToAction("Index"));
        }