Commit 6bfa9e9d by Bogdan Andjelkovic

dodat profile accept u adminu

parent eb725791
...@@ -52,4 +52,10 @@ public class AdminController ...@@ -52,4 +52,10 @@ public class AdminController
model.addAttribute("gradovi", list); model.addAttribute("gradovi", list);
return "lista-korisnika-delete"; return "lista-korisnika-delete";
} }
@PostMapping ("/accept-user/{id}")
public String acceptUser(@PathVariable("id") Integer id, @AuthenticationPrincipal KorisnikDetails loggedUser, Model model){
kRepo.enableKorisnik(id);
return "redirect:/lista-korisnika";
}
} }
...@@ -23,6 +23,7 @@ public class Korisnik { ...@@ -23,6 +23,7 @@ public class Korisnik {
int tipId; int tipId;
int gradId; int gradId;
boolean enabled;
@Override @Override
public String toString() { public String toString() {
return "Korisnik{" + return "Korisnik{" +
......
...@@ -50,7 +50,7 @@ public class KorisnikDetails implements UserDetails { ...@@ -50,7 +50,7 @@ public class KorisnikDetails implements UserDetails {
@Override @Override
public boolean isEnabled() { public boolean isEnabled() {
return true; return this.korisnik.isEnabled();
} }
public void setKorisnik(Korisnik korisnik) public void setKorisnik(Korisnik korisnik)
......
...@@ -24,7 +24,7 @@ public class KorisnikRepository ...@@ -24,7 +24,7 @@ public class KorisnikRepository
{ {
try { try {
String slika = Base64.getEncoder().encodeToString(multipartFile.getBytes()); String slika = Base64.getEncoder().encodeToString(multipartFile.getBytes());
String sql = "insert into korisnik( ime, prezime, telefon, email, sifra, tipId, slika, gradid) values('"+korisnik.getIme()+"','"+korisnik.getPrezime()+"','"+korisnik.getTelefon()+"','"+korisnik.getEmail()+"','"+new BCryptPasswordEncoder().encode(korisnik.getSifra())+"',1, '"+ slika +"', "+korisnik.getGradId()+")"; String sql = "insert into korisnik( ime, prezime, telefon, email, sifra, tipId, slika, gradid, enabled) values('"+korisnik.getIme()+"','"+korisnik.getPrezime()+"','"+korisnik.getTelefon()+"','"+korisnik.getEmail()+"','"+new BCryptPasswordEncoder().encode(korisnik.getSifra())+"',1, '"+ slika +"', "+korisnik.getGradId()+",false)";
dataBase.statement.executeUpdate( sql); dataBase.statement.executeUpdate( sql);
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
...@@ -75,7 +75,7 @@ public class KorisnikRepository ...@@ -75,7 +75,7 @@ public class KorisnikRepository
rs = dataBase.statement.executeQuery( sql); rs = dataBase.statement.executeQuery( sql);
while( rs.next()) while( rs.next())
{ {
return ( new Korisnik( rs.getInt("korisnikId"), rs.getString("ime"), rs.getString("prezime"), rs.getString("email"), rs.getString("sifra"), rs.getString("telefon"), rs.getString("slika"), rs.getInt("tipid"), rs.getInt("gradid"))); return ( new Korisnik( rs.getInt("korisnikId"), rs.getString("ime"), rs.getString("prezime"), rs.getString("email"), rs.getString("sifra"), rs.getString("telefon"), rs.getString("slika"), rs.getInt("tipid"), rs.getInt("gradid"), rs.getBoolean("enabled")));
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
...@@ -90,7 +90,7 @@ public class KorisnikRepository ...@@ -90,7 +90,7 @@ public class KorisnikRepository
rs = dataBase.statement.executeQuery( sql); rs = dataBase.statement.executeQuery( sql);
while( rs.next()) while( rs.next())
{ {
return ( new Korisnik( rs.getInt("korisnikId"), rs.getString("ime"), rs.getString("prezime"), rs.getString("email"), rs.getString("sifra"), rs.getString("telefon"), rs.getString("slika"), rs.getInt("tipid"), rs.getInt("gradid"))); return ( new Korisnik( rs.getInt("korisnikId"), rs.getString("ime"), rs.getString("prezime"), rs.getString("email"), rs.getString("sifra"), rs.getString("telefon"), rs.getString("slika"), rs.getInt("tipid"), rs.getInt("gradid"), rs.getBoolean("enabled")));
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
...@@ -122,7 +122,7 @@ public class KorisnikRepository ...@@ -122,7 +122,7 @@ public class KorisnikRepository
try { try {
rs = dataBase.statement.executeQuery(sql); rs = dataBase.statement.executeQuery(sql);
while (rs.next()) { while (rs.next()) {
list.add(new Korisnik(rs.getInt("korisnikId"), rs.getString("ime"), rs.getString("prezime"), rs.getString("email"), rs.getString("sifra"), rs.getString("telefon"), rs.getString("slika"), rs.getInt("tipid"), rs.getInt("gradid"))); list.add( new Korisnik( rs.getInt("korisnikId"), rs.getString("ime"), rs.getString("prezime"), rs.getString("email"), rs.getString("sifra"), rs.getString("telefon"), rs.getString("slika"), rs.getInt("tipid"), rs.getInt("gradid"), rs.getBoolean("enabled")));
} }
return list; return list;
} }
...@@ -164,4 +164,16 @@ public class KorisnikRepository ...@@ -164,4 +164,16 @@ public class KorisnikRepository
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
public void enableKorisnik( int korisnikId)
{
String sql = " update korisnik " +
" set enabled = true" +
" where korisnikid = " + korisnikId;
try {
dataBase.statement.executeUpdate( sql);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
} }
...@@ -105,10 +105,15 @@ ...@@ -105,10 +105,15 @@
</div> </div>
<div class="col-md-2 d-flex flex-column justify-content-around align-items-center"> <div class="col-md-2 d-flex flex-column justify-content-around align-items-center">
<form method="POST" <form method="POST"
th:action="@{/delete-user/{id}(id=${korisnik.getKorisnikId()})}"> th:action="@{/delete-user/{id}(id=${korisnik.getKorisnikId()})}"
th:if="${korisnik.isEnabled()==true}">
<button type="submit" class="btn btn-danger">Obrisi korisnika</button> <button type="submit" class="btn btn-danger">Obrisi korisnika</button>
</form> </form>
<button type="button" class="btn btn-secondary">Izmeni korisnika</button> <form method="POST"
th:action="@{/accept-user/{id}(id=${korisnik.getKorisnikId()})}"
th:if="${korisnik.isEnabled()==false}">
<button type="submit" class="btn btn-secondary">Prihvati korisnika</button>
</form>
</div> </div>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment