Exemple #1
0
        public IHttpActionResult PostKorisnik(Korisnik korisnik)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (korisnik.Id > 0)
            {
                Korisnik k = db.Korisnics.Find(korisnik.Id);
                k.Grad       = korisnik.Grad;
                k.created_at = korisnik.created_at;
                k.Email      = korisnik.Email;
                k.Ime        = korisnik.Ime;
                k.Prezime    = korisnik.Prezime;
                k.Spol       = korisnik.Spol;
                db.SaveChanges();
            }
            else
            {
                korisnik.password = KorisniciHelper.GenerateHash(korisnik.password, "nema");
                db.Korisnics.Add(korisnik);
                db.SaveChanges();
            }

            return(CreatedAtRoute("DefaultApi", new { id = korisnik.Id }, korisnik));
        }
        private void potvrdiButton_Click(object sender, EventArgs e)
        {
            HttpResponseMessage response = serviceCaller.GetResponse("Login/" + usernameInput.Text);

            if (response.IsSuccessStatusCode)
            {
                Administrator korisnik = response.Content.ReadAsAsync <Administrator>().Result;
                if (korisnik != null && korisnik.PasswordHash == KorisniciHelper.GenerateHash(passwordInput.Text, korisnik.PasswordSalt))
                {
                    LogiraniKorisnik k = new LogiraniKorisnik();
                    k.Id       = korisnik.Id;
                    k.password = korisnik.PasswordHash;
                    k.username = korisnik.username;
                    Global.prijavljeniKorisnik = k;
                    this.DialogResult          = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show(Global.GetMessage("login_pass_err"), Global.GetMessage("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show(Global.GetMessage("login_err"), Global.GetMessage("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public LogiraniKorisnik Get(string username, string password)
        {
            string           novi = KorisniciHelper.GenerateHash(password, "nema");
            LogiraniKorisnik k    = ctx.Korisnics.Where(x => x.username == username)
                                    .Where(y => y.password == novi).Select(x => new LogiraniKorisnik
            {
                Id       = x.Id,
                Ime      = x.Ime,
                Prezime  = x.Prezime,
                username = username,
                Email    = x.Email,
            }).SingleOrDefault();

            return(k);
        }