Commit 5504f58a by Bogdan Andjelkovic

automatski menja info

parent a5f0777b
......@@ -5,12 +5,14 @@ import com.example.SkuciSe.model.korisnik.KorisnikDetails;
import com.example.SkuciSe.repository.KorisnikRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.Base64;
@Controller
public class AppController
......@@ -55,7 +57,7 @@ public class AppController
}
@GetMapping("/profile")
public String getProfile( Model model, @AuthenticationPrincipal KorisnikDetails loggedUser)
public String getProfile(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser)
{
model.addAttribute("loggedUser", loggedUser);
model.addAttribute("editUser", loggedUser.getKorisnik());
......@@ -64,9 +66,12 @@ public class AppController
}
@PostMapping("/profile-update")
public String postProfileEdit( @ModelAttribute Korisnik korisnik)
public String postProfileEdit(Model model, @ModelAttribute Korisnik korisnik, @AuthenticationPrincipal KorisnikDetails loggedUser)
{
kRepo.update( korisnik);
System.out.println( korisnik.toString());
loggedUser.setKorisnik( korisnik);
return "redirect:/profile";
}
}
......@@ -51,4 +51,16 @@ public class KorisnikDetails implements UserDetails {
public boolean isEnabled() {
return true;
}
public void setKorisnik(Korisnik korisnik)
{
this.korisnik.setIme( korisnik.getIme());
this.korisnik.setPrezime( korisnik.getPrezime());
this.korisnik.setEmail( korisnik.getEmail());
this.korisnik.setTelefon( korisnik.getTelefon());
}
public void setKorisnikSlika( String slika)
{
this.korisnik.setSlika( slika);
}
}
......@@ -58,7 +58,6 @@ public class KorisnikRepository
public void updateSlika( Korisnik korisnik, MultipartFile file)
{
String fileName = StringUtils.cleanPath(file.getOriginalFilename());
String slika = null;
String sql = null;
try {
......
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