Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SkuciSe
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tim 2 - 2022
SkuciSe
Commits
0d234ee4
Commit
0d234ee4
authored
Sep 04, 2022
by
Bogdan Andjelkovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
edit profile password - back
parent
a0d9b4e9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
0 deletions
+33
-0
SkuciSe/src/main/java/com/example/SkuciSe/controller/ProfileController.java
+15
-0
SkuciSe/src/main/java/com/example/SkuciSe/model/korisnik/KorisnikDetails.java
+6
-0
SkuciSe/src/main/java/com/example/SkuciSe/repository/KorisnikRepository.java
+12
-0
No files found.
SkuciSe/src/main/java/com/example/SkuciSe/controller/ProfileController.java
View file @
0d234ee4
...
@@ -63,4 +63,19 @@ public class ProfileController
...
@@ -63,4 +63,19 @@ public class ProfileController
}
}
return
"redirect:/profile"
;
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"
;
}
}
}
SkuciSe/src/main/java/com/example/SkuciSe/model/korisnik/KorisnikDetails.java
View file @
0d234ee4
...
@@ -2,6 +2,7 @@ package com.example.SkuciSe.model.korisnik;
...
@@ -2,6 +2,7 @@ package com.example.SkuciSe.model.korisnik;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
java.util.Collection
;
import
java.util.Collection
;
...
@@ -64,4 +65,9 @@ public class KorisnikDetails implements UserDetails {
...
@@ -64,4 +65,9 @@ public class KorisnikDetails implements UserDetails {
{
{
this
.
korisnik
.
setSlika
(
slika
);
this
.
korisnik
.
setSlika
(
slika
);
}
}
public
void
setKorisnikSifra
(
String
sifra
)
{
this
.
korisnik
.
setSifra
(
new
BCryptPasswordEncoder
().
encode
(
sifra
));
}
}
}
SkuciSe/src/main/java/com/example/SkuciSe/repository/KorisnikRepository.java
View file @
0d234ee4
...
@@ -152,4 +152,16 @@ public class KorisnikRepository
...
@@ -152,4 +152,16 @@ public class KorisnikRepository
throw
new
RuntimeException
(
e
);
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
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment