Commit a55247fc by Bogdan Andjelkovic

profile edit 1

parent c39022db
......@@ -58,7 +58,15 @@ public class AppController
public String getProfile( Model model, @AuthenticationPrincipal KorisnikDetails loggedUser)
{
model.addAttribute("loggedUser", loggedUser);
model.addAttribute("editUser", loggedUser);
model.addAttribute("profileRole", kRepo.findRoleById( loggedUser.getKorisnik().getTipId()));
return("profile");
}
@PostMapping("/profile-edit")
public String postProfileEdit( @ModelAttribute KorisnikDetails korisnikDetails)
{
kRepo.update( korisnikDetails.getKorisnik());
return "redirect:/profile";
}
}
......@@ -37,9 +37,5 @@ public class Korisnik {
'}';
}
/*public String getEncodedPic(){
String slika=null;
slika= Base64.getEncoder().encodeToString(getSlika());
return slika;
*/
}
\ No newline at end of file
......@@ -28,7 +28,6 @@ public class KorisnikRepository
public void insert( Korisnik korisnik, MultipartFile multipartFile) throws IOException
{
String fileName = StringUtils.cleanPath(multipartFile.getOriginalFilename());
String slika = Base64.getEncoder().encodeToString(multipartFile.getBytes());
System.out.println( slika);
String sql = "insert into korisnik( ime, prezime, telefon, email, sifra, tipId, slika) values('"+korisnik.getIme()+"','"+korisnik.getPrezime()+"','"+korisnik.getTelefon()+"','"+korisnik.getEmail()+"','"+new BCryptPasswordEncoder().encode(korisnik.getSifra())+"',1, '"+ slika +"')";
......@@ -40,6 +39,42 @@ public class KorisnikRepository
}
}
public void update( Korisnik korisnik)
{
String sql = " insert into korisnik " +
" where korisnikid = " + korisnik.getKorisnikId() +
" set ime = " + korisnik.getIme() +
",set prezime = " + korisnik.getPrezime() +
",set email = " + korisnik.getEmail() +
",set sifra = " + new BCryptPasswordEncoder().encode(korisnik.getSifra()) +
",set telefon = " + korisnik.getTelefon();
try {
System.out.println( sql);
statement.executeUpdate( sql);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public void updateSlika( Korisnik korisnik, MultipartFile file)
{
String fileName = StringUtils.cleanPath(file.getOriginalFilename());
String slika = null;
String sql = null;
try {
slika = Base64.getEncoder().encodeToString(file.getBytes());
sql = " insert into korisnik " +
" where korisnikid = " + korisnik.getKorisnikId() +
" set slika = " + slika;
System.out.println( sql);
statement.executeUpdate( sql);
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public Korisnik findByEmail(String email)
{
String sql = "select * from korisnik where email = '"+email+"'";
......
......@@ -63,7 +63,6 @@
<img class="photo" th:src="@{'data:image/png;charset=utf-8;base64,'+${loggedUser.getKorisnik().getSlika()}}" alt="slika korisnika">
<p class="fw-bold h4 mt-3"><span th:text="${loggedUser.getKorisnik().getIme()}"></span></p>
<p class="text-muted" th:object="${profileRole}" th:text="${profileRole}"></p>
<br>
<div class="d-flex ">
<div class="btn btn-outline-primary message">Poruka</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