Commit 0d234ee4 by Bogdan Andjelkovic

edit profile password - back

parent a0d9b4e9
......@@ -63,4 +63,19 @@ public class ProfileController
}
return "redirect:/profile";
}
@GetMapping("/password-edit")
public String getProfilePasswordEdit(Model model, @ModelAttribute Korisnik korisnik, @AuthenticationPrincipal KorisnikDetails loggedUser)
{
model.addAttribute("loggedUser", loggedUser);
model.addAttribute("editUser", loggedUser.getKorisnik());
return "/profile-edit";
}
@PostMapping("/password-edit-save")
public String postPasswordEditSave(Model model, @ModelAttribute Korisnik korisnik, @AuthenticationPrincipal KorisnikDetails loggedUser)
{
kRepo.updateSifra( korisnik);
loggedUser.setKorisnikSifra( korisnik.getSifra());
return "redirect:/logout";
}
}
......@@ -2,6 +2,7 @@ package com.example.SkuciSe.model.korisnik;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import java.util.Collection;
......@@ -64,4 +65,9 @@ public class KorisnikDetails implements UserDetails {
{
this.korisnik.setSlika( slika);
}
public void setKorisnikSifra(String sifra)
{
this.korisnik.setSifra( new BCryptPasswordEncoder().encode( sifra));
}
}
......@@ -152,4 +152,16 @@ public class KorisnikRepository
throw new RuntimeException(e);
}
}
public void updateSifra( Korisnik korisnik)
{
String sql = " update korisnik " +
" set sifra = '" + new BCryptPasswordEncoder().encode( korisnik.getSifra()) +
"' where korisnikid = " + korisnik.getKorisnikId();
try {
dataBase.statement.executeUpdate( sql);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
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