public IHttpActionResult NoviKorisnik(KorisniciVM k) { Korisnici korisnik = new Korisnici(); korisnik.Email = k.Email; korisnik.Adresa = k.Adresa; korisnik.Kontakt = k.Kontakt; korisnik.Ime = k.Ime; korisnik.KorisnickoIme = k.KorisnickoIme; korisnik.Lozinka = k.Lozinka; korisnik.Prezime = k.Prezime; try { ctx.Korisnici.Add(korisnik); ctx.SaveChanges(); } catch (Exception) { return(NotFound()); } return(Ok()); }
public KorisniciVM Insert(KorisniciInsertRequest request) { var entity = _mapper.Map <Korisnici>(request); KorisniciVM korisnik = new KorisniciVM(); if (request.Password != request.PasswordConfirmation) { korisnik.KorisnikId = 100; return(korisnik); } entity.LozinkaSalt = GenerateSalt(); entity.LozinkaHash = GenerateHash(entity.LozinkaSalt, request.Password); Korisnici checkExists = _context.Korisnici.Where(w => w.KorisnickoIme == request.KorisnickoIme).FirstOrDefault(); if (checkExists != null) { korisnik.KorisnikId = 200; return(korisnik); //throw new UserException("Korisnik pod korisničkim imenom : " + request.KorisnickoIme + " već postoji!"); } _context.Add(entity); _context.SaveChanges(); return(_mapper.Map <KorisniciVM>(entity)); }
public KorisniciVM Insert(KorisniciInsertRequest request) { var entity = _mapper.Map <Korisnici>(request); KorisniciVM korisnik = new KorisniciVM(); if (request.Password != request.PasswordConfirmation) { throw new ArgumentException("Pogrešan password"); } entity.LozinkaSalt = GenerateSalt(); entity.LozinkaHash = GenerateHash(entity.LozinkaSalt, request.Password); Korisnici checkExists = _context.Korisnici.Where(w => w.KorisnickoIme == request.KorisnickoIme).FirstOrDefault(); if (checkExists != null) { throw new ArgumentException("Korisnik već postoji"); } _context.Add(entity); _context.SaveChanges(); return(_mapper.Map <KorisniciVM>(entity)); }
public KorisniciVM prepRadnika() { KorisniciVM model = new KorisniciVM(); model.DatumRodjenja = DateTime.Now; model.Spolovi = new List <SelectListItem>(); model.Spolovi.Add(new SelectListItem() { Value = "Muško", Text = "Muško" }); model.Spolovi.Add(new SelectListItem() { Value = "Žensko", Text = "Žensko" }); model.Gradovi = _db.Grad.Include(x => x.Drzava).Select(x => new SelectListItem() { Value = x.GradId.ToString(), Text = x.Naziv + ", " + x.Drzava.Naziv }).ToList(); return(model); }
public KorisniciVM Provjera(string username, string lozinka) { Context ctx = new Context(); KorisniciVM k = ctx.Korisnici.Where(x => x.KorisnickoIme == username && x.Lozinka == lozinka).Select(x => new KorisniciVM { Ime = x.Ime, Prezime = x.Prezime, Email = x.Email, Adresa = x.Adresa, Kontakt = x.Kontakt, KorisnickoIme = x.KorisnickoIme, Id = x.Id, Lozinka = x.Lozinka }).FirstOrDefault(); return(k); }
public async Task <IActionResult> Snimi(KorisniciVM model, IFormFile imgInp) { bool x = await _roleManager.RoleExistsAsync("Radnik"); if (!x) { await _roleManager.CreateAsync(new IdentityRole { Name = "Radnik" }); } //password must be strong enough in order for userManager.CreateAsync to work!!! string password = "******"; ApplicationUser user = new ApplicationUser { JMBG = model.JMBG, Ime = model.Ime, Prezime = model.Prezime, DatumRodjenja = model.DatumRodjenja, Telefon = model.Telefon, Spol = model.Spol, Adresa = model.Adresa, Slika = await _imgHelper.GetImgLocationAsync(imgInp), UserName = model.Ime + '.' + model.Prezime, Email = model.Ime + "." + model.Prezime + "@traveleurope.ba",//, GradId = model.GradId }; IdentityResult chkUser = await _userManager.CreateAsync(user, password); await _userManager.AddToRoleAsync(user, "Radnik"); Radnik radnik = new Radnik { RadnikId = user.Id, GodineStaza = model.GodineStaza, Pozicija = model.Pozicija }; _db.Add(radnik); _db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Kreiraj(KorisniciVM model) { bool x = await _roleManager.RoleExistsAsync("Klijent"); if (!x) { await _roleManager.CreateAsync(new IdentityRole { Name = "Klijent" }); } //password must be strong enough in order for userManager.CreateAsync to work!!! string password = "******"; ApplicationUser user = new ApplicationUser { JMBG = model.JMBG, Ime = model.Ime, Prezime = model.Prezime, DatumRodjenja = model.DatumRodjenja, Telefon = model.Telefon, Spol = model.Spol, Adresa = model.Adresa, GradId = model.GradId, UserName = model.Ime.ToLower() + '.' + model.Prezime.ToLower(), Email = model.Ime + "." + model.Prezime + "@traveleurope.ba" }; await _userManager.CreateAsync(user, password); await _userManager.AddToRoleAsync(user, "Klijent"); Klijent klijent = new Klijent { KlijentId = user.Id, BrojPasosa = model.BrojPasosa, BrVozackeDozvole = model.BrVozackeDozvole }; _db.Klijent.Add(klijent); _db.SaveChanges(); return(RedirectToAction("RegistracijaSucceedLogin", "Account")); }
public IHttpActionResult PostKorisnik(KorisniciVM korisnik) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } korisnik.Id = Convert.ToInt32(db.esp_Korisnik_Insert(korisnik.Ime, korisnik.Prezime, korisnik.Email, korisnik.Mobitel, korisnik.Adresa, korisnik.KorisnickoIme, korisnik.Lozinka).FirstOrDefault()); db.esp_Pacijents_Insert(korisnik.Id, null, DateTime.Now); return(CreatedAtRoute("DefaultApi", new { id = korisnik.Id }, korisnik)); }
public KorisniciVM ProvjeraStomatolog(string username, string lozinka) { KorisniciVM k = ctx.Korisniks.Where(x => x.KorisnickoIme == username && x.Lozinka == lozinka). Include(x => x.Stomatolog).Select(x => new KorisniciVM { Ime = x.Ime, Prezime = x.Prezime, KorisnickoIme = x.KorisnickoIme, Lozinka = x.Lozinka, Email = x.Email, Id = x.Id, Adresa = x.Adresa, Mobitel = x.Mobitel, Aktivan = x.Aktivan, IsAdmin = x.IsAdmin }).FirstOrDefault(); return(k); }
private async void btnSnimi_Click(object sender, EventArgs e) { KorisniciVM korisnik = new KorisniciVM(); if (this.ValidateChildren()) { var request = new KorisniciInsertRequest() { Email = txtEmail.Text, Ime = txtIme.Text, KorisnickoIme = txtKorisnickoIme.Text, Password = txtPassword.Text, PasswordConfirmation = txtPotvrda.Text, Prezime = txtPrezime.Text, DatumRodjenja = txtDatumRodjenja.Value, GradID = cbxGradovi.SelectedIndex, Status = Convert.ToInt32(cboxAktivan.Checked) }; try { korisnik = await _service.Insert <KorisniciVM>(request); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (korisnik.KorisnikId == 100) { MessageBox.Show("Paswordi se ne slažu"); } else if (korisnik.KorisnikId == 200) { MessageBox.Show("Korisnik pod korisničkim imenom " + request.KorisnickoIme + " već postoji"); } else if (korisnik.KorisnickoIme != null && korisnik.Email != null) { MessageBox.Show("Korisnik je uspješno kreiran"); } } }
public IHttpActionResult IzmjeniPodatke(KorisniciVM k) { Korisnik korisnik = new Korisnik(); korisnik.Id = k.Id; korisnik.Ime = k.Ime; korisnik.Prezime = k.Prezime; korisnik.Lozinka = k.Lozinka; korisnik.KorisnickoIme = k.KorisnickoIme; korisnik.Email = k.Email; korisnik.Mobitel = k.Mobitel; korisnik.Aktivan = true; korisnik.Adresa = k.Adresa; db.Entry(korisnik).State = EntityState.Modified; db.SaveChanges(); return(Ok()); }
public IHttpActionResult IzmjeniPodatke(KorisniciVM k) { Korisnici korisnik = new Korisnici(); korisnik.Id = k.Id; korisnik.Ime = k.Ime; korisnik.Prezime = k.Prezime; korisnik.Email = k.Email; korisnik.Adresa = k.Adresa; korisnik.Kontakt = k.Kontakt; korisnik.KorisnickoIme = k.KorisnickoIme; korisnik.Lozinka = k.Lozinka; ctx.Entry(korisnik).State = EntityState.Modified; ctx.SaveChanges(); return(Ok()); }
public IActionResult Unos(bool?postoji = null, int?uloga = null, int?sifra = null, string?ime = null, string?prezime = null, string?telefon = null, string?mail = null, string?lozinka = null, string?username = null) { if (HttpContext.Session.GetInt32("user ID") == null) { TempData["poruka"] = poruka; return(Redirect("/Auth/Index")); } if (HttpContext.Session.GetString("role") != "SuperAdmin") { TempData["poruka"] = poruka2; return(Redirect("/Auth/Index")); } else { List <Uloge> lista_uloge = db.Uloge.Select(x => new Uloge { Naziv = x.Naziv, Opis = x.Opis, Sifra = x.Sifra, Uloge_ID = x.Uloge_ID }).ToList(); ViewData["uloge"] = lista_uloge; KorisniciVM model = new KorisniciVM { Ime = ime, Korisnicko_Ime = username, Lozinka = lozinka, Mail = mail, Postoji = postoji, Prezime = prezime, Sifra = sifra, Telefon = telefon, Uloge_FK = uloga, Uloge = db.Uloge.Where(a => a.Uloge_ID == uloga).FirstOrDefault() }; return(View("Unos", model)); } }
protected override async Task <AuthenticateResult> HandleAuthenticateAsync() { if (!Request.Headers.ContainsKey("Authorization")) { return(AuthenticateResult.Fail("Missing Authorization Header")); } KorisniciVM user = null; try { var authHeader = AuthenticationHeaderValue.Parse(Request.Headers["Authorization"]); var credentialBytes = Convert.FromBase64String(authHeader.Parameter); var credentials = Encoding.UTF8.GetString(credentialBytes).Split(':'); var username = credentials[0]; var password = credentials[1]; user = _userService.Authenticiraj(username, password); } catch { return(AuthenticateResult.Fail("Invalid Authorization Header")); } if (user == null) { return(AuthenticateResult.Fail("Invalid Username or Password")); } var claims = new List <Claim> { new Claim(ClaimTypes.NameIdentifier, user.KorisnickoIme), new Claim(ClaimTypes.Name, user.Ime), }; var identity = new ClaimsIdentity(claims, Scheme.Name); var principal = new ClaimsPrincipal(identity); var ticket = new AuthenticationTicket(principal, Scheme.Name); return(AuthenticateResult.Success(ticket)); }
private async void btnLogin_Click(object sender, EventArgs e) { try { KorisniciVM korisnik = await _service.Authenticiraj <KorisniciVM>(txtUsername.Text, txtPassword.Text); if (korisnik != null) { MessageBox.Show("Dobrodosli " + korisnik.Ime + " " + korisnik.Prezime); DialogResult = DialogResult.OK; frmIndex frm = new frmIndex(); frm.Show(); } else { MessageBox.Show("Pogresan username ili password", "Autentifikacija", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Authentikacija", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public Page2() { InitializeComponent(); BindingContext = model = new KorisniciVM(); }
public IActionResult Dodaj() { KorisniciVM model = _userManagementHelper.prepRadnika(); return(View("Dodaj", model)); }