Exemple #1
0
        public async Task <IActionResult> OdjaviSe()
        {
            ZaposlenikISZRSWebUser zaposlenik = await _userManager.FindByNameAsync(HttpContext.User.Identity.Name);

            if (await _userManager.IsInRoleAsync(zaposlenik, "Administrator"))
            {
                await _signInManager.SignOutAsync();

                return(RedirectToAction("Index", "Home", new { area = "" }));
            }



            Ugovori ugovor = UserDB.UgovoriORadu.Where(x => x.ZaposlenikKorisnickoIme == HttpContext.User.Identity.Name).SingleOrDefault();

            DolasciNaPosao dolazak = UserDB.DolasciNaPosao.Where(x => x.DatumDolaska.Date == DateTime.Today && x.UgovorOraduId == ugovor.Id).SingleOrDefault();

            dolazak.DatumOdlaska = DateTime.Now;
            dolazak.BrojSati     = (dolazak.DatumOdlaska - dolazak.DatumDolaska).Hours;
            UserDB.DolasciNaPosao.Update(dolazak);
            UserDB.SaveChanges();

            await _signInManager.SignOutAsync();

            return(RedirectToAction("Index", "Home", new { area = "" }));
        }
        public ActionResult Create(RegisterModel webUser, int Uloga, IFormFile Slika)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    ZaposlenikISZRSWebUser novi = new ZaposlenikISZRSWebUser();

                    if (Slika.Length > 0)
                    {
                        byte[] SlikaBitovi = null;
                        using (var fs1 = Slika.OpenReadStream())
                            using (var ms1 = new MemoryStream())
                            {
                                fs1.CopyTo(ms1);
                                SlikaBitovi = ms1.ToArray();
                            }

                        novi.Slika = SlikaBitovi;
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                return(View());
            }
            catch
            {
                return(View());
            }
        }
        public async Task <IActionResult> DolasciNaPosao(string KorisnickoIme)
        {
            ZaposlenikISZRSWebUser zaposlenik = await _userManager.FindByNameAsync(KorisnickoIme);

            Ugovori ugovor = UserDB.UgovoriORadu.Where(x => x.ZaposlenikKorisnickoIme == KorisnickoIme).SingleOrDefault();

            List <DolasciNaPosao> dolasci = UserDB.DolasciNaPosao.Where(x => x.UgovorOraduId == ugovor.Id).ToList();

            return(View(dolasci));
        }
Exemple #4
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            ZaposlenikISZRSWebUser user1 = await _userManager.GetUserAsync(HttpContext.User);


            IList <string> uloge = await _userManager.GetRolesAsync(user);

            KorisnikInfo korisnikInfo = new KorisnikInfo(user1, uloge);

            return(View("KorisnikVC", korisnikInfo));
        }
Exemple #5
0
        private void CreateRoles(IServiceProvider serviceProvider)
        {
            var roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >();
            var userManager = serviceProvider.GetRequiredService <UserManager <ZaposlenikISZRSWebUser> >();
            Task <IdentityResult> roleResult;
            string email = "*****@*****.**";

            //Check that there is an Administrator role and create if not
            Task <bool> hasAdminRole = roleManager.RoleExistsAsync("Administrator");

            hasAdminRole.Wait();

            if (!hasAdminRole.Result)
            {
                roleResult = roleManager.CreateAsync(new IdentityRole("Administrator"));
                roleResult.Wait();
            }

            ProvjeriDodajUlogu("Recepcionar", roleManager);
            ProvjeriDodajUlogu("Logisticar", roleManager);



            //Check if the admin user exists and create it if not
            //Add to the Administrator role

            Task <ZaposlenikISZRSWebUser> testUser = userManager.FindByEmailAsync(email);

            testUser.Wait();

            if (testUser.Result == null)
            {
                ZaposlenikISZRSWebUser Administrator = new ZaposlenikISZRSWebUser();
                Administrator.Email    = email;
                Administrator.UserName = "******";
                Administrator.Ime      = "Adin";
                Administrator.Prezime  = "Sijamija";
                Administrator.JMBG     = "1234567890123";


                Task <IdentityResult> newUser = userManager.CreateAsync(Administrator, "AdinSijamija_23");
                newUser.Wait();

                if (newUser.Result.Succeeded)
                {
                    Task <IdentityResult> newUserRole = userManager.AddToRoleAsync(Administrator, "Administrator");
                    newUserRole.Wait();
                }
            }
        }
Exemple #6
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");

            if (ModelState.IsValid)
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true


                var result = await _signInManager.PasswordSignInAsync(Input.UserName, Input.Password, false, false);



                //var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: true);
                if (result.Succeeded)
                {
                    _logger.LogInformation("User logged in.");

                    ZaposlenikISZRSWebUser zaposlenik = await _userManager.FindByNameAsync(Input.UserName);

                    bool JeAdmin = await _userManager.IsInRoleAsync(zaposlenik, "Administrator");

                    if (JeAdmin)
                    {
                        return(RedirectToAction("Index", "Pocetna", new { area = "Administracija" }));
                    }
                    bool JeLogisticar = await _userManager.IsInRoleAsync(zaposlenik, "Logisticar");

                    if (JeLogisticar)
                    {
                        return(RedirectToAction("Logistika", "Pocetna", new { area = "Administracija" }));
                    }
                    bool JeRecepcionar = await _userManager.IsInRoleAsync(zaposlenik, "Recepcionar");

                    if (JeRecepcionar)
                    {
                        return(RedirectToAction("Index", "Pocetna", new { area = "Recepcija" }));
                    }



                    return(LocalRedirect(returnUrl));
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, Input.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning("User account locked out.");
                    return(RedirectToPage("./Lockout"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return(Page());
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            bool validanUgovor = true;

            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var user = new ZaposlenikISZRSWebUser
                {
                    UserName     = Input.Ime + Input.Prezime,
                    PhoneNumber  = Input.PhoneNumber,
                    Ime          = Input.Ime,
                    Prezime      = Input.Prezime,
                    DatumRođenja = Input.DatumRođenja,
                    JMBG         = Input.JMBG,


                    Email = null
                };

                if (SlikaFile != null)
                {
                    if (SlikaFile.Length > 0)
                    {
                        byte[] SlikaBitovi = null;
                        using (var fs1 = SlikaFile.OpenReadStream())
                            using (var ms1 = new MemoryStream())
                            {
                                fs1.CopyTo(ms1);
                                SlikaBitovi = ms1.ToArray();
                            }

                        user.Slika = SlikaBitovi;
                    }
                }

                if (!String.IsNullOrEmpty(Input.KorisnickoIme))
                {
                    var postojeci = await _userManager.FindByNameAsync(Input.KorisnickoIme);

                    if (postojeci != null)
                    {
                        user.UserName = Input.KorisnickoIme;
                    }
                }



                if (Ugovor.DatumPocetkaUgovora < DateTime.Now)
                {
                    ModelState.AddModelError(string.Empty, "Datum pocetka mora biti veći od jučernjašeg datuma");
                    validanUgovor = false;
                }

                if (Ugovor.DatumPocetkaUgovora > Ugovor.DatumZavrsetkaUgovora)
                {
                    ModelState.AddModelError(string.Empty, "Datum pocetka mora biti veći od datuma završetka ugovora");
                    validanUgovor = false;
                }

                if ((Ugovor.DatumZavrsetkaUgovora - Ugovor.DatumPocetkaUgovora).TotalDays < 30)
                {
                    ModelState.AddModelError(string.Empty, "ugovor mora trajati najmanje 1 mjesec");
                    validanUgovor = false;
                }

                if (validanUgovor)
                {
                    var result = await _userManager.CreateAsync(user, Input.Password);

                    if (result.Succeeded)
                    {
                        switch (TipKorisnika)
                        {
                        case 1:
                            await _userManager.AddToRoleAsync(user, "Recepcionar");

                            break;

                        case 2:
                            await _userManager.AddToRoleAsync(user, "Logisticar");

                            break;

                        default:
                            break;
                        }


                        _logger.LogInformation("User created a new account with password.");



                        Ugovor.ZaposlenikKorisnickoIme = user.UserName;
                        await UserDB.UgovoriORadu.AddAsync(Ugovor);

                        await UserDB.SaveChangesAsync();


                        return(RedirectToAction("Index", "Zaposlenici", new { area = "Administracija" }));
                    }
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(string.Empty, error.Description);
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Exemple #8
0
        public async Task <IActionResult> PrijaviSe(string username, string password)
        {
            if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
            {
                TempData["Error"] = "Polje KorisnickoIme/Lozinka su prazne";
                return(RedirectToAction("Index", "Home"));
            }

            var result = await _signInManager.PasswordSignInAsync(username, password, false, false);

            if (result.Succeeded)
            {
                ZaposlenikISZRSWebUser zaposlenik = await _userManager.FindByNameAsync(username);

                if (await _userManager.IsInRoleAsync(zaposlenik, "Administrator"))
                {
                    return(RedirectToAction("Index", "Pocetna", new { area = "Administracija" }));
                }



                Ugovori ugovor = UserDB.UgovoriORadu.Where(x => x.ZaposlenikKorisnickoIme == username).SingleOrDefault();

                DolasciNaPosao dolazak = UserDB.DolasciNaPosao.Where(x => x.DatumDolaska.Date == DateTime.Today && x.UgovorOraduId == ugovor.Id).SingleOrDefault();

                if (dolazak == null)
                {
                    dolazak = new DolasciNaPosao()
                    {
                        DatumDolaska  = DateTime.Now,
                        BrojSati      = 0,
                        UgovorOraduId = ugovor.Id
                    };
                    await UserDB.DolasciNaPosao.AddAsync(dolazak);

                    await UserDB.SaveChangesAsync();
                }



                bool JeAdmin = await _userManager.IsInRoleAsync(zaposlenik, "Administrator");

                if (JeAdmin)
                {
                    return(RedirectToAction("Index", "Pocetna", new { area = "Administracija" }));
                }
                bool JeLogisticar = await _userManager.IsInRoleAsync(zaposlenik, "Logisticar");

                if (JeLogisticar)
                {
                    return(RedirectToAction("Logistika", "Pocetna", new { area = "Administracija" }));
                }
                bool JeRecepcionar = await _userManager.IsInRoleAsync(zaposlenik, "Recepcionar");

                if (JeRecepcionar)
                {
                    return(RedirectToAction("Index", "Pocetna", new { area = "Recepcija" }));
                }
            }


            TempData["Error"] = "Korisnik sa ovom kombinacijom ne postoji";
            return(RedirectToAction("Index", "Home"));
        }
Exemple #9
0
 public KorisnikInfo(ZaposlenikISZRSWebUser korisnik, IList <string> uloge)
 {
     this.korisnik = korisnik;
     Uloge         = string.Join(",", uloge);
 }